package org.simantics.tests.modelled.ui;
-import java.io.BufferedReader;
-import java.io.StringReader;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
-import java.util.regex.Pattern;
+import java.util.Map;
import java.util.stream.Collectors;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.swt.graphics.Image;
import org.simantics.Simantics;
import org.simantics.db.ReadGraph;
import org.simantics.db.common.request.ReadRequest;
import org.simantics.db.exception.DatabaseException;
import org.simantics.layer0.Layer0;
-import org.simantics.scl.compiler.commands.CommandSession;
-import org.simantics.scl.compiler.commands.TestScriptExecutor;
import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
-import org.simantics.scl.compiler.module.options.ModuleCompilationOptions;
-import org.simantics.scl.compiler.module.options.ModuleCompilationOptionsAdvisor;
-import org.simantics.scl.compiler.module.repository.ModuleRepository;
-import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.scl.runtime.SCLContext;
import org.simantics.scl.runtime.reporting.AbstractSCLReportingHandler;
+import org.simantics.scl.runtime.reporting.SCLReportingHandler;
import org.simantics.tests.modelled.ontology.TestsResource;
import org.simantics.tests.modelled.utils.ModelledSTSSuite;
import org.simantics.tests.modelled.utils.ModelledSTSTest;
+import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable;
import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
public class STSTestSuiteModel {
- static class STSTest {
+ private Map<String, List<CommandSessionVariable>> storedVars = new HashMap<>();
+
+ class STSTest {
private final ModelledSTSTest test;
return parent;
}
- public void execute(CommandSession session) {
+ public void execute() {
isRunning = true;
-
- TestScriptExecutor executor = new TestScriptExecutor(session, new BufferedReader(new StringReader(getDefinition())), new AbstractSCLReportingHandler() {
-
- @Override
- public void print(String text) {
- appendOutput(text + "\n");
- }
-
- @Override
- public void printCommand(String command) {
- appendOutput("> " + command + "\n");
- }
-
- @Override
- public void printError(String error) {
- appendOutput(error + "\n");
- }
- }, true);
long start = System.currentTimeMillis();
+ Object old = SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
try {
if (parent != null)
parent.startedCount++;
- executor.execute();
+
+ SCLContext.getCurrent().put(SCLReportingHandler.REPORTING_HANDLER, new AbstractSCLReportingHandler() {
+
+ @Override
+ public void print(String text) {
+ appendOutput(text + "\n");
+ }
+
+ @Override
+ public void printCommand(String command) {
+ appendOutput("> " + command + "\n");
+ }
+
+ @Override
+ public void printError(String error) {
+ appendOutput(error + "\n");
+ }
+ });
+ List<CommandSessionVariable> resolvedVars = new ArrayList<>();
+ for (String deps : test.getDependencies()) {
+ List<CommandSessionVariable> vars = storedVars.get(deps);
+ if (vars != null)
+ resolvedVars.addAll(vars);
+ }
+
+ List<CommandSessionVariable> vars = test.run(resolvedVars);
+ storedVars.put(test.getName(), vars);
+
executed = true;
} catch (Throwable t) {
t.printStackTrace();
isRunning = false;
long end = System.currentTimeMillis();
duration = end - start;
+
+ SCLContext.getCurrent().put(SCLReportingHandler.REPORTING_HANDLER, old);
}
-
}
protected void appendOutput(String text) {
}
}
- static class STSSuite {
+ class STSSuite {
private ModelledSTSSuite suite;
private STSTest[] children;
private STSSuite suite;
private STSTest test;
private final List<STSExecutionListener> listeners = new ArrayList<>();
+ private Job currentJob;
public STSTestSuiteModel() {
}
}
public void execute() {
-
- ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY);
- if (suite != null) {
- repo.setAdvisor(new ModuleCompilationOptionsAdvisor() {
+ String command;
+ if (suite != null)
+ command = suite.getName();
+ else
+ command = test.getName();
+ if (currentJob != null)
+ currentJob.cancel();
+ currentJob = new Job(command) {
+ @Override
+ protected IStatus run(IProgressMonitor monitor) {
+ if (suite != null) {
+ executeSuite();
+ } else if (test != null) {
+ executeTest();
+ }
+ return Status.OK_STATUS;
+ }
+
+ @Override
+ protected void canceling() {
+ Thread thread = getThread();
+ if(thread != null)
+ thread.interrupt();
- @Override
- public ModuleCompilationOptions getOptions(String moduleName) {
- boolean coverage = false;
- for (Pattern p : suite.suite.getModuleNameFilterPatterns()) {
- if (p.matcher(moduleName.toLowerCase()).find()) {
- coverage = true;
- break;
- }
- }
- return new ModuleCompilationOptions(coverage);
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
- });
- }
- CommandSession session = new CommandSession(repo, null);
- if (suite != null) {
- executeSuite(session);
- } else if (test != null) {
- executeTest(session);
- }
+
+ thread = getThread();
+ if(thread != null)
+ thread.stop();
+ }
+ };
+ currentJob.schedule();
+ }
+
+ public void interrupt() {
+ if (currentJob != null)
+ currentJob.cancel();
}
private void testExecuted() {
});
}
- private void executeSuite(CommandSession session) {
+ private void executeSuite() {
for (STSTest test : suite.getChildren()) {
if (test.isIgnored()) {
testExecuted();
test.getParent().ignoredCount++;
continue;
}
- test.execute(session);
- STSSuiteTestCollector.setSuiteCoverage(test.test, suite.suite, session);
+ test.execute();
testExecuted();
}
}
- private void executeTest(CommandSession session) {
- test.execute(session);
+ private void executeTest() {
+ test.execute();
testExecuted();
- STSSuiteTestCollector.setTestCoverage(test.test, session);
}
public boolean hasChildren(Object element) {