From 2fb951a4a92e4a863a54c645bae18c2b9aa274bf Mon Sep 17 00:00:00 2001 From: jsimomaa Date: Thu, 15 Jun 2017 09:27:10 +0300 Subject: [PATCH] Add inclusion filter to modelled STS tests refs #7305 Change-Id: Iad8b19ceddaad0c493a2b8a8b5d267ab0abb0a8a --- .../META-INF/MANIFEST.MF | 3 +- .../modelled/junit/v2/ModelledSTSRunner.java | 16 +++++++++ .../junit/v2/ModelledSTSSuiteRunner.java | 34 +++++++++++++++++-- .../tests/modelled/utils/ModelledSTSTest.java | 3 +- 4 files changed, 52 insertions(+), 4 deletions(-) diff --git a/bundles/org.simantics.tests.modelled/META-INF/MANIFEST.MF b/bundles/org.simantics.tests.modelled/META-INF/MANIFEST.MF index 8f1829479..4cbcec294 100644 --- a/bundles/org.simantics.tests.modelled/META-INF/MANIFEST.MF +++ b/bundles/org.simantics.tests.modelled/META-INF/MANIFEST.MF @@ -10,7 +10,8 @@ Require-Bundle: org.simantics.tests.modelled.ontology, org.junit, org.simantics.modeling;bundle-version="1.1.1", org.slf4j.api, - org.simantics.db.testing + org.simantics.db.testing, + org.simantics.debug.browser;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Bundle-ActivationPolicy: lazy Export-Package: org.simantics.tests.modelled, diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java index 29628cec0..31077a080 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSRunner.java @@ -19,6 +19,7 @@ import org.simantics.tests.modelled.utils.STSSuiteTestCollector; public class ModelledSTSRunner extends ParentRunner { + 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 children; @@ -28,6 +29,8 @@ public class ModelledSTSRunner extends ParentRunner { try { initialize0(); Collection suites = STSSuiteTestCollector.collectTests(); + + // Filter exclusions String exclusionFilter = System.getProperty(EXCLUSION_FILTER); Collection filtered; if (exclusionFilter != null) { @@ -36,7 +39,18 @@ public class ModelledSTSRunner extends ParentRunner { } else { filtered = suites; } + // Filter inclusions +// String inclusionFilter = System.getProperty(INCLUSION_FILTER); +// Collection 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 sorted = included.stream().sorted((o1, o2) -> Integer.compare(o1.getPriority(), o2.getPriority())).collect(Collectors.toList()); List sorted = filtered.stream().sorted((o1, o2) -> Integer.compare(o1.getPriority(), o2.getPriority())).collect(Collectors.toList()); @@ -96,11 +110,13 @@ public class ModelledSTSRunner extends ParentRunner { private void initialize0() throws Exception { AcornTests.newSimanticsWorkspace(null, 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()); } } diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java index 11931d824..ac42653e5 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/junit/v2/ModelledSTSSuiteRunner.java @@ -25,11 +25,40 @@ public class ModelledSTSSuiteRunner extends ParentRunner super(ModelledSTSSuiteRunner.class); this.suite = suite; this.children = new ArrayList<>(suite.getChildren().size()); + + // Do possible filtering + // Filter exclusions + String exclusionFilter = System.getProperty(ModelledSTSRunner.EXCLUSION_FILTER); + // Filter inclusions + String inclusionFilter = System.getProperty(ModelledSTSRunner.INCLUSION_FILTER); for (ModelledSTSTest test : suite.getSortedChildren()) { - children.add(new ModelledSTSTestRunner(test)); + boolean add = false; + if (exclusionFilter != null) { + String[] filters = exclusionFilter.split(","); + if (!startsWithAny(test, filters)) { + add = true; + } + } + if (inclusionFilter != null) { + String[] filters = inclusionFilter.split(","); + if (!startsWithAny(test, filters)) { + add = false; + } + } + if (add) + children.add(new ModelledSTSTestRunner(test)); } } + private static boolean startsWithAny(ModelledSTSTest test, String[] filters) { + for (String filter : filters) { + if (test.getName().contains(filter)) { + return true; + } + } + return false; + } + @Override protected String getName() { return suite.getName(); @@ -61,7 +90,8 @@ public class ModelledSTSSuiteRunner extends ParentRunner } notifier.fireTestStarted(description); List newVars = child.runWithVars(variables); - storedVariables.put(child.getTest().getName(), newVars); +// TODO: FIX THIS BY NOT ADDING ALL VARIABLES TO MEMORY (CAN BE HUGE) +// storedVariables.put(child.getTest().getName(), newVars); notifier.fireTestFinished(description); } catch (Throwable e) { notifier.fireTestFailure(new Failure(description, e)); diff --git a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java index 33e4c25e2..c0ed9b191 100644 --- a/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java +++ b/bundles/org.simantics.tests.modelled/src/org/simantics/tests/modelled/utils/ModelledSTSTest.java @@ -94,6 +94,7 @@ public class ModelledSTSTest { public List run(List vars) throws IOException { ModuleRepository repo = new ModuleRepository(SCLOsgi.SOURCE_REPOSITORY); + CommandSession session = null; try { repo.setAdvisor(new ModuleCompilationOptionsAdvisor() { @@ -113,7 +114,7 @@ public class ModelledSTSTest { }); SCLReportingHandler handler = (SCLReportingHandler) SCLContext.getCurrent().get(SCLReportingHandler.REPORTING_HANDLER); - CommandSession session = new CommandSession(repo, handler); + session = new CommandSession(repo, handler); for (CommandSessionVariable var : vars) session.setVariable(var.getName(), var.getType(), var.getValue()); -- 2.43.2