]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java
Add inclusion filter to modelled STS tests
[simantics/platform.git] / bundles / org.simantics.tests.modelled / src / org / simantics / tests / modelled / junit / v2 / ModelledSTSRunner.java
index c74f6efaea0fb0485f377177eba45ecfe26191d2..31077a080d75d8e2c18352dab1a2dbdc264d70f4 100644 (file)
@@ -1,5 +1,7 @@
 package org.simantics.tests.modelled.junit.v2;
 
+import java.util.ArrayList;
+import java.util.Collection;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -12,28 +14,67 @@ import org.junit.runners.ParentRunner;
 import org.junit.runners.model.InitializationError;
 import org.simantics.Simantics;
 import org.simantics.db.testing.common.AcornTests;
-import org.simantics.scl.compiler.commands.CommandSession;
-import org.simantics.scl.osgi.SCLOsgi;
+import org.simantics.tests.modelled.utils.ModelledSTSSuite;
 import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
 
 public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
 
-    private CommandSession commandSession;
+    public static final String INCLUSION_FILTER = "org.simantics.tests.modelled.singleTestIncludeFilter";
+    public static final String EXCLUSION_FILTER = "org.simantics.tests.modelled.excludeFilter";
+    
+    private final List<ModelledSTSSuiteRunner> children;
 
-    public ModelledSTSRunner(Class<?> testClass) throws Exception {
+    public ModelledSTSRunner(Class<?> testClass) throws InitializationError {
         super(testClass);
-        initialize0();
+        try {
+            initialize0();
+            Collection<ModelledSTSSuite> suites = STSSuiteTestCollector.collectTests();
+            
+            // Filter exclusions
+            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;
+            }
+            // Filter inclusions
+//            String inclusionFilter = System.getProperty(INCLUSION_FILTER);
+//            Collection<ModelledSTSSuite> included;
+//            if (inclusionFilter != null) {
+//                String[] filters = inclusionFilter.split(",");
+//                included = filtered.stream().filter(s -> startsWithAny(s, filters)).collect(Collectors.toList());
+//            } else {
+//                included = filtered;
+//            }
+            
+            // Sort by priority
+//            List<ModelledSTSSuite> sorted = included.stream().sorted((o1, o2) -> Integer.compare(o1.getPriority(), o2.getPriority())).collect(Collectors.toList());
+            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) {
+            throw new InitializationError(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 STSSuiteTestCollector.collectTests().stream().map(suite -> {
-            try {
-                return new ModelledSTSSuiteRunner(suite);
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-        }).collect(Collectors.toList());
+        return children;
     }
 
     @Override
@@ -55,7 +96,6 @@ public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
 
     @Override
     protected void runChild(ModelledSTSSuiteRunner child, RunNotifier notifier) {
-        child.setCommandSesssion(commandSession);
         child.run(notifier);
         // TODO: Add coverage reporting to ModelledSTSRunner
 //        CombinedCoverage cover = child.getCoverage();
@@ -70,12 +110,13 @@ public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
 
     private void initialize0() throws Exception {
         AcornTests.newSimanticsWorkspace(null, null);
-        this.commandSession = new CommandSession(SCLOsgi.MODULE_REPOSITORY, null);
+        org.simantics.debug.browser.internal.Activator.getDefault().startDebugServer();
         initialize();
     }
 
     private void deinitialize0() throws Exception {
         deinitialize();
+        org.simantics.debug.browser.internal.Activator.getDefault().stopDebugServer();
         Simantics.shutdown(new NullProgressMonitor());
     }
 }