annotate truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java @ 22165:67f75f61c974

Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Mon, 21 Sep 2015 12:36:30 +0200
parents dc83cc1f94f2
children 0480c4873a4a
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;
22165
67f75f61c974 Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22157
diff changeset
49 import java.io.ByteArrayInputStream;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
50 import java.io.ByteArrayOutputStream;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
51 import java.io.File;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
52 import java.io.FileNotFoundException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
53 import java.io.IOException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
54 import java.io.PrintWriter;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
55 import java.io.StringReader;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
56 import java.net.URL;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
57 import java.nio.charset.Charset;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
58 import java.nio.file.FileSystems;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
59 import java.nio.file.FileVisitResult;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
60 import java.nio.file.Files;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
61 import java.nio.file.Path;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
62 import java.nio.file.SimpleFileVisitor;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
63 import java.nio.file.attribute.BasicFileAttributes;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
64 import java.util.ArrayList;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
65 import java.util.List;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
66 import org.junit.Assert;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
67 import org.junit.internal.TextListener;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
68 import org.junit.runner.Description;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
69 import org.junit.runner.JUnitCore;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
70 import org.junit.runner.Result;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
71 import org.junit.runner.manipulation.Filter;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
72 import org.junit.runner.manipulation.NoTestsRemainException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
73 import org.junit.runner.notification.Failure;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
74 import org.junit.runner.notification.RunNotifier;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
75 import org.junit.runners.ParentRunner;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
76 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
77
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
78 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
79
17007
004e3f0a0517 Truffle: added new infrastructure for graal truffle runtime tests using SL.
Christian Humer <christian.humer@gmail.com>
parents: 17006
diff changeset
80 private static int repeats = 1;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
81
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
82 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
83 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
84 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
85
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
86 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
87
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
88 static class TestCase {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
89 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
90 protected final Path path;
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
91 protected final String sourceName;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
92 protected final String testInput;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
93 protected final String expectedOutput;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
94 protected String actualOutput;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
95
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
96 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
97 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
98 this.sourceName = sourceName;
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
99 this.path = path;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
100 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
101 this.expectedOutput = expectedOutput;
13809
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
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
105 private final List<TestCase> testCases;
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 public SLTestRunner(Class<?> runningClass) throws InitializationError {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
108 super(runningClass);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
109 try {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
110 testCases = createTests(runningClass);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
111 } catch (IOException e) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
112 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
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 }
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
115
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
116 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
117 protected Description describeChild(TestCase child) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
118 return child.name;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
119 }
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
120
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
121 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
122 protected List<TestCase> getChildren() {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
123 return testCases;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
124 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
125
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
126 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
127 SLTestSuite suite = c.getAnnotation(SLTestSuite.class);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
128 if (suite == null) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
129 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
130 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
131
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
132 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
133
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
134 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
135
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
136 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
137 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
138 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
139 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
140 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
141 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
142 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
143 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
144 }
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
145 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
146 throw new FileNotFoundException(paths[0]);
13809
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
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
149 final Path rootPath = root;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
150
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
151 final List<TestCase> foundCases = new ArrayList<>();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
152 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
153 @Override
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
154 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
155 String sourceName = sourceFile.getFileName().toString();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
156 if (sourceName.endsWith(SOURCE_SUFFIX)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
157 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
158
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
159 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
160 String testInput = "";
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
161 if (Files.exists(inputFile)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
162 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
163 }
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
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
165 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
166 String expectedOutput = "";
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
167 if (Files.exists(outputFile)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
168 expectedOutput = readAllLines(outputFile);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
169 }
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
170
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
171 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
172 }
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 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
174 }
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
175 });
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
176 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
177 }
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
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
179 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
180 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
181 if (url != null) {
22059
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
182 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
183 String externalForm = url.toExternalForm();
22059
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
184 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
185 String suffix = null;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
186 String prefix = null;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
187 if (externalForm.startsWith("jar:file:")) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
188 prefix = "jar:file:";
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
189 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
190 } else if (externalForm.startsWith("file:")) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
191 prefix = "file:";
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
192 suffix = sep + "bin" + classPart;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
193 } else {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
194 return null;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
195 }
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
196 if (externalForm.endsWith(suffix)) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
197 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
198 for (String path : paths) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
199 String candidate = base + sep + path;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
200 if (new File(candidate).exists()) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
201 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
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 }
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 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
207 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
208
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
209 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
210 // 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
211 StringBuilder outFile = new StringBuilder();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
212 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
213 outFile.append(line).append(LF);
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
214 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
215 return outFile.toString();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
216 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
217
17006
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
218 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
219 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
220 }
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
221
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
222 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
223
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
224 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
225 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
226 }
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
227
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
228 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
229 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
230 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
231
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
232 ByteArrayOutputStream out = new ByteArrayOutputStream();
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 {
22165
67f75f61c974 Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22157
diff changeset
234 TruffleVM vm = TruffleVM.newVM().setIn(new ByteArrayInputStream(repeat(testCase.testInput, repeats).getBytes("UTF-8"))).setOut(out).build();
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
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);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
237
22165
67f75f61c974 Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22157
diff changeset
238 PrintWriter printer = new PrintWriter(out);
67f75f61c974 Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22157
diff changeset
239 SLLanguage.run(vm, testCase.path, null, printer, repeats, builtins);
21469
286aef83a9a7 Replacing PrintStream with PrintWriter in the simple language
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21468
diff changeset
240 printer.flush();
22165
67f75f61c974 Certain languages (like FastR) prefer access to raw byte streams. Offering it. One always has an option to wrap Input and Output Streams into character based Readers and Writers
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22157
diff changeset
241
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
242 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
243 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
244 } 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
245 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
246 } finally {
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
247 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
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 }
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
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 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
252 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
253 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
254 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
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 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
257 }
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
258
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
259 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
260 JUnitCore core = new JUnitCore();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
261 core.addListener(new TextListener(System.out));
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
262 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
263 if (args.length > 0) {
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
264 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
265 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
266 Result r = core.run(suite);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
267 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
268 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
269 }
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
270 }
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
271
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
272 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
273 private final String pattern;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
274
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
275 private NameFilter(String pattern) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
276 this.pattern = pattern.toLowerCase();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
277 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
278
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
279 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
280 public boolean shouldRun(Description description) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
281 return description.getMethodName().toLowerCase().contains(pattern);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
282 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
283
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
284 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
285 public String describe() {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
286 return "Filter contains " + pattern;
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 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
289
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
290 }