]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java
Enhancements to modelled tests
[simantics/platform.git] / bundles / org.simantics.tests.modelled / src / org / simantics / tests / modelled / junit / v2 / ModelledSTSSuiteRunner.java
index a568976cc6da745db0beba6a818ad738c98487c7..5b7a8ef0ac3d5b352052476055bd160b7c58531b 100644 (file)
@@ -1,26 +1,32 @@
 package org.simantics.tests.modelled.junit.v2;
 
+import java.util.ArrayList;
 import java.util.List;
-import java.util.stream.Collectors;
+import java.util.Map;
 
 import org.junit.runner.Description;
 import org.junit.runner.notification.Failure;
 import org.junit.runner.notification.RunNotifier;
 import org.junit.runners.ParentRunner;
-import org.simantics.scl.compiler.commands.CommandSession;
+import org.junit.runners.model.InitializationError;
 import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
-import org.simantics.scl.osgi.SCLOsgi;
 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
-import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
+import org.simantics.tests.modelled.utils.ModelledSTSTest;
+import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable;
 
 public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner> {
 
     private final ModelledSTSSuite suite;
-    private CommandSession commandSession;
+    private final List<ModelledSTSTestRunner> children;
+    private Map<String, List<CommandSessionVariable>> storedVariables;
 
-    public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws Exception {
+    public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws InitializationError {
         super(ModelledSTSSuiteRunner.class);
         this.suite = suite;
+        this.children = new ArrayList<>(suite.getChildren().size());
+        for (ModelledSTSTest test : suite.getSortedChildren()) {
+            children.add(new ModelledSTSTestRunner(test));
+        }
     }
 
     @Override
@@ -30,7 +36,7 @@ public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner>
 
     @Override
     protected List<ModelledSTSTestRunner> getChildren() {
-        return suite.getChildren().stream().map(test -> new ModelledSTSTestRunner(test)).collect(Collectors.toList());
+        return children;
     }
 
     @Override
@@ -44,15 +50,21 @@ public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner>
         if (isIgnored(child)) {
             notifier.fireTestIgnored(description);
         } else {
-            notifier.fireTestStarted(description);
             try {
-                child.run(getCommandSession());
+                List<CommandSessionVariable> variables = new ArrayList<>();
+                for (String dep : child.getTest().getDependencies()) {
+                    List<CommandSessionVariable> storedVars = storedVariables.get(dep);
+                    if (storedVars != null) {
+                        variables.addAll(storedVars);
+                    }
+                }
+                List<CommandSessionVariable> newVars = child.runWithVars(variables);
+                storedVariables.put(child.getTest().getName(), newVars);
                 notifier.fireTestFinished(description);
-                STSSuiteTestCollector.setSuiteCoverage(child.getTest(), suite, getCommandSession());
-            } catch (Throwable e) {
+            } catch (Exception e) {
                 notifier.fireTestFailure(new Failure(description, e));
             }
-        }
+        } 
     }
 
     @Override
@@ -60,16 +72,6 @@ public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner>
         return child.isIgnored();
     }
 
-    public void setCommandSesssion(CommandSession commandSession) {
-        this.commandSession = commandSession;
-    }
-
-    public CommandSession getCommandSession() {
-        if (commandSession == null)
-            commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
-        return commandSession;
-    }
-
     public CombinedCoverage getCoverage() {
         return suite.getCoverage();
     }