X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2Fv2%2FModelledSTSSuiteRunner.java;h=0bfb1f1ceaf02ab61476398c4075e2dead9e165b;hp=a568976cc6da745db0beba6a818ad738c98487c7;hb=3e8cd4aef089a228d7f2e141f2b2159f820a4266;hpb=7a7f73011a6364cbb80ce4ef04424472d345a65a diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java index a568976cc..0bfb1f1ce 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java @@ -1,28 +1,64 @@ package org.simantics.tests.modelled.junit.v2; +import java.util.ArrayList; +import java.util.HashMap; 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 { private final ModelledSTSSuite suite; - private CommandSession commandSession; + private final List children; + private Map> storedVariables = new HashMap<>(); - 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()); + + // Do possible filtering + // Filter exclusions + String exclusionFilter = System.getProperty(ModelledSTSRunner.EXCLUSION_FILTER); + // Filter inclusions + String inclusionFilter = System.getProperty(ModelledSTSRunner.INCLUSION_FILTER); + for (ModelledSTSTest test : suite.getSortedChildren()) { + boolean add = true; + if (exclusionFilter != null) { + String[] filters = exclusionFilter.split(","); + if (startsWithAny(test, filters)) { + add = false; + } + } + if (inclusionFilter != null) { + String[] filters = inclusionFilter.split(","); + if (!startsWithAny(test, filters)) { + add = false; + } + } + if (add) + children.add(new ModelledSTSTestRunner(test)); + } } + private static boolean startsWithAny(ModelledSTSTest test, String[] filters) { + for (String filter : filters) { + if (test.getName().contains(filter)) { + return true; + } + } + return false; + } + @Override protected String getName() { return suite.getName(); @@ -30,7 +66,7 @@ public class ModelledSTSSuiteRunner extends ParentRunner @Override protected List getChildren() { - return suite.getChildren().stream().map(test -> new ModelledSTSTestRunner(test)).collect(Collectors.toList()); + return children; } @Override @@ -44,15 +80,23 @@ public class ModelledSTSSuiteRunner extends ParentRunner if (isIgnored(child)) { notifier.fireTestIgnored(description); } else { - notifier.fireTestStarted(description); try { - child.run(getCommandSession()); + List variables = new ArrayList<>(); + for (String dep : child.getTest().getDependencies()) { + List storedVars = storedVariables.get(dep); + if (storedVars != null) { + variables.addAll(storedVars); + } + } + notifier.fireTestStarted(description); + List newVars = child.runWithVars(variables); +// TODO: FIX THIS BY NOT ADDING ALL VARIABLES TO MEMORY (CAN BE HUGE) +// storedVariables.put(child.getTest().getName(), newVars); notifier.fireTestFinished(description); - STSSuiteTestCollector.setSuiteCoverage(child.getTest(), suite, getCommandSession()); } catch (Throwable e) { notifier.fireTestFailure(new Failure(description, e)); } - } + } } @Override @@ -60,16 +104,6 @@ public class ModelledSTSSuiteRunner extends ParentRunner 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(); }