]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Merge "Do not merge TG if it is not set as immutable"
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Mon, 5 Jun 2017 20:16:17 +0000 (23:16 +0300)
committerGerrit Code Review <gerrit2@www.simantics.org>
Mon, 5 Jun 2017 20:16:17 +0000 (23:16 +0300)
bundles/org.simantics.tests.modelled.ontology/graph/Tests.pgraph
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSSuite.java
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java
bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/STSSuiteTestCollector.java

index e3aa1f61f0a3aacd47b0ec72be8030506f191b26..59d9e578cafde5b49df06921c4fe8d4859cd562d 100644 (file)
@@ -41,6 +41,7 @@ TESTS.STSSuite <T L0.Entity
     @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
index e77224b58c72caa59b1e290831e817803844368e..29628cec061e8b4ef5117da84d45947524cd3893 100644 (file)
@@ -3,6 +3,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;
 
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.junit.runner.Description;
@@ -18,6 +19,8 @@ import org.simantics.tests.modelled.utils.STSSuiteTestCollector;
 
 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 {
@@ -25,8 +28,20 @@ public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
         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) {
@@ -34,6 +49,15 @@ public class ModelledSTSRunner extends ParentRunner<ModelledSTSSuiteRunner> {
         }
     }
 
+    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;
index 5b7a8ef0ac3d5b352052476055bd160b7c58531b..11931d824c3990c432aece73020949d1bb058491 100644 (file)
@@ -1,6 +1,7 @@
 package org.simantics.tests.modelled.junit.v2;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
@@ -18,7 +19,7 @@ public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner>
 
     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);
@@ -58,10 +59,11 @@ public class ModelledSTSSuiteRunner extends ParentRunner<ModelledSTSTestRunner>
                         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));
             }
         } 
index 7ccb3ccd358f52b7b443476ff8ade20b8c05883b..87f95ca1f64b7112cf17382bcdeacad6ea0c4339 100644 (file)
@@ -20,14 +20,16 @@ public class ModelledSTSSuite {
 
     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;
@@ -121,4 +123,8 @@ public class ModelledSTSSuite {
         return moduleNameFilterPatterns;
     }
 
+    public int getPriority() {
+        return priority;
+    }
+
 }
index 3430696b81456e5959d35b001da7319df906baac..6d9e4f4fece76c6cc9fe09e5e805735ff6c39206 100644 (file)
@@ -95,41 +95,46 @@ public class ModelledSTSTest {
     
     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() {
index 8917d16462425ddf65e93b20636d19dcaa766a78..58aa323e1e98e5053380b1579eaf2c27823f4e85 100644 (file)
@@ -102,6 +102,7 @@ public class STSSuiteTestCollector {
         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));
@@ -111,7 +112,7 @@ public class STSSuiteTestCollector {
             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) {