1 package org.simantics.tests.modelled.junit;
\r
3 import java.io.BufferedReader;
\r
4 import java.io.IOException;
\r
5 import java.io.StringReader;
\r
7 import org.junit.runner.Description;
\r
8 import org.junit.runner.Runner;
\r
9 import org.junit.runner.notification.RunNotifier;
\r
10 import org.simantics.scl.compiler.commands.CommandSession;
\r
11 import org.simantics.scl.compiler.commands.TestScriptExecutor;
\r
12 import org.simantics.scl.osgi.SCLOsgi;
\r
13 import org.simantics.scl.runtime.SCLContext;
\r
14 import org.simantics.scl.runtime.reporting.SCLReportingHandler;
\r
16 public class RuntimeSTSTestRunner extends Runner {
\r
18 private final String name;
\r
19 private final String code;
\r
20 private final Integer priority;
\r
21 private CommandSession session;
\r
23 public RuntimeSTSTestRunner(String name, String code, Integer priority) {
\r
26 this.priority = priority;
\r
29 public void setCommandSession(CommandSession session) {
\r
30 this.session = session;
\r
34 public Description getDescription() {
\r
35 return Description.createTestDescription(RuntimeSTSTestRunner.class, name);
\r
39 public void run(RunNotifier notifier) {
\r
40 StringReader reade = new StringReader(code);
\r
41 BufferedReader reader = new BufferedReader(reade);
\r
43 SCLContext context = SCLContext.getCurrent();
\r
44 SCLReportingHandler printer = (SCLReportingHandler)context.get(SCLReportingHandler.REPORTING_HANDLER);
\r
45 SCLReportingHandler handler;
\r
46 if(printer instanceof SCLReportingHandler)
\r
47 handler = (SCLReportingHandler)printer;
\r
49 handler = SCLReportingHandler.DEFAULT;
\r
52 if (session == null)
\r
53 session = new CommandSession(SCLOsgi.MODULE_REPOSITORY, handler);
\r
54 new TestScriptExecutor(session, reader, handler).execute();
\r
55 } catch (IOException e) {
\r
56 throw new RuntimeException(e);
\r
60 } catch (IOException e) {
\r
66 public Integer getPriority() {
\r