author | ysuenaga |
Wed, 30 Mar 2016 21:05:13 +0900 | |
changeset 37218 | c7241bc368bf |
parent 27579 | d1a63c99cdd5 |
permissions | -rw-r--r-- |
10202 | 1 |
/* |
27579 | 2 |
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved. |
10202 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
import java.io.*; |
|
25 |
import java.util.*; |
|
10638
c8e9604cf151
7075721: javac should have public enum for exit codes
jjg
parents:
10202
diff
changeset
|
26 |
import com.sun.tools.javac.main.Main; |
10202 | 27 |
|
28 |
/* |
|
29 |
* Utility class to emulate jtreg @compile/fail, but also checking the specific |
|
30 |
* exit code, given as the first arg. |
|
31 |
*/ |
|
32 |
public class CompileFail { |
|
33 |
public static void main(String... args) { |
|
34 |
if (args.length < 2) |
|
35 |
throw new IllegalArgumentException("insufficient args"); |
|
36 |
int expected_rc = getReturnCode(args[0]); |
|
37 |
||
38 |
List<String> javacArgs = new ArrayList<>(); |
|
39 |
javacArgs.addAll(Arrays.asList( |
|
40 |
"-d", "." |
|
41 |
)); |
|
42 |
||
43 |
File testSrc = new File(System.getProperty("test.src")); |
|
44 |
for (int i = 1; i < args.length; i++) { // skip first arg |
|
45 |
String arg = args[i]; |
|
46 |
if (arg.endsWith(".java")) |
|
47 |
javacArgs.add(new File(testSrc, arg).getPath()); |
|
48 |
else |
|
49 |
javacArgs.add(arg); |
|
50 |
} |
|
51 |
||
52 |
int rc = com.sun.tools.javac.Main.compile( |
|
53 |
javacArgs.toArray(new String[javacArgs.size()])); |
|
54 |
||
55 |
if (rc != expected_rc) |
|
56 |
throw new Error("unexpected exit code: " + rc |
|
57 |
+ ", expected: " + expected_rc); |
|
58 |
} |
|
59 |
||
60 |
static int getReturnCode(String name) { |
|
10638
c8e9604cf151
7075721: javac should have public enum for exit codes
jjg
parents:
10202
diff
changeset
|
61 |
return Main.Result.valueOf(name).exitCode; |
10202 | 62 |
} |
63 |
||
64 |
} |