annotate truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents cf19259edf87
children 67f75f61c974 dcb70d90c11d
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 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
5 * The Universal Permissive License (UPL), Version 1.0
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22059
diff changeset
6 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
7 * Subject to the condition set forth below, permission is hereby granted to any
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
8 * person obtaining a copy of this software, associated documentation and/or
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
9 * data (collectively the "Software"), free of charge and under any and all
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
10 * copyright rights in the Software, and any and all patent rights owned or
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
11 * freely licensable by each licensor hereunder covering either (i) the
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
12 * unmodified Software as contributed to or provided by such licensor, or (ii)
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
13 * the Larger Works (as defined below), to deal in both
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22059
diff changeset
14 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
15 * (a) the Software, and
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22059
diff changeset
16 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
17 * (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
18 * one is included with the Software each a "Larger Work" to which the Software
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
19 * is contributed by such licensors),
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22059
diff changeset
20 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
21 * without restriction, including without limitation the rights to copy, create
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
22 * derivative works of, display, perform, and distribute the Software and make,
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
23 * use, sell, offer for sale, import, export, have made, and have sold the
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
24 * Software and the Larger Work(s), and to sublicense the foregoing rights on
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
25 * either these or other terms.
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22059
diff changeset
26 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
27 * This license is subject to the following condition:
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22059
diff changeset
28 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
29 * The above copyright notice and either this complete permission notice or at a
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
30 * minimum a reference to the UPL must be included in all copies or substantial
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
31 * portions of the Software.
22065
503529c65456 Remove trailing whitespace from UPL license
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22059
diff changeset
32 *
21997
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
33 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
34 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
35 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
36 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
37 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
38 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
c07e64ecb528 Update SL copyright headers to use UPL
Gilles Duboscq <gilles.m.duboscq@oracle.com>
parents: 21951
diff changeset
39 * SOFTWARE.
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
40 */
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
41 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
42
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
43 import com.oracle.truffle.api.dsl.NodeFactory;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
44 import com.oracle.truffle.api.vm.TruffleVM;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
45 import com.oracle.truffle.sl.SLLanguage;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
46 import com.oracle.truffle.sl.builtins.SLBuiltinNode;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
47 import com.oracle.truffle.sl.test.SLTestRunner.TestCase;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
48 import java.io.BufferedReader;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
49 import java.io.ByteArrayOutputStream;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
50 import java.io.File;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
51 import java.io.FileNotFoundException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
52 import java.io.IOException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
53 import java.io.PrintWriter;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
54 import java.io.StringReader;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
55 import java.net.URL;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
56 import java.nio.charset.Charset;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
57 import java.nio.file.FileSystems;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
58 import java.nio.file.FileVisitResult;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
59 import java.nio.file.Files;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
60 import java.nio.file.Path;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
61 import java.nio.file.SimpleFileVisitor;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
62 import java.nio.file.attribute.BasicFileAttributes;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
63 import java.util.ArrayList;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
64 import java.util.List;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
65 import org.junit.Assert;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
66 import org.junit.internal.TextListener;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
67 import org.junit.runner.Description;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
68 import org.junit.runner.JUnitCore;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
69 import org.junit.runner.Result;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
70 import org.junit.runner.manipulation.Filter;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
71 import org.junit.runner.manipulation.NoTestsRemainException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
72 import org.junit.runner.notification.Failure;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
73 import org.junit.runner.notification.RunNotifier;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
74 import org.junit.runners.ParentRunner;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
75 import org.junit.runners.model.InitializationError;
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
76
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
77 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
78
17007
004e3f0a0517 Truffle: added new infrastructure for graal truffle runtime tests using SL.
Christian Humer <christian.humer@gmail.com>
parents: 17006
diff changeset
79 private static int repeats = 1;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
80
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
81 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
82 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
83 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
84
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
85 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
86
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
87 static class TestCase {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
88 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
89 protected final Path path;
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
90 protected final String sourceName;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
91 protected final String testInput;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
92 protected final String expectedOutput;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
93 protected String actualOutput;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
94
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
95 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
96 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
97 this.sourceName = sourceName;
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
98 this.path = path;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
99 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
100 this.expectedOutput = expectedOutput;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
101 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
102 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
103
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
104 private final List<TestCase> testCases;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
105
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
106 public SLTestRunner(Class<?> runningClass) throws InitializationError {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
107 super(runningClass);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
108 try {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
109 testCases = createTests(runningClass);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
110 } catch (IOException e) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
111 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
112 }
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
113 }
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
114
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
115 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
116 protected Description describeChild(TestCase child) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
117 return child.name;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
118 }
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
119
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
120 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
121 protected List<TestCase> getChildren() {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
122 return testCases;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
123 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
124
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
125 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
126 SLTestSuite suite = c.getAnnotation(SLTestSuite.class);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
127 if (suite == null) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
128 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
129 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
130
22023
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
131 String[] paths = suite.value();
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
132
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
133 Path root = getRootViaResourceURL(c, paths);
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
134
22023
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
135 if (root == null) {
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
136 for (String path : paths) {
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
137 Path candidate = FileSystems.getDefault().getPath(path);
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
138 if (Files.exists(candidate)) {
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
139 root = candidate;
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
140 break;
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
141 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
142 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
143 }
22023
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
144 if (root == null && paths.length > 0) {
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
145 throw new FileNotFoundException(paths[0]);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
146 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
147
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
148 final Path rootPath = root;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
149
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
150 final List<TestCase> foundCases = new ArrayList<>();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
151 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
152 @Override
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
153 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
154 String sourceName = sourceFile.getFileName().toString();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
155 if (sourceName.endsWith(SOURCE_SUFFIX)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
156 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
157
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
158 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
159 String testInput = "";
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
160 if (Files.exists(inputFile)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
161 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
162 }
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
163
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
164 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
165 String expectedOutput = "";
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
166 if (Files.exists(outputFile)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
167 expectedOutput = readAllLines(outputFile);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
168 }
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
169
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
170 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
171 }
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
172 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
173 }
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
174 });
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
175 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
176 }
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
177
22024
216e0683bbf1 made SLInstrumentTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 22023
diff changeset
178 public static Path getRootViaResourceURL(final Class<?> c, String[] paths) {
22023
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
179 URL url = c.getResource(c.getSimpleName() + ".class");
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
180 if (url != null) {
22059
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
181 char sep = File.separatorChar;
22023
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
182 String externalForm = url.toExternalForm();
22059
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
183 String classPart = sep + c.getName().replace('.', sep) + ".class";
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
184 String suffix = null;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
185 String prefix = null;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
186 if (externalForm.startsWith("jar:file:")) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
187 prefix = "jar:file:";
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
188 suffix = sep + "build/truffle-sl.jar!" + classPart;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
189 } else if (externalForm.startsWith("file:")) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
190 prefix = "file:";
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
191 suffix = sep + "bin" + classPart;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
192 } else {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
193 return null;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
194 }
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
195 if (externalForm.endsWith(suffix)) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
196 String base = externalForm.substring(prefix.length(), externalForm.length() - suffix.length());
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
197 for (String path : paths) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
198 String candidate = base + sep + path;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
199 if (new File(candidate).exists()) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
200 return FileSystems.getDefault().getPath(candidate);
22023
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
201 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
202 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
203 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
204 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
205 return null;
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
206 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
207
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
208 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
209 // 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
210 StringBuilder outFile = new StringBuilder();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
211 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
212 outFile.append(line).append(LF);
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
213 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
214 return outFile.toString();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
215 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
216
17006
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
217 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
218 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
219 }
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
220
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
221 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
222
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
223 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
224 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
225 }
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
226
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
227 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
228 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
229 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
230
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
231 ByteArrayOutputStream out = new ByteArrayOutputStream();
21469
286aef83a9a7 Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21468
diff changeset
232 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
233 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
234 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
235
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
236 String script = readAllLines(testCase.path);
22104
cf19259edf87 TruffleVM.eval and Source.withMimeType
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22065
diff changeset
237 SLLanguage.run(vm, testCase.path, null, printer, repeats, builtins);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
238
21469
286aef83a9a7 Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21468
diff changeset
239 printer.flush();
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
240 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
241 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
242 } 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
243 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
244 } finally {
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
245 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
246 }
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
247 }
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
248
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
249 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
250 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
251 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
252 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
253 }
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
254 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
255 }
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
256
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
257 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
258 JUnitCore core = new JUnitCore();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
259 core.addListener(new TextListener(System.out));
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
260 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
261 if (args.length > 0) {
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
262 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
263 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
264 Result r = core.run(suite);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
265 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
266 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
267 }
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
268 }
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
269
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
270 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
271 private final String pattern;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
272
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
273 private NameFilter(String pattern) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
274 this.pattern = pattern.toLowerCase();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
275 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
276
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
277 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
278 public boolean shouldRun(Description description) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
279 return description.getMethodName().toLowerCase().contains(pattern);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
280 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
281
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
282 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
283 public String describe() {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
284 return "Filter contains " + pattern;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
285 }
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
286 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
287
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
288 }