X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.tests.modelled.ui%2Fsrc%2Forg%2Fsimantics%2Ftests%2Fmodelled%2Fui%2FSTSTestSuiteModel.java;h=b6cda3fdc817aaafc77e1560b89a16195eb2c3ab;hp=976efa2c2d2a0aab10b40125ed664672c2b4f9d9;hb=1ec0193a5a5b8f368b03adb24acd762838ddf8ea;hpb=06ee0c4c71cd9e372969da1570e7fcac2c4397a5 diff --git a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java index 976efa2c2..b6cda3fdc 100644 --- a/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java +++ b/bundles/org.simantics.tests.modelled.ui/src/org/simantics/tests/modelled/ui/STSTestSuiteModel.java @@ -1,13 +1,16 @@ 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; @@ -15,22 +18,21 @@ import org.simantics.db.Resource; 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> storedVars = new HashMap<>(); + + class STSTest { private final ModelledSTSTest test; @@ -66,31 +68,41 @@ public class STSTestSuiteModel { 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 resolvedVars = new ArrayList<>(); + for (String deps : test.getDependencies()) { + List vars = storedVars.get(deps); + if (vars != null) + resolvedVars.addAll(vars); + } + + List vars = test.run(resolvedVars); + storedVars.put(test.getName(), vars); + executed = true; } catch (Throwable t) { t.printStackTrace(); @@ -101,8 +113,9 @@ public class STSTestSuiteModel { isRunning = false; long end = System.currentTimeMillis(); duration = end - start; + + SCLContext.getCurrent().put(SCLReportingHandler.REPORTING_HANDLER, old); } - } protected void appendOutput(String text) { @@ -135,7 +148,7 @@ public class STSTestSuiteModel { } } - static class STSSuite { + class STSSuite { private ModelledSTSSuite suite; private STSTest[] children; @@ -216,6 +229,7 @@ public class STSTestSuiteModel { private STSSuite suite; private STSTest test; private final List listeners = new ArrayList<>(); + private Job currentJob; public STSTestSuiteModel() { } @@ -237,30 +251,47 @@ public class 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() { @@ -269,23 +300,21 @@ public class STSTestSuiteModel { }); } - 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) {