X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2Fv2%2FModelledSTSTestRunner.java;fp=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2Fv2%2FModelledSTSTestRunner.java;h=a2acbfcb8d23edc93ab0a64d76c2ff6bc56a4377;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/ModelledSTSTestRunner.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSTestRunner.java new file mode 100644 index 000000000..a2acbfcb8 --- /dev/null +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSTestRunner.java @@ -0,0 +1,74 @@ +package org.simantics.tests.modelled.junit.v2; + +import java.io.BufferedReader; +import java.io.StringReader; + +import org.junit.runner.Description; +import org.junit.runner.Runner; +import org.junit.runner.notification.RunNotifier; +import org.simantics.scl.compiler.commands.CommandSession; +import org.simantics.scl.compiler.commands.TestScriptExecutor; +import org.simantics.scl.osgi.SCLOsgi; +import org.simantics.scl.runtime.SCLContext; +import org.simantics.scl.runtime.reporting.SCLReportingHandler; +import org.simantics.tests.modelled.utils.ModelledSTSTest; +import org.simantics.tests.modelled.utils.STSSuiteTestCollector; + +public class ModelledSTSTestRunner extends Runner { + + private Description description; + private ModelledSTSTest test; + + public ModelledSTSTestRunner(ModelledSTSTest test) { + this.test = test; + } + + public String getName() { + return test.getName(); + } + + @Override + public Description getDescription() { + if (description == null) + description = Description.createTestDescription(ModelledSTSTestRunner.class, getName()); + return description; + } + + /** + * This method is called from ModelledSTSSuite (ParentRunner) with the same + * CommandSession + * + * @param session + */ + public void run(CommandSession session) { + try (BufferedReader reader = new BufferedReader(new StringReader(test.getCode()))) { + SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); + new TestScriptExecutor(session, reader, handler, true).execute(); + STSSuiteTestCollector.setTestCoverage(test, session); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + @Override + public void run(RunNotifier notifier) { + notifier.fireTestStarted(getDescription()); + try { + run(new CommandSession(SCLOsgi.MODULE_REPOSITORY, null)); + } finally { + notifier.fireTestFinished(getDescription()); + } + } + + public boolean isIgnored() { + return test.isIgnored(); + } + + public int getPriority() { + return test.getPriority(); + } + + public ModelledSTSTest getTest() { + return test; + } +}