Mercurial > hg > graal-compiler
annotate graal/com.oracle.truffle.sl.test/src/com/oracle/truffle/sl/test/SLTestRunner.java @ 16675:0fc43b066eee
SL/SourceAttribution: correct some omissions, and in particular add new node SLParenExpressionNode to represent a parenthesized expression; this is semantically neutral of course, but needed to account correctly for the text of such an expression (as opposed to its contents).
author | Michael Van De Vanter <michael.van.de.vanter@oracle.com> |
---|---|
date | Fri, 01 Aug 2014 16:30:22 -0700 |
parents | 915ebb306fcc |
children | 7c8ddb4233cd |
rev | line source |
---|---|
13762
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
1 /* |
15891
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13961
diff
changeset
|
2 * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
13762
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
4 * |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
8 * |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
14 * |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
18 * |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
21 * questions. |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
22 */ |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.truffle.sl.test; |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
24 |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
25 import java.io.*; |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
26 import java.nio.charset.*; |
13762
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
27 import java.nio.file.*; |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
28 import java.nio.file.attribute.*; |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
29 import java.util.*; |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
30 |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
31 import org.junit.*; |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
32 import org.junit.internal.*; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
33 import org.junit.runner.*; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
34 import org.junit.runner.manipulation.*; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
35 import org.junit.runner.notification.*; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
36 import org.junit.runners.*; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
37 import org.junit.runners.model.*; |
13762
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
38 |
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
|
39 import com.oracle.truffle.api.source.*; |
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 import com.oracle.truffle.sl.*; |
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 import com.oracle.truffle.sl.runtime.*; |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
42 import com.oracle.truffle.sl.test.SLTestRunner.TestCase; |
13762
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
43 |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
44 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
|
45 |
16675
0fc43b066eee
SL/SourceAttribution: correct some omissions, and in particular add new node SLParenExpressionNode to represent a parenthesized expression; this is semantically neutral of course, but needed to account correctly for the text of such an expression (as opposed to its contents).
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16067
diff
changeset
|
46 private static final int REPEATS = 1; |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
47 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
48 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
|
49 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
|
50 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
|
51 |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
52 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
|
53 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
54 static class TestCase { |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
55 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
|
56 protected final Path path; |
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13961
diff
changeset
|
57 protected final String sourceName; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
58 protected final String testInput; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
59 protected final String expectedOutput; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
60 protected String actualOutput; |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
61 |
15891
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13961
diff
changeset
|
62 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
|
63 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
|
64 this.sourceName = sourceName; |
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13961
diff
changeset
|
65 this.path = path; |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
66 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
|
67 this.expectedOutput = expectedOutput; |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
68 } |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
69 } |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
70 |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
71 private final List<TestCase> testCases; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
72 |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
73 public SLTestRunner(Class<?> runningClass) throws InitializationError { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
74 super(runningClass); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
75 try { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
76 testCases = createTests(runningClass); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
77 } catch (IOException e) { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
78 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
|
79 } |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
80 } |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
81 |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
82 @Override |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
83 protected Description describeChild(TestCase child) { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
84 return child.name; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
85 } |
13762
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
86 |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
87 @Override |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
88 protected List<TestCase> getChildren() { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
89 return testCases; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
90 } |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
91 |
15891
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13961
diff
changeset
|
92 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
|
93 SLTestSuite suite = c.getAnnotation(SLTestSuite.class); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
94 if (suite == null) { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
95 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
|
96 } |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
97 |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
98 String[] pathes = suite.value(); |
13762
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
99 |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
100 Path root = null; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
101 for (String path : pathes) { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
102 root = FileSystems.getDefault().getPath(path); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
103 if (Files.exists(root)) { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
104 break; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
105 } |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
106 } |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
107 if (root == null && pathes.length > 0) { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
108 throw new FileNotFoundException(pathes[0]); |
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 |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
111 final Path rootPath = root; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
112 |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
113 final List<TestCase> foundCases = new ArrayList<>(); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
114 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
|
115 @Override |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
116 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
|
117 String sourceName = sourceFile.getFileName().toString(); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
118 if (sourceName.endsWith(SOURCE_SUFFIX)) { |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
119 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
|
120 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
121 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
|
122 String testInput = ""; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
123 if (Files.exists(inputFile)) { |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
124 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
|
125 } |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
126 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
127 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
|
128 String expectedOutput = ""; |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
129 if (Files.exists(outputFile)) { |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
130 expectedOutput = readAllLines(outputFile); |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
131 } |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
132 |
15891
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13961
diff
changeset
|
133 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
|
134 } |
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 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
|
136 } |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
137 }); |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
138 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
|
139 } |
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 |
13821
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
141 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
|
142 // 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
|
143 StringBuilder outFile = new StringBuilder(); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
144 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
|
145 outFile.append(line).append(LF); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
146 } |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
147 return outFile.toString(); |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
148 } |
b16ec83edc73
Documentation and more refactoring of Simple Language
Christian Wimmer <christian.wimmer@oracle.com>
parents:
13809
diff
changeset
|
149 |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
150 @Override |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
151 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
|
152 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
|
153 |
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
|
154 ByteArrayOutputStream out = new ByteArrayOutputStream(); |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
155 PrintStream printer = new PrintStream(out); |
13762
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
156 try { |
15891
09ac9ac9c4fc
Truffle: SourceManager renamed to SourceFactory
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
13961
diff
changeset
|
157 SLContext context = new SLContext(new BufferedReader(new StringReader(repeat(testCase.testInput, REPEATS))), printer); |
16067
915ebb306fcc
Truffle/Source: major API revision
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
15891
diff
changeset
|
158 final Source source = Source.fromText(readAllLines(testCase.path), testCase.sourceName); |
16675
0fc43b066eee
SL/SourceAttribution: correct some omissions, and in particular add new node SLParenExpressionNode to represent a parenthesized expression; this is semantically neutral of course, but needed to account correctly for the text of such an expression (as opposed to its contents).
Michael Van De Vanter <michael.van.de.vanter@oracle.com>
parents:
16067
diff
changeset
|
159 SLMain.run(context, source, System.out, REPEATS); |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
160 |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
161 String actualOutput = new String(out.toByteArray()); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
162 Assert.assertEquals(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
|
163 } catch (Throwable ex) { |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
164 notifier.fireTestFailure(new Failure(testCase.name, 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
|
165 } finally { |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
166 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
|
167 } |
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 |
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
|
170 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
|
171 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
|
172 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
|
173 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
|
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 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
|
176 } |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
177 |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
178 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
|
179 JUnitCore core = new JUnitCore(); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
180 core.addListener(new TextListener(System.out)); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
181 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
|
182 if (args.length > 0) { |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
183 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
|
184 } |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
185 Result r = core.run(suite); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
186 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
|
187 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
|
188 } |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
189 } |
e34d5cca7496
Use source and expected output files to test Simple Language, instead of individual JUnit tests with the source and expected output as strings
Christian Wimmer <christian.wimmer@oracle.com>
parents:
diff
changeset
|
190 |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
191 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
|
192 private final String pattern; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
193 |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
194 private NameFilter(String pattern) { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
195 this.pattern = pattern.toLowerCase(); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
196 } |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
197 |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
198 @Override |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
199 public boolean shouldRun(Description description) { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
200 return description.getMethodName().toLowerCase().contains(pattern); |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
201 } |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
202 |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
203 @Override |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
204 public String describe() { |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
205 return "Filter contains " + pattern; |
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
206 } |
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
|
207 } |
13809
030e75d4d7dc
SL: added junit integration for external tests.
Christian Humer <christian.humer@gmail.com>
parents:
13764
diff
changeset
|
208 |
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
|
209 } |