1 package org.simantics.tests.modelled.junit.v2;
3 import java.io.BufferedReader;
4 import java.io.StringReader;
6 import org.junit.runner.Description;
7 import org.junit.runner.Runner;
8 import org.junit.runner.notification.RunNotifier;
9 import org.simantics.scl.compiler.commands.CommandSession;
10 import org.simantics.scl.compiler.commands.TestScriptExecutor;
11 import org.simantics.scl.osgi.SCLOsgi;
12 import org.simantics.scl.runtime.SCLContext;
13 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
14 import org.simantics.tests.modelled.utils.ModelledSTSTest;
15 import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
17 public class ModelledSTSTestRunner extends Runner {
19 private Description description;
20 private ModelledSTSTest test;
22 public ModelledSTSTestRunner(ModelledSTSTest test) {
26 public String getName() {
27 return test.getName();
31 public Description getDescription() {
32 if (description == null)
33 description = Description.createTestDescription(ModelledSTSTestRunner.class, getName());
38 * This method is called from ModelledSTSSuite (ParentRunner) with the same
43 public void run(CommandSession session) {
44 try (BufferedReader reader = new BufferedReader(new StringReader(test.getCode()))) {
45 SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
46 new TestScriptExecutor(session, reader, handler, true).execute();
47 STSSuiteTestCollector.setTestCoverage(test, session);
48 } catch (Exception e) {
49 throw new RuntimeException(e);
54 public void run(RunNotifier notifier) {
55 notifier.fireTestStarted(getDescription());
57 run(new CommandSession(SCLOsgi.MODULE_REPOSITORY, null));
59 notifier.fireTestFinished(getDescription());
63 public boolean isIgnored() {
64 return test.isIgnored();
67 public int getPriority() {
68 return test.getPriority();
71 public ModelledSTSTest getTest() {