jjg@1064: /* jjg@1064: * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. jjg@1064: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@1064: * jjg@1064: * This code is free software; you can redistribute it and/or modify it jjg@1064: * under the terms of the GNU General Public License version 2 only, as jjg@1064: * published by the Free Software Foundation. jjg@1064: * jjg@1064: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@1064: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@1064: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@1064: * version 2 for more details (a copy is included in the LICENSE file that jjg@1064: * accompanied this code). jjg@1064: * jjg@1064: * You should have received a copy of the GNU General Public License version jjg@1064: * 2 along with this work; if not, write to the Free Software Foundation, jjg@1064: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@1064: * jjg@1064: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jjg@1064: * or visit www.oracle.com if you need additional information or have any jjg@1064: * questions. jjg@1064: */ jjg@1064: jjg@1064: import java.io.*; jjg@1064: import java.util.*; jjg@1097: import com.sun.tools.javac.main.Main; jjg@1064: jjg@1064: /* jjg@1064: * Utility class to emulate jtreg @compile/fail, but also checking the specific jjg@1064: * exit code, given as the first arg. jjg@1064: */ jjg@1064: public class CompileFail { jjg@1064: public static void main(String... args) { jjg@1064: if (args.length < 2) jjg@1064: throw new IllegalArgumentException("insufficient args"); jjg@1064: int expected_rc = getReturnCode(args[0]); jjg@1064: jjg@1064: List javacArgs = new ArrayList<>(); jjg@1064: javacArgs.addAll(Arrays.asList( jjg@1064: "-bootclasspath", System.getProperty("sun.boot.class.path"), jjg@1064: "-d", "." jjg@1064: )); jjg@1064: jjg@1064: File testSrc = new File(System.getProperty("test.src")); jjg@1064: for (int i = 1; i < args.length; i++) { // skip first arg jjg@1064: String arg = args[i]; jjg@1064: if (arg.endsWith(".java")) jjg@1064: javacArgs.add(new File(testSrc, arg).getPath()); jjg@1064: else jjg@1064: javacArgs.add(arg); jjg@1064: } jjg@1064: jjg@1064: int rc = com.sun.tools.javac.Main.compile( jjg@1064: javacArgs.toArray(new String[javacArgs.size()])); jjg@1064: jjg@1064: if (rc != expected_rc) jjg@1064: throw new Error("unexpected exit code: " + rc jjg@1064: + ", expected: " + expected_rc); jjg@1064: } jjg@1064: jjg@1064: static int getReturnCode(String name) { jjg@1097: return Main.Result.valueOf(name).exitCode; jjg@1064: } jjg@1064: jjg@1064: }