X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.scl.compiler%2Ftests%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2FScriptTestBase.java;fp=bundles%2Forg.simantics.scl.compiler%2Ftests%2Forg%2Fsimantics%2Fscl%2Fcompiler%2Ftests%2FScriptTestBase.java;h=9e4401d895644ed5798307bb9c449d8cd54469b3;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/ScriptTestBase.java b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/ScriptTestBase.java new file mode 100644 index 000000000..9e4401d89 --- /dev/null +++ b/bundles/org.simantics.scl.compiler/tests/org/simantics/scl/compiler/tests/ScriptTestBase.java @@ -0,0 +1,45 @@ +package org.simantics.scl.compiler.tests; + +import java.io.BufferedReader; +import java.io.InputStreamReader; +import java.nio.charset.Charset; + +import org.junit.Before; +import org.simantics.scl.compiler.commands.CommandSession; +import org.simantics.scl.compiler.commands.TestScriptExecutor; +import org.simantics.scl.compiler.module.repository.ModuleRepository; +import org.simantics.scl.compiler.source.repository.CompositeModuleSourceRepository; +import org.simantics.scl.compiler.source.repository.SourceRepositories; + +public class ScriptTestBase { + + private final String path; + + ModuleRepository moduleRepository; + + public ScriptTestBase(String path) { + this.path = path; + } + + @Before + public void initialize() throws Exception { + moduleRepository = new ModuleRepository( + new CompositeModuleSourceRepository( + SourceRepositories.BUILTIN_SOURCE_REPOSITORY, + SourceRepositories.PRELUDE_SOURCE_REPOSITORY + )); + } + + protected void test() throws Exception { + String testScriptName = Thread.currentThread().getStackTrace()[2].getMethodName(); + String testPath = "scripts/" + testScriptName + ".sts"; + + CommandSession session = new CommandSession(moduleRepository, null); + new TestScriptExecutor(session, + new BufferedReader( + new InputStreamReader(getClass().getResourceAsStream(testPath), Charset.forName("UTF-8"))), + null) + .execute(); + } + +}