]> gerrit.simantics Code Review - simantics/platform.git/blob - tests/org.simantics.scl.compiler.tests/src/org/simantics/scl/compiler/tests/ScriptTestBase.java
Merge commit '876ede6'
[simantics/platform.git] / tests / org.simantics.scl.compiler.tests / src / org / simantics / scl / compiler / tests / ScriptTestBase.java
1 package org.simantics.scl.compiler.tests;
2
3 import java.io.BufferedReader;
4 import java.io.InputStreamReader;
5 import java.nio.charset.Charset;
6
7 import org.junit.Before;
8 import org.simantics.scl.compiler.commands.CommandSession;
9 import org.simantics.scl.compiler.commands.TestScriptExecutor;
10 import org.simantics.scl.compiler.module.repository.ModuleRepository;
11 import org.simantics.scl.compiler.source.repository.CompositeModuleSourceRepository;
12 import org.simantics.scl.compiler.source.repository.SourceRepositories;
13
14 public class ScriptTestBase {
15     
16     private final String path;
17     
18     ModuleRepository moduleRepository;
19     
20     public ScriptTestBase(String path) {
21         this.path = path;
22     }
23     
24     @Before
25     public void initialize() throws Exception {
26         moduleRepository = new ModuleRepository(
27                 new CompositeModuleSourceRepository(
28                         SourceRepositories.BUILTIN_SOURCE_REPOSITORY,
29                         SourceRepositories.PRELUDE_SOURCE_REPOSITORY
30                         ));
31     }
32     
33     protected void test() throws Exception {
34         String testScriptName = Thread.currentThread().getStackTrace()[2].getMethodName();
35         String testPath = "scripts/" + testScriptName + ".sts";
36
37         CommandSession session = new CommandSession(moduleRepository, null);
38         new TestScriptExecutor(session, 
39                 new BufferedReader(
40                         new InputStreamReader(getClass().getResourceAsStream(testPath), Charset.forName("UTF-8"))),
41                         null)
42         .execute();
43     }
44     
45 }