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;
public class ModelledSTSTest {
private final String name;
+ private final String parentName;
private final String code;
private final int priority;
private final boolean ignored;
+ private Set<String> imports;
private Set<String> dependencies;
private Set<String> unresolvedDependencies;
-
+
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> imports, Set<String> dependencies, Map<String, String> variables) {
this.name = name;
+ this.parentName = parentName;
this.code = code;
this.priority = priority;
this.ignored = ignored;
+ this.imports = imports;
this.dependencies = dependencies;
this.unresolvedDependencies = new HashSet<>(dependencies);
this.variables = variables;
return name;
}
+ public String getParentName() {
+ return parentName;
+ }
+
public String getCode() {
return code;
}
return value;
}
}
-
+
public List<CommandSessionVariable> run(List<CommandSessionVariable> vars) throws IOException {
- ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY);
+// ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY);
+ ModuleRepository repo = SCLOsgi.MODULE_REPOSITORY;
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;
+// 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);
session = new CommandSession(repo, handler);
-
+
+ for(String imp : imports) {
+ session.execute("import \"" + imp + "\"");
+ }
+
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();
+
+ new TestScriptExecutor(session, new BufferedReader(new StringReader(code)), handler, false).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();
+// repo.flush();
+ Builtins.flush();
+ JavaModule.flush();
}
}
public Set<String> getDependencies() {
return dependencies;
}
-
+
public Set<String> getUnresolvedDependencies() {
return unresolvedDependencies;
}
-
+
public boolean resolveDependency(String testDep) {
return unresolvedDependencies.remove(testDep);
}
int result = 1;
result = prime * result + ((code == null) ? 0 : code.hashCode());
result = prime * result + ((coverage == null) ? 0 : coverage.hashCode());
+ result = prime * result + ((imports == null) ? 0 : imports.hashCode());
result = prime * result + ((dependencies == null) ? 0 : dependencies.hashCode());
result = prime * result + (ignored ? 1231 : 1237);
result = prime * result + ((name == null) ? 0 : name.hashCode());
return false;
} else if (!coverage.equals(other.coverage))
return false;
+ if (imports== null) {
+ if (other.imports != null)
+ return false;
+ } else if (!imports.equals(other.imports))
+ return false;
if (dependencies == null) {
if (other.dependencies != null)
return false;