@L0.assert TESTS.STSSuite.moduleNameFilter ""
@L0.assert TESTS.ignore false
@L0.assert TESTS.dependencies ""
+ @L0.assert TESTS.STSTest.executionPriority -1
TESTS.STSSuite : MOD.TypeWithChangeInformation
TESTS.STSSuite : L0.TypeWithIdentifier
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.stream.Collectors;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.runner.Description;
public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
+ public static final String EXCLUSION_FILTER = "org.simantics.tests.modelled.excludeFilter";
+
private final List<ModelledSTSSuiteRunner> children;
public ModelledSTSRunner(Class<?> testClass) throws InitializationError {
try {
initialize0();
Collection<ModelledSTSSuite> suites = STSSuiteTestCollector.collectTests();
- children = new ArrayList<>(suites.size());
- for (ModelledSTSSuite suite : suites) {
+ String exclusionFilter = System.getProperty(EXCLUSION_FILTER);
+ Collection<ModelledSTSSuite> filtered;
+ if (exclusionFilter != null) {
+ String[] filters = exclusionFilter.split(",");
+ filtered = suites.stream().filter(s -> !startsWithAny(s, filters)).collect(Collectors.toList());
+ } else {
+ filtered = suites;
+ }
+ // Sort by priority
+ List<ModelledSTSSuite> sorted = filtered.stream().sorted((o1, o2) -> Integer.compare(o1.getPriority(), o2.getPriority())).collect(Collectors.toList());
+
+
+ children = new ArrayList<>(sorted.size());
+ for (ModelledSTSSuite suite : sorted) {
children.add(new ModelledSTSSuiteRunner(suite));
}
} catch (Exception e) {
}
}
+ private static boolean startsWithAny(ModelledSTSSuite suite, String[] filters) {
+ for (String filter : filters) {
+ if (suite.getName().contains(filter)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
@Override
protected List<ModelledSTSSuiteRunner> getChildren() {
return children;
package org.simantics.tests.modelled.junit.v2;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
private final ModelledSTSSuite suite;
private final List<ModelledSTSTestRunner> children;
- private Map<String, List<CommandSessionVariable>> storedVariables;
+ private Map<String, List<CommandSessionVariable>> storedVariables = new HashMap<>();
public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws InitializationError {
super(ModelledSTSSuiteRunner.class);
variables.addAll(storedVars);
}
}
+ notifier.fireTestStarted(description);
List<CommandSessionVariable> newVars = child.runWithVars(variables);
storedVariables.put(child.getTest().getName(), newVars);
notifier.fireTestFinished(description);
- } catch (Exception e) {
+ } catch (Throwable e) {
notifier.fireTestFailure(new Failure(description, e));
}
}
private String name;
private List<ModelledSTSTest> children;
+ private int priority;
private String moduleNameFilter;
private List<Pattern> moduleNameFilterPatterns = new ArrayList<>();
private CoverageBuilder coverageBuilder;
private Map<String, String> variables;
- ModelledSTSSuite(String name, List<ModelledSTSTest> children, String moduleNameFilter, Map<String, String> variables) {
+ ModelledSTSSuite(String name, List<ModelledSTSTest> children, String moduleNameFilter, int priority, Map<String, String> variables) {
this.name = name;
+ this.priority = priority;
this.children = children;
this.variables = variables;
this.moduleNameFilter = moduleNameFilter;
return moduleNameFilterPatterns;
}
+ public int getPriority() {
+ return priority;
+ }
+
}
public List<CommandSessionVariable> run(List<CommandSessionVariable> vars) throws IOException {
ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY);
- repo.setAdvisor(new ModuleCompilationOptionsAdvisor() {
+ try {
+ repo.setAdvisor(new ModuleCompilationOptionsAdvisor() {
+
+ @Override
+ public ModuleCompilationOptions getOptions(String moduleName) {
+ // TODO: default to false
+ boolean coverage = true;
+ // TODO: add moduleName filters back
+ // for (Pattern p : getModuleNameFilterPatterns()) {
+ // if (p.matcher(moduleName.toLowerCase()).find()) {
+ // coverage = true;
+ // break;
+ // }
+ // }
+ return new ModuleCompilationOptions(coverage);
+ }
+ });
- @Override
- public ModuleCompilationOptions getOptions(String moduleName) {
- // TODO: default to false
- boolean coverage = true;
- // TODO: add moduleName filters back
-// for (Pattern p : getModuleNameFilterPatterns()) {
-// if (p.matcher(moduleName.toLowerCase()).find()) {
-// coverage = true;
-// break;
-// }
-// }
- return new ModuleCompilationOptions(coverage);
- }
- });
-
- SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
- CommandSession session = new CommandSession(repo, handler);
-
- for (CommandSessionVariable var : vars)
- session.setVariable(var.getName(), var.getType(), var.getValue());
-
- for (Map.Entry<String, String> entry : variables.entrySet())
- session.setVariable(entry.getKey(), Types.STRING, entry.getValue());
-
- new TestScriptExecutor(session, new BufferedReader(new StringReader(code)), handler, true).execute();
- STSSuiteTestCollector.setTestCoverage(this, session);
-
- // Return variables from this session
- List<CommandSessionVariable> result = new ArrayList<>();
- for (String var : session.getVariables())
- result.add(new CommandSessionVariable(var, session.getVariableType(var), session.getVariableValue(var)));
-
- return result;
+ SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER);
+ CommandSession session = new CommandSession(repo, handler);
+
+ for (CommandSessionVariable var : vars)
+ session.setVariable(var.getName(), var.getType(), var.getValue());
+
+ for (Map.Entry<String, String> entry : variables.entrySet())
+ session.setVariable(entry.getKey(), Types.STRING, entry.getValue());
+
+ new TestScriptExecutor(session, new BufferedReader(new StringReader(code)), handler, true).execute();
+ STSSuiteTestCollector.setTestCoverage(this, session);
+
+ // Return variables from this session
+ List<CommandSessionVariable> result = new ArrayList<>();
+ for (String var : session.getVariables())
+ result.add(new CommandSessionVariable(var, session.getVariableType(var), session.getVariableValue(var)));
+
+ return result;
+ } finally {
+ // remember to flush this repository
+ repo.flush();
+ }
}
public Set<String> getDependencies() {
TestsResource TESTS = TestsResource.getInstance(graph);
String suiteName = graph.getURI(suite);
String moduleNameFilter = graph.getPossibleRelatedValue2(suite, TESTS.STSSuite_moduleNameFilter, Bindings.STRING);
+ Integer priority = graph.getPossibleRelatedValue2(suite, TESTS.STSTest_executionPriority, Bindings.INTEGER);
Layer0 L0 = Layer0.getInstance(graph);
Collection<Resource> stsVariables = graph.sync(new ObjectsWithType(suite, L0.ConsistsOf, TESTS.STSVariable));
String value = graph.getRelatedValue(stsVariable, TESTS.STSVariable_definition);
variables.put(name, value);
}
- return new ModelledSTSSuite(suiteName, children, moduleNameFilter, variables);
+ return new ModelledSTSSuite(suiteName, children, moduleNameFilter, priority != null ? priority : -1, variables);
}
public static void setTestCoverage(ModelledSTSTest test, CommandSession session) {