X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Ftests%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2FTestBase.java;h=466c0978b6ec56ac57e12c2952ea7d916ab6d10e;hp=7a445392db34a2d38102d8de5e5040cc9e46229e;hb=9a175feb652b2b7bba7afa540831b9076be3c10e;hpb=0b72d3e4ec886838314ffeba0fa201e32c0aae3e diff --git a/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/TestBase.java b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/TestBase.java index 7a445392d..466c0978b 100644 --- a/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/TestBase.java +++ b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/TestBase.java @@ -3,6 +3,7 @@ package org.simantics.scl.compiler.tests; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.Arrays; import java.util.regex.Pattern; @@ -13,6 +14,7 @@ import org.simantics.scl.compiler.module.ImportDeclaration; import org.simantics.scl.compiler.module.Module; import org.simantics.scl.compiler.module.repository.ModuleRepository; import org.simantics.scl.compiler.module.repository.UpdateListener; +import org.simantics.scl.compiler.source.ModuleSource; import org.simantics.scl.compiler.source.StringModuleSource; import org.simantics.scl.compiler.source.repository.CompositeModuleSourceRepository; import org.simantics.scl.compiler.source.repository.MapModuleSourceRepository; @@ -26,7 +28,7 @@ public class TestBase { SourceRepositories.BUILTIN_SOURCE_REPOSITORY, SourceRepositories.PRELUDE_SOURCE_REPOSITORY )); - private static final Pattern TEST_SEPARATOR = Pattern.compile("^-- *$", Pattern.MULTILINE); + private static final Pattern TEST_SEPARATOR = Pattern.compile("^--+ *$", Pattern.MULTILINE); private static final Charset UTF8 = Charset.forName("UTF-8"); String path; @@ -35,17 +37,36 @@ public class TestBase { this.path = path; } - protected void test() { String testModuleName = Thread.currentThread().getStackTrace()[2].getMethodName(); String testPath = path + "/" + testModuleName + ".scl"; try { String[] testParts = readTestParts(testPath); - for(int i=0;i auxModuleNameList = new ArrayList(); + while(j < testParts.length) { + String part = testParts[j]; + if(part.startsWith("// module ")) + auxModuleNameList.add(part.substring(10).split("\\n", 2)[0].trim()); + else + break; + ++j; + } + int mainId = j; + String[] moduleNames = new String[mainId+1]; + String[] moduleTexts = new String[mainId+1]; + for(int i=0;i result = testEnvironment.getModule(testModuleName); + new MapModuleSourceRepository(moduleSources)); + int lastId = moduleNames.length-1; + Failable result = testEnvironment.getModule(moduleNames[lastId]); if(!result.didSucceed()) - return ((Failure)result).toString(input); + return ((Failure)result).toString(moduleTexts[lastId]); else { - Object main = testEnvironment.getRuntimeModule(testModuleName).getResult().getValue("main"); + Object main = testEnvironment.getRuntimeModule(moduleNames[lastId]).getResult().getValue("main"); return String.valueOf(main); } } @@ -97,9 +128,11 @@ public class TestBase { } String text = new String(buffer, 0, pos, UTF8); String[] result = TEST_SEPARATOR.split(text); - if(result.length % 2 == 1) { - result = Arrays.copyOf(result, result.length+2); - result[result.length-1] = ""; + for(int i=1;i