annotate graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java @ 21490:3286fb5fea4a

Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Tue, 26 May 2015 19:11:36 +0200
parents 286aef83a9a7
children 31fc2fce38f3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
1 /*
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved.
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
4 *
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
8 *
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
14 *
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
18 *
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
21 * questions.
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
22 */
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
23 package com.oracle.truffle.sl.test;
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
24
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
25 import java.io.*;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
26 import java.nio.charset.*;
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
27 import java.nio.file.*;
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
28 import java.nio.file.attribute.*;
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
29 import java.util.*;
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
30
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
31 import org.junit.*;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
32 import org.junit.internal.*;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
33 import org.junit.runner.*;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
34 import org.junit.runner.manipulation.*;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
35 import org.junit.runner.notification.*;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
36 import org.junit.runners.*;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
37 import org.junit.runners.model.*;
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
38
17006
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
39 import com.oracle.truffle.api.dsl.*;
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21469
diff changeset
40 import com.oracle.truffle.api.vm.TruffleVM;
21468
99942eac9c6d Introducing TruffleVM - a central place to invoke code in any registered TruffleLanguage.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 18485
diff changeset
41 import com.oracle.truffle.sl.SLMain;
17006
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
42 import com.oracle.truffle.sl.builtins.*;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
43 import com.oracle.truffle.sl.test.SLTestRunner.TestCase;
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
44
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
45 public final class SLTestRunner extends ParentRunner<TestCase> {
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
46
17007
004e3f0a0517 Truffle: added new infrastructure for graal truffle runtime tests using SL.
Christian Humer <christian.humer@gmail.com>
parents: 17006
diff changeset
47 private static int repeats = 1;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
48
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
49 private static final String SOURCE_SUFFIX = ".sl";
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
50 private static final String INPUT_SUFFIX = ".input";
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
51 private static final String OUTPUT_SUFFIX = ".output";
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
52
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
53 private static final String LF = System.getProperty("line.separator");
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
54
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
55 static class TestCase {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
56 protected final Description name;
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
57 protected final Path path;
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
58 protected final String sourceName;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
59 protected final String testInput;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
60 protected final String expectedOutput;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
61 protected String actualOutput;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
62
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
63 protected TestCase(Class<?> testClass, String baseName, String sourceName, Path path, String testInput, String expectedOutput) {
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
64 this.name = Description.createTestDescription(testClass, baseName);
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
65 this.sourceName = sourceName;
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
66 this.path = path;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
67 this.testInput = testInput;
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
68 this.expectedOutput = expectedOutput;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
69 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
70 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
71
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
72 private final List<TestCase> testCases;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
73
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
74 public SLTestRunner(Class<?> runningClass) throws InitializationError {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
75 super(runningClass);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
76 try {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
77 testCases = createTests(runningClass);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
78 } catch (IOException e) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
79 throw new InitializationError(e);
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
80 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
81 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
82
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
83 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
84 protected Description describeChild(TestCase child) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
85 return child.name;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
86 }
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
87
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
88 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
89 protected List<TestCase> getChildren() {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
90 return testCases;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
91 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
92
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
93 protected static List<TestCase> createTests(final Class<?> c) throws IOException, InitializationError {
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
94 SLTestSuite suite = c.getAnnotation(SLTestSuite.class);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
95 if (suite == null) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
96 throw new InitializationError(String.format("@%s annotation required on class '%s' to run with '%s'.", SLTestSuite.class.getSimpleName(), c.getName(), SLTestRunner.class.getSimpleName()));
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
97 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
98
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
99 String[] pathes = suite.value();
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
100
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
101 Path root = null;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
102 for (String path : pathes) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
103 root = FileSystems.getDefault().getPath(path);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
104 if (Files.exists(root)) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
105 break;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
106 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
107 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
108 if (root == null && pathes.length > 0) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
109 throw new FileNotFoundException(pathes[0]);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
110 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
111
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
112 final Path rootPath = root;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
113
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
114 final List<TestCase> foundCases = new ArrayList<>();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
115 Files.walkFileTree(rootPath, new SimpleFileVisitor<Path>() {
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
116 @Override
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
117 public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
118 String sourceName = sourceFile.getFileName().toString();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
119 if (sourceName.endsWith(SOURCE_SUFFIX)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
120 String baseName = sourceName.substring(0, sourceName.length() - SOURCE_SUFFIX.length());
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
121
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
122 Path inputFile = sourceFile.resolveSibling(baseName + INPUT_SUFFIX);
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
123 String testInput = "";
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
124 if (Files.exists(inputFile)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
125 testInput = readAllLines(inputFile);
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
126 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
127
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
128 Path outputFile = sourceFile.resolveSibling(baseName + OUTPUT_SUFFIX);
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
129 String expectedOutput = "";
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
130 if (Files.exists(outputFile)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
131 expectedOutput = readAllLines(outputFile);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
132 }
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
133
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
134 foundCases.add(new TestCase(c, baseName, sourceName, sourceFile, testInput, expectedOutput));
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
135 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
136 return FileVisitResult.CONTINUE;
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
137 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
138 });
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
139 return foundCases;
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
140 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
141
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
142 private static String readAllLines(Path file) throws IOException {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
143 // fix line feeds for non unix os
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
144 StringBuilder outFile = new StringBuilder();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
145 for (String line : Files.readAllLines(file, Charset.defaultCharset())) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
146 outFile.append(line).append(LF);
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
147 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
148 return outFile.toString();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
149 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
150
17006
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
151 public static void setRepeats(int repeats) {
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
152 SLTestRunner.repeats = repeats;
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
153 }
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
154
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
155 private static final List<NodeFactory<? extends SLBuiltinNode>> builtins = new ArrayList<>();
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
156
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
157 public static void installBuiltin(NodeFactory<? extends SLBuiltinNode> builtin) {
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
158 builtins.add(builtin);
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
159 }
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
160
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
161 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
162 protected void runChild(TestCase testCase, RunNotifier notifier) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
163 notifier.fireTestStarted(testCase.name);
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
164
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
165 ByteArrayOutputStream out = new ByteArrayOutputStream();
21469
286aef83a9a7 Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21468
diff changeset
166 PrintWriter printer = new PrintWriter(out);
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
167 try {
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21469
diff changeset
168 TruffleVM vm = TruffleVM.newVM().stdIn(new BufferedReader(new StringReader(repeat(testCase.testInput, repeats)))).stdOut(printer).build();
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21469
diff changeset
169
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21469
diff changeset
170 String script = readAllLines(testCase.path);
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21469
diff changeset
171 SLMain.run(vm, testCase.path.toUri(), null, printer, repeats, builtins);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
172
21469
286aef83a9a7 Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21468
diff changeset
173 printer.flush();
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
174 String actualOutput = new String(out.toByteArray());
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21469
diff changeset
175 Assert.assertEquals(script, repeat(testCase.expectedOutput, repeats), actualOutput);
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
176 } catch (Throwable ex) {
21490
3286fb5fea4a Introducing standard I/O and error into Env and using TruffleVM to execute SL test cases. Adding SLTckTest to verify SL language interop.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21469
diff changeset
177 notifier.fireTestFailure(new Failure(testCase.name, new IllegalStateException("Cannot run " + testCase.sourceName, ex)));
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
178 } finally {
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
179 notifier.fireTestFinished(testCase.name);
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
180 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
181 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
182
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
183 private static String repeat(String s, int count) {
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
184 StringBuilder result = new StringBuilder(s.length() * count);
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
185 for (int i = 0; i < count; i++) {
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
186 result.append(s);
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
187 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
188 return result.toString();
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
189 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
190
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
191 public static void runInMain(Class<?> testClass, String[] args) throws InitializationError, NoTestsRemainException {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
192 JUnitCore core = new JUnitCore();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
193 core.addListener(new TextListener(System.out));
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
194 SLTestRunner suite = new SLTestRunner(testClass);
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
195 if (args.length > 0) {
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
196 suite.filter(new NameFilter(args[0]));
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
197 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
198 Result r = core.run(suite);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
199 if (!r.wasSuccessful()) {
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
200 System.exit(1);
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
201 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
202 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
203
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
204 private static final class NameFilter extends Filter {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
205 private final String pattern;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
206
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
207 private NameFilter(String pattern) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
208 this.pattern = pattern.toLowerCase();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
209 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
210
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
211 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
212 public boolean shouldRun(Description description) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
213 return description.getMethodName().toLowerCase().contains(pattern);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
214 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
215
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
216 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
217 public String describe() {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
218 return "Filter contains " + pattern;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
219 }
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
220 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
221
13762
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
222 }