X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2Fv2%2FModelledSTSSuiteRunner.java;fp=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2Fv2%2FModelledSTSSuiteRunner.java;h=a568976cc6da745db0beba6a818ad738c98487c7;hb=f03893d9b643eae3f03debf7a656edbfa5b9b501;hp=0000000000000000000000000000000000000000;hpb=51006ffec13cbf8e0d9c8b07212d69478e4bdd4e;p=simantics%2Fplatform.git 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 new file mode 100644 index 000000000..a568976cc --- /dev/null +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java @@ -0,0 +1,77 @@ +package org.simantics.tests.modelled.junit.v2; + +import java.util.List; +import java.util.stream.Collectors; + +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.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; + +public class ModelledSTSSuiteRunner extends ParentRunner { + + private final ModelledSTSSuite suite; + private CommandSession commandSession; + + public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws Exception { + super(ModelledSTSSuiteRunner.class); + this.suite = suite; + } + + @Override + protected String getName() { + return suite.getName(); + } + + @Override + protected List getChildren() { + return suite.getChildren().stream().map(test -> new ModelledSTSTestRunner(test)).collect(Collectors.toList()); + } + + @Override + protected Description describeChild(ModelledSTSTestRunner child) { + return child.getDescription(); + } + + @Override + protected void runChild(ModelledSTSTestRunner child, RunNotifier notifier) { + Description description = describeChild(child); + if (isIgnored(child)) { + notifier.fireTestIgnored(description); + } else { + notifier.fireTestStarted(description); + try { + child.run(getCommandSession()); + notifier.fireTestFinished(description); + STSSuiteTestCollector.setSuiteCoverage(child.getTest(), suite, getCommandSession()); + } catch (Throwable e) { + notifier.fireTestFailure(new Failure(description, e)); + } + } + } + + @Override + protected boolean isIgnored(ModelledSTSTestRunner child) { + 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(); + } + +}