]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java
Builtins and JavaModule SCL modules may leak memory
[simantics/platform.git] / bundles / org.simantics.tests.modelled / src / org / simantics / tests / modelled / utils / ModelledSTSTest.java
index 3430696b81456e5959d35b001da7319df906baac..0c0d8682a5706688c6031f8f68698823390ccb89 100644 (file)
@@ -8,13 +8,12 @@ import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.regex.Pattern;
 
 import org.simantics.scl.compiler.commands.CommandSession;
 import org.simantics.scl.compiler.commands.TestScriptExecutor;
+import org.simantics.scl.compiler.elaboration.java.Builtins;
+import org.simantics.scl.compiler.elaboration.java.JavaModule;
 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.compiler.types.Type;
 import org.simantics.scl.compiler.types.Types;
@@ -25,6 +24,7 @@ import org.simantics.scl.runtime.reporting.SCLReportingHandler;
 public class ModelledSTSTest {
 
     private final String name;
+    private final String parentName;
     private final String code;
     private final int priority;
     private final boolean ignored;
@@ -34,8 +34,9 @@ public class ModelledSTSTest {
     private CombinedCoverage coverage;
     private Map<String, String> variables;
 
-    ModelledSTSTest(String name, String code, int priority, boolean ignored, Set<String> dependencies, Map<String, String> variables) {
+    ModelledSTSTest(String name, String parentName, String code, int priority, boolean ignored, Set<String> dependencies, Map<String, String> variables) {
         this.name = name;
+        this.parentName = parentName;
         this.code = code;
         this.priority = priority;
         this.ignored = ignored;
@@ -48,6 +49,10 @@ public class ModelledSTSTest {
         return name;
     }
 
+    public String getParentName() {
+        return parentName;
+    }
+
     public String getCode() {
         return code;
     }
@@ -95,41 +100,49 @@ public class ModelledSTSTest {
     
     public List<CommandSessionVariable> run(List<CommandSessionVariable> vars) throws IOException {
         ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY);
-        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;
-//                    }
+        CommandSession session = null;
+        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);
 //                }
-                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);
+            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();
+            Builtins.flush();
+            JavaModule.flush();
+        }
     }
 
     public Set<String> getDependencies() {
@@ -143,4 +156,65 @@ public class ModelledSTSTest {
     public boolean resolveDependency(String testDep) {
         return unresolvedDependencies.remove(testDep);
     }
+
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((code == null) ? 0 : code.hashCode());
+        result = prime * result + ((coverage == null) ? 0 : coverage.hashCode());
+        result = prime * result + ((dependencies == null) ? 0 : dependencies.hashCode());
+        result = prime * result + (ignored ? 1231 : 1237);
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + priority;
+        result = prime * result + ((unresolvedDependencies == null) ? 0 : unresolvedDependencies.hashCode());
+        result = prime * result + ((variables == null) ? 0 : variables.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj)
+            return true;
+        if (obj == null)
+            return false;
+        if (getClass() != obj.getClass())
+            return false;
+        ModelledSTSTest other = (ModelledSTSTest) obj;
+        if (code == null) {
+            if (other.code != null)
+                return false;
+        } else if (!code.equals(other.code))
+            return false;
+        if (coverage == null) {
+            if (other.coverage != null)
+                return false;
+        } else if (!coverage.equals(other.coverage))
+            return false;
+        if (dependencies == null) {
+            if (other.dependencies != null)
+                return false;
+        } else if (!dependencies.equals(other.dependencies))
+            return false;
+        if (ignored != other.ignored)
+            return false;
+        if (name == null) {
+            if (other.name != null)
+                return false;
+        } else if (!name.equals(other.name))
+            return false;
+        if (priority != other.priority)
+            return false;
+        if (unresolvedDependencies == null) {
+            if (other.unresolvedDependencies != null)
+                return false;
+        } else if (!unresolvedDependencies.equals(other.unresolvedDependencies))
+            return false;
+        if (variables == null) {
+            if (other.variables != null)
+                return false;
+        } else if (!variables.equals(other.variables))
+            return false;
+        return true;
+    }
 }