annotate truffle/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java @ 22548:6b76a24fffbd default tip

Use all variables: a, b, u,v and x, y
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Thu, 14 Jan 2016 14:20:57 +0100
parents 906a5f6e07cc
children
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
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
43 import java.io.ByteArrayInputStream;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
44 import java.io.ByteArrayOutputStream;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
45 import java.io.File;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
46 import java.io.FileNotFoundException;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
47 import java.io.IOException;
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
48 import java.io.PrintStream;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
49 import java.io.PrintWriter;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
50 import java.net.URL;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
51 import java.nio.charset.Charset;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
52 import java.nio.file.FileSystems;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
53 import java.nio.file.FileVisitResult;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
54 import java.nio.file.Files;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
55 import java.nio.file.Path;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
56 import java.nio.file.SimpleFileVisitor;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
57 import java.nio.file.attribute.BasicFileAttributes;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
58 import java.util.ArrayList;
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
59 import java.util.Enumeration;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
60 import java.util.List;
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
61 import java.util.jar.JarEntry;
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
62 import java.util.jar.JarFile;
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
63
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22104
diff changeset
64 import org.junit.Assert;
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
65 import org.junit.Assume;
22157
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
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
77 import com.oracle.truffle.api.dsl.NodeFactory;
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
78 import com.oracle.truffle.api.vm.PolyglotEngine;
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
79 import com.oracle.truffle.sl.SLLanguage;
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
80 import com.oracle.truffle.sl.builtins.SLBuiltinNode;
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
81 import com.oracle.truffle.sl.test.SLTestRunner.TestCase;
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
82
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
83 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
84
17007
004e3f0a0517 Truffle: added new infrastructure for graal truffle runtime tests using SL.
Christian Humer <christian.humer@gmail.com>
parents: 17006
diff changeset
85 private static int repeats = 1;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
86
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
87 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
88 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
89 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
90
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
91 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
92
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
93 static class TestCase {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
94 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
95 protected final Path path;
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
96 protected final String sourceName;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
97 protected final String testInput;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
98 protected final String expectedOutput;
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
99 protected String actualOutput;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
100
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
101 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
102 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
103 this.sourceName = sourceName;
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
104 this.path = path;
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
105 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
106 this.expectedOutput = expectedOutput;
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
107 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
108 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
109
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
110 private final List<TestCase> testCases;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
111
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
112 public SLTestRunner(Class<?> runningClass) throws InitializationError {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
113 super(runningClass);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
114 try {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
115 testCases = createTests(runningClass);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
116 } catch (IOException e) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
117 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
118 }
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 }
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 Description describeChild(TestCase child) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
123 return child.name;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
124 }
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
125
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
126 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
127 protected List<TestCase> getChildren() {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
128 return testCases;
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
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
131 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
132 SLTestSuite suite = c.getAnnotation(SLTestSuite.class);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
133 if (suite == null) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
134 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
135 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
136
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
137 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
138
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 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
140
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
141 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
142 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
143 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
144 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
145 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
146 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
147 }
13809
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 }
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
150 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
151 throw new FileNotFoundException(paths[0]);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
152 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
153
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
154 final Path rootPath = root;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
155
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
156 final List<TestCase> foundCases = new ArrayList<>();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
157 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
158 @Override
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
159 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
160 String sourceName = sourceFile.getFileName().toString();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
161 if (sourceName.endsWith(SOURCE_SUFFIX)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
162 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
163
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
164 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
165 String testInput = "";
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
166 if (Files.exists(inputFile)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
167 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
168 }
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
169
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
170 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
171 String expectedOutput = "";
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
172 if (Files.exists(outputFile)) {
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
173 expectedOutput = readAllLines(outputFile);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
174 }
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
175
15891
09ac9ac9c4fc Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents: 13961
diff changeset
176 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
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 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
179 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
180 });
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
181 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
182 }
e34d5cca7496 Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff changeset
183
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
184 /**
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
185 * Recursively deletes a file that may represent a directory.
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
186 */
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
187 private static void delete(File f) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
188 if (f.isDirectory()) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
189 for (File c : f.listFiles()) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
190 delete(c);
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
191 }
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
192 }
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
193 if (!f.delete()) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
194 PrintStream err = System.err;
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
195 err.println("Failed to delete file: " + f);
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
196 }
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
197 }
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
198
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
199 /**
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
200 * Unpacks a jar file to a temporary directory that will be removed when the VM exits.
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
201 *
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
202 * @param jarfilePath the path of the jar to unpack
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
203 * @return the path of the temporary directory
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
204 */
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
205 private static String explodeJarToTempDir(File jarfilePath) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
206 try {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
207 final Path jarfileDir = Files.createTempDirectory(jarfilePath.getName());
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
208 Runtime.getRuntime().addShutdownHook(new Thread() {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
209 @Override
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
210 public void run() {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
211 delete(jarfileDir.toFile());
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
212 }
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
213 });
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
214 jarfileDir.toFile().deleteOnExit();
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
215 JarFile jarfile = new JarFile(jarfilePath);
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
216 Enumeration<JarEntry> entries = jarfile.entries();
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
217 while (entries.hasMoreElements()) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
218 JarEntry e = entries.nextElement();
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
219 if (!e.isDirectory()) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
220 File path = new File(jarfileDir.toFile(), e.getName().replace('/', File.separatorChar));
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
221 File dir = path.getParentFile();
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
222 dir.mkdirs();
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
223 assert dir.exists();
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
224 Files.copy(jarfile.getInputStream(e), path.toPath());
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
225 }
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
226 }
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
227 return jarfileDir.toFile().getAbsolutePath();
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
228 } catch (IOException e) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
229 throw new AssertionError(e);
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
230 }
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
231 }
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
232
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
233 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
234 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
235 if (url != null) {
22059
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
236 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
237 String externalForm = url.toExternalForm();
22059
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
238 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
239 String prefix = null;
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
240 String base;
22059
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
241 if (externalForm.startsWith("jar:file:")) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
242 prefix = "jar:file:";
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
243 int bang = externalForm.indexOf('!', prefix.length());
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
244 Assume.assumeTrue(bang != -1);
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
245 File jarfilePath = new File(externalForm.substring(prefix.length(), bang));
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
246 Assume.assumeTrue(jarfilePath.exists());
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
247 base = explodeJarToTempDir(jarfilePath);
22059
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
248 } else if (externalForm.startsWith("file:")) {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
249 prefix = "file:";
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
250 base = externalForm.substring(prefix.length(), externalForm.length() - classPart.length());
22059
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
251 } else {
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
252 return null;
cc84642d989f Enable SLTestRunner to find tests from jar file
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 22029
diff changeset
253 }
22203
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
254 for (String path : paths) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
255 String candidate = base + sep + path;
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
256 if (new File(candidate).exists()) {
0995fbcf3e60 SLTestRunner unpacks jars to temp directories to ensure SL test sources and expected output files in a jar are loadable
Doug Simon <doug.simon@oracle.com>
parents: 22201
diff changeset
257 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
258 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
259 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
260 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
261 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
262 }
fee42ec8c59b made SLTestRunner (maybe) find test classes when Truffle is not the primary suite
Doug Simon <doug.simon@oracle.com>
parents: 21951
diff changeset
263
13821
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
264 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
265 // 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
266 StringBuilder outFile = new StringBuilder();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
267 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
268 outFile.append(line).append(LF);
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
269 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
270 return outFile.toString();
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
271 }
b16ec83edc73 Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents: 13809
diff changeset
272
17006
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
273 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
274 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
275 }
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
276
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
277 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
278
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
279 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
280 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
281 }
e9c119927199 SL: added internal APIs to SL for the Graal runtime tests.
Christian Humer <christian.humer@gmail.com>
parents: 16687
diff changeset
282
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
283 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
284 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
285 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
286
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
287 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
288 try {
22335
906a5f6e07cc Giving the PolyglotEngine builder factory method more sensible name.
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22203
diff changeset
289 PolyglotEngine vm = PolyglotEngine.newBuilder().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
290
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
291 String script = readAllLines(testCase.path);
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
292
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
293 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
294 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
295 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
296
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
297 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
298 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
299 } 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
300 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
301 } finally {
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
302 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
303 }
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
304 }
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
305
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
306 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
307 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
308 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
309 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
310 }
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
311 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
312 }
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
313
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
314 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
315 JUnitCore core = new JUnitCore();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
316 core.addListener(new TextListener(System.out));
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
317 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
318 if (args.length > 0) {
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
319 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
320 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
321 Result r = core.run(suite);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
322 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
323 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
324 }
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
325 }
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
326
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
327 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
328 private final String pattern;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
329
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
330 private NameFilter(String pattern) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
331 this.pattern = pattern.toLowerCase();
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
332 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
333
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
334 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
335 public boolean shouldRun(Description description) {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
336 return description.getMethodName().toLowerCase().contains(pattern);
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
337 }
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
338
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
339 @Override
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
340 public String describe() {
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
341 return "Filter contains " + pattern;
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
342 }
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
343 }
13809
030e75d4d7dc SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents: 13764
diff changeset
344
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
345 }