X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2FRuntimeSTSTestRunner.java;fp=bundles%2Forg.simantics.tests.modelled%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fjunit%2FRuntimeSTSTestRunner.java;h=a80b84e750f7dbe413b255b5a2527d7dc49dc139;hb=53059ca1a958697cc6235d27628614fbaa944d59;hp=0000000000000000000000000000000000000000;hpb=e87f0965679502de281692c298d66a7ae9507bd8;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java new file mode 100644 index 000000000..a80b84e75 --- /dev/null +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/RuntimeSTSTestRunner.java @@ -0,0 +1,69 @@ +package org.simantics.tests.modelled.junit; + +import java.io.BufferedReader; +import java.io.IOException; +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; + +public class RuntimeSTSTestRunner extends Runner { + + private final String name; + private final String code; + private final Integer priority; + private CommandSession session; + + public RuntimeSTSTestRunner(String name, String code, Integer priority) { + this.name = name; + this.code = code; + this.priority = priority; + } + + public void setCommandSession(CommandSession session) { + this.session = session; + } + + @Override + public Description getDescription() { + return Description.createTestDescription(RuntimeSTSTestRunner.class, name); + } + + @Override + public void run(RunNotifier notifier) { + StringReader reade = new StringReader(code); + BufferedReader reader = new BufferedReader(reade); + + SCLContext context = SCLContext.getCurrent(); + SCLReportingHandler printer = (SCLReportingHandler)context.get(SCLReportingHandler.REPORTING_HANDLER); + SCLReportingHandler handler; + if(printer instanceof SCLReportingHandler) + handler = (SCLReportingHandler)printer; + else + handler = SCLReportingHandler.DEFAULT; + + try { + if (session == null) + session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, handler); + new TestScriptExecutor(session, reader, handler).execute(); + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + try { + reader.close(); + } catch (IOException e) { + // Ignore + } + } + } + + public Integer getPriority() { + return priority; + } +}