1 package org.simantics.tests.modelled.junit.v2;
3 import java.util.ArrayList;
4 import java.util.HashMap;
8 import org.junit.runner.Description;
9 import org.junit.runner.notification.Failure;
10 import org.junit.runner.notification.RunNotifier;
11 import org.junit.runners.ParentRunner;
12 import org.junit.runners.model.InitializationError;
13 import org.simantics.scl.compiler.module.coverage.CombinedCoverage;
14 import org.simantics.tests.modelled.utils.ModelledSTSSuite;
15 import org.simantics.tests.modelled.utils.ModelledSTSTest;
16 import org.simantics.tests.modelled.utils.ModelledSTSTest.CommandSessionVariable;
18 public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner> {
20 private final ModelledSTSSuite suite;
21 private final List<ModelledSTSTestRunner> children;
22 private Map<String, List<CommandSessionVariable>> storedVariables = new HashMap<>();
24 public ModelledSTSSuiteRunner(ModelledSTSSuite suite) throws InitializationError {
25 super(ModelledSTSSuiteRunner.class);
27 this.children = new ArrayList<>(suite.getChildren().size());
29 // Do possible filtering
31 String exclusionFilter = System.getProperty(ModelledSTSRunner.EXCLUSION_FILTER);
33 String inclusionFilter = System.getProperty(ModelledSTSRunner.INCLUSION_FILTER);
34 for (ModelledSTSTest test : suite.getSortedChildren()) {
36 if (exclusionFilter != null) {
37 String[] filters = exclusionFilter.split(",");
38 if (!startsWithAny(test, filters)) {
42 if (inclusionFilter != null) {
43 String[] filters = inclusionFilter.split(",");
44 if (!startsWithAny(test, filters)) {
49 children.add(new ModelledSTSTestRunner(test));
53 private static boolean startsWithAny(ModelledSTSTest test, String[] filters) {
54 for (String filter : filters) {
55 if (test.getName().contains(filter)) {
63 protected String getName() {
64 return suite.getName();
68 protected List<ModelledSTSTestRunner> getChildren() {
73 protected Description describeChild(ModelledSTSTestRunner child) {
74 return child.getDescription();
78 protected void runChild(ModelledSTSTestRunner child, RunNotifier notifier) {
79 Description description = describeChild(child);
80 if (isIgnored(child)) {
81 notifier.fireTestIgnored(description);
84 List<CommandSessionVariable> variables = new ArrayList<>();
85 for (String dep : child.getTest().getDependencies()) {
86 List<CommandSessionVariable> storedVars = storedVariables.get(dep);
87 if (storedVars != null) {
88 variables.addAll(storedVars);
91 notifier.fireTestStarted(description);
92 List<CommandSessionVariable> newVars = child.runWithVars(variables);
93 // TODO: FIX THIS BY NOT ADDING ALL VARIABLES TO MEMORY (CAN BE HUGE)
94 // storedVariables.put(child.getTest().getName(), newVars);
95 notifier.fireTestFinished(description);
96 } catch (Throwable e) {
97 notifier.fireTestFailure(new Failure(description, e));
103 protected boolean isIgnored(ModelledSTSTestRunner child) {
104 return child.isIgnored();
107 public CombinedCoverage getCoverage() {
108 return suite.getCoverage();