test/tools/javac/lib/CompileFail.java

Fri, 05 Aug 2011 15:57:59 -0700

author
jjg
date
Fri, 05 Aug 2011 15:57:59 -0700
changeset 1064
c0d5f93af048
child 1097
497571d34112
permissions
-rw-r--r--

7074189: some javac tests fail with latest jtreg 4.1 b03
Reviewed-by: darcy

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@1064 26
jjg@1064 27 /*
jjg@1064 28 * Utility class to emulate jtreg @compile/fail, but also checking the specific
jjg@1064 29 * exit code, given as the first arg.
jjg@1064 30 */
jjg@1064 31 public class CompileFail {
jjg@1064 32 public static void main(String... args) {
jjg@1064 33 if (args.length < 2)
jjg@1064 34 throw new IllegalArgumentException("insufficient args");
jjg@1064 35 int expected_rc = getReturnCode(args[0]);
jjg@1064 36
jjg@1064 37 List<String> javacArgs = new ArrayList<>();
jjg@1064 38 javacArgs.addAll(Arrays.asList(
jjg@1064 39 "-bootclasspath", System.getProperty("sun.boot.class.path"),
jjg@1064 40 "-d", "."
jjg@1064 41 ));
jjg@1064 42
jjg@1064 43 File testSrc = new File(System.getProperty("test.src"));
jjg@1064 44 for (int i = 1; i < args.length; i++) { // skip first arg
jjg@1064 45 String arg = args[i];
jjg@1064 46 if (arg.endsWith(".java"))
jjg@1064 47 javacArgs.add(new File(testSrc, arg).getPath());
jjg@1064 48 else
jjg@1064 49 javacArgs.add(arg);
jjg@1064 50 }
jjg@1064 51
jjg@1064 52 int rc = com.sun.tools.javac.Main.compile(
jjg@1064 53 javacArgs.toArray(new String[javacArgs.size()]));
jjg@1064 54
jjg@1064 55 if (rc != expected_rc)
jjg@1064 56 throw new Error("unexpected exit code: " + rc
jjg@1064 57 + ", expected: " + expected_rc);
jjg@1064 58 }
jjg@1064 59
jjg@1064 60 static int getReturnCode(String name) {
jjg@1064 61 switch (name) {
jjg@1064 62 case "OK":
jjg@1064 63 return EXIT_OK;
jjg@1064 64
jjg@1064 65 case "ERROR":
jjg@1064 66 return EXIT_ERROR;
jjg@1064 67
jjg@1064 68 case "CMDERR":
jjg@1064 69 return EXIT_CMDERR;
jjg@1064 70
jjg@1064 71 case "SYSERR":
jjg@1064 72 return EXIT_SYSERR;
jjg@1064 73
jjg@1064 74 case "ABNORMAL":
jjg@1064 75 return EXIT_ABNORMAL;
jjg@1064 76
jjg@1064 77 default:
jjg@1064 78 throw new IllegalArgumentException(name);
jjg@1064 79 }
jjg@1064 80 }
jjg@1064 81
jjg@1064 82 // The following is cut-n-paste from com.sun.tools.javac.main.Main
jjg@1064 83 static final int
jjg@1064 84 EXIT_OK = 0, // Compilation completed with no errors.
jjg@1064 85 EXIT_ERROR = 1, // Completed but reported errors.
jjg@1064 86 EXIT_CMDERR = 2, // Bad command-line arguments
jjg@1064 87 EXIT_SYSERR = 3, // System error or resource exhaustion.
jjg@1064 88 EXIT_ABNORMAL = 4; // Compiler terminated abnormally
jjg@1064 89 }

mercurial