annotate truffle/com.oracle.truffle.tck/src/com/oracle/truffle/tck/TruffleJUnitCore.java @ 22157:dc83cc1f94f2

Using fully qualified imports
author Jaroslav Tulach <jaroslav.tulach@oracle.com>
date Wed, 16 Sep 2015 11:33:22 +0200
parents 329fe954f6f2
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
1 /*
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
4 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation. Oracle designates this
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
8 * particular file as subject to the "Classpath" exception as provided
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
9 * by Oracle in the LICENSE file that accompanied this code.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
10 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
11 * This code is distributed in the hope that it will be useful, but WITHOUT
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
14 * version 2 for more details (a copy is included in the LICENSE file that
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
15 * accompanied this code).
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
16 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
17 * You should have received a copy of the GNU General Public License version
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
18 * 2 along with this work; if not, write to the Free Software Foundation,
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
20 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
22 * or visit www.oracle.com if you need additional information or have any
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
23 * questions.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
24 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
25 package com.oracle.truffle.tck;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
26
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
27 import java.io.BufferedReader;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
28 import java.io.File;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
29 import java.io.FileReader;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
30 import java.io.IOException;
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
31 import java.lang.reflect.Modifier;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
32 import java.nio.charset.Charset;
22157
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
33 import java.nio.file.Files;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
34 import java.util.ArrayList;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
35 import java.util.List;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
36 import junit.runner.Version;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
37 import org.junit.internal.JUnitSystem;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
38 import org.junit.internal.RealSystem;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
39 import org.junit.runner.Description;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
40 import org.junit.runner.JUnitCore;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
41 import org.junit.runner.Request;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
42 import org.junit.runner.Result;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
43 import org.junit.runner.Runner;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
44 import org.junit.runner.notification.Failure;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
45 import org.junit.runners.ParentRunner;
dc83cc1f94f2 Using fully qualified imports
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 22123
diff changeset
46 import org.junit.runners.model.RunnerScheduler;
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
47
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
48 final class TruffleJUnitCore {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
49
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
50 /**
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
51 * Run the tests contained in the classes named in the <code>args</code>. A single test method
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
52 * can be specified by adding #method after the class name. Only a single test can be run in
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
53 * this way. If all tests run successfully, exit with a status of 0. Otherwise exit with a
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
54 * status of 1. Write feedback while tests are running and write stack traces for all failed
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
55 * tests after the tests all complete.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
56 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
57 * @param args names of classes in which to find tests to run
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
58 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
59 public static void main(String... args) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
60 JUnitSystem system = new RealSystem();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
61 JUnitCore junitCore = new JUnitCore();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
62 system.out().println("TruffleJUnitCore");
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
63 system.out().println("JUnit version " + Version.id());
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
64 List<Class<?>> classes = new ArrayList<>();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
65 String methodName = null;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
66 List<Failure> missingClasses = new ArrayList<>();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
67 boolean verbose = false;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
68 boolean enableTiming = false;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
69 boolean failFast = false;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
70 boolean eagerStackTrace = false;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
71 boolean gcAfterTest = false;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
72
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
73 String[] expandedArgs = expandArgs(args);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
74 for (int i = 0; i < expandedArgs.length; i++) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
75 String each = expandedArgs[i];
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
76 if (each.charAt(0) == '-') {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
77 // command line arguments
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
78 if (each.contentEquals("-JUnitVerbose")) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
79 verbose = true;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
80 } else if (each.contentEquals("-JUnitFailFast")) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
81 failFast = true;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
82 } else if (each.contentEquals("-JUnitEnableTiming")) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
83 enableTiming = true;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
84 } else if (each.contentEquals("-JUnitEagerStackTrace")) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
85 eagerStackTrace = true;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
86 } else if (each.contentEquals("-JUnitGCAfterTest")) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
87 gcAfterTest = true;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
88 } else {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
89 system.out().println("Unknown command line argument: " + each);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
90 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
91
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
92 } else {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
93 /*
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
94 * Entries of the form class#method are handled specially. Only one can be specified
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
95 * on the command line as there's no obvious way to build a runner for multiple
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
96 * ones.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
97 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
98 if (methodName != null) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
99 system.out().println("Only a single class and method can be specified: " + each);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
100 System.exit(1);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
101 } else if (each.contains("#")) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
102 String[] pair = each.split("#");
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
103 if (pair.length != 2) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
104 system.out().println("Malformed class and method request: " + each);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
105 System.exit(1);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
106 } else if (classes.size() != 0) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
107 system.out().println("Only a single class and method can be specified: " + each);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
108 System.exit(1);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
109 } else {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
110 methodName = pair[1];
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
111 each = pair[0];
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
112 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
113 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
114 try {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
115 Class<?> cls = Class.forName(each, false, TruffleJUnitCore.class.getClassLoader());
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
116 if ((cls.getModifiers() & Modifier.ABSTRACT) == 0) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
117 classes.add(cls);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
118 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
119 } catch (ClassNotFoundException e) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
120 system.out().println("Could not find class: " + each);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
121 Description description = Description.createSuiteDescription(each);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
122 Failure failure = new Failure(description, e);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
123 missingClasses.add(failure);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
124 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
125 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
126 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
127 final TruffleTextListener textListener;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
128 if (!verbose) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
129 textListener = new TruffleTextListener(system);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
130 } else {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
131 textListener = new TruffleVerboseTextListener(system);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
132 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
133 TruffleJUnitRunListener listener = textListener;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
134 if (enableTiming) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
135 listener = new TimingDecorator(listener);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
136 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
137 if (eagerStackTrace) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
138 listener = new EagerStackTraceDecorator(listener);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
139 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
140 if (gcAfterTest) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
141 listener = new GCAfterTestDecorator(listener);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
142 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
143 junitCore.addListener(TruffleTextListener.createRunListener(listener));
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
144 Request request;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
145 if (methodName == null) {
22123
329fe954f6f2 Can compile Truffle API with following javac lints: -Xlint:all,-auxiliaryclass,-try,-processing
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents: 21951
diff changeset
146 request = Request.classes(classes.toArray(new Class<?>[0]));
21938
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
147 if (failFast) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
148 Runner runner = request.getRunner();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
149 if (runner instanceof ParentRunner) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
150 ParentRunner<?> parentRunner = (ParentRunner<?>) runner;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
151 parentRunner.setScheduler(new RunnerScheduler() {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
152 public void schedule(Runnable childStatement) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
153 if (textListener.getLastFailure() == null) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
154 childStatement.run();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
155 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
156 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
157
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
158 public void finished() {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
159 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
160 });
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
161 } else {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
162 system.out().println("Unexpected Runner subclass " + runner.getClass().getName() + " - fail fast not supported");
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
163 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
164 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
165 } else {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
166 if (failFast) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
167 system.out().println("Single method selected - fail fast not supported");
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
168 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
169 request = Request.method(classes.get(0), methodName);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
170 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
171 Result result = junitCore.run(request);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
172 for (Failure each : missingClasses) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
173 result.getFailures().add(each);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
174 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
175 System.exit(result.wasSuccessful() ? 0 : 1);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
176 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
177
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
178 /**
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
179 * Gets the command line for the current process.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
180 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
181 * @return the command line arguments for the current process or {@code null} if they are not
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
182 * available
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
183 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
184 public static List<String> getProcessCommandLine() {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
185 String processArgsFile = System.getenv().get("MX_SUBPROCESS_COMMAND_FILE");
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
186 if (processArgsFile != null) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
187 try {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
188 return Files.readAllLines(new File(processArgsFile).toPath(), Charset.forName("UTF-8"));
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
189 } catch (IOException e) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
190 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
191 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
192 return null;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
193 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
194
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
195 /**
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
196 * Expand any arguments starting with @ and return the resulting argument array.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
197 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
198 * @param args
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
199 * @return the expanded argument array
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
200 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
201 private static String[] expandArgs(String[] args) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
202 List<String> result = null;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
203 for (int i = 0; i < args.length; i++) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
204 String arg = args[i];
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
205 if (arg.length() > 0 && arg.charAt(0) == '@') {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
206 if (result == null) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
207 result = new ArrayList<>();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
208 for (int j = 0; j < i; j++) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
209 result.add(args[j]);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
210 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
211 expandArg(arg.substring(1), result);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
212 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
213 } else if (result != null) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
214 result.add(arg);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
215 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
216 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
217 return result != null ? result.toArray(new String[0]) : args;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
218 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
219
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
220 /**
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
221 * Add each line from {@code filename} to the list {@code args}.
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
222 *
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
223 * @param filename
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
224 * @param args
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
225 */
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
226 private static void expandArg(String filename, List<String> args) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
227 BufferedReader br = null;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
228 try {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
229 br = new BufferedReader(new FileReader(filename));
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
230
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
231 String buf;
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
232 while ((buf = br.readLine()) != null) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
233 args.add(buf);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
234 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
235 br.close();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
236 } catch (IOException ioe) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
237 ioe.printStackTrace();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
238 System.exit(2);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
239 } finally {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
240 try {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
241 if (br != null) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
242 br.close();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
243 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
244 } catch (IOException ioe) {
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
245 ioe.printStackTrace();
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
246 System.exit(3);
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
247 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
248 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
249 }
0a6e10379b9b Keeping only Truffle-related modules in this repository
Jaroslav Tulach <jaroslav.tulach@oracle.com>
parents:
diff changeset
250 }