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