author | katleman |
Thu, 21 Aug 2014 14:16:14 -0700 | |
changeset 25878 | 6d561031123e |
parent 5520 | 86e4b9a9da40 |
child 27579 | d1a63c99cdd5 |
permissions | -rw-r--r-- |
4940
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
1 |
/* |
5520 | 2 |
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
4940
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
4 |
* |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
8 |
* |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
14 |
* |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
18 |
* |
5520 | 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. |
|
4940
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
22 |
*/ |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
23 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
24 |
import java.io.*; |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
25 |
import java.util.*; |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
26 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
27 |
/* |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
28 |
* Wrapper for the EarlyAssert test to run the test in a JVM without assertions |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
29 |
* enabled. |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
30 |
*/ |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
31 |
public class EarlyAssertWrapper { |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
32 |
public static void main(String... args) throws Exception { |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
33 |
EarlyAssertWrapper w = new EarlyAssertWrapper(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
34 |
w.run(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
35 |
} |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
36 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
37 |
void run() throws Exception { |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
38 |
List<String> cmd = new ArrayList<String>(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
39 |
File java_home = new File(System.getProperty("java.home")); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
40 |
if (java_home.getName().equals("jre")) |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
41 |
java_home = java_home.getParentFile(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
42 |
cmd.add(new File(new File(java_home, "bin"), "java").getPath()); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
43 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
44 |
// ensure we run with the same bootclasspath as this test, |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
45 |
// in case this test is being run with -Xbootclasspath |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
46 |
cmd.add("-Xbootclasspath:" + System.getProperty("sun.boot.class.path")); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
47 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
48 |
// propogate classpath |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
49 |
cmd.add("-classpath"); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
50 |
cmd.add(System.getProperty("java.class.path")); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
51 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
52 |
// ensure all assertions disabled in target VM |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
53 |
cmd.add("-da"); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
54 |
cmd.add("-dsa"); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
55 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
56 |
cmd.add("EarlyAssert"); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
57 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
58 |
System.err.println("Running command: " + cmd); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
59 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
60 |
ProcessBuilder pb = new ProcessBuilder(cmd); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
61 |
pb.redirectErrorStream(true); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
62 |
Process p = pb.start(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
63 |
p.getOutputStream().close(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
64 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
65 |
StringWriter sw = new StringWriter(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
66 |
PrintWriter pw = new PrintWriter(sw); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
67 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
68 |
String line; |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
69 |
DataInputStream in = new DataInputStream(p.getInputStream()); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
70 |
try { |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
71 |
while ((line = in.readLine()) != null) |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
72 |
pw.println(line); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
73 |
} finally { |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
74 |
in.close(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
75 |
} |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
76 |
pw.close(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
77 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
78 |
String out = sw.toString(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
79 |
int rc = p.waitFor(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
80 |
if (rc != 0 || out.length() > 0) |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
81 |
throw new Error("failed: rc=" + rc + (out.length() > 0 ? ": " + out : "")); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
82 |
} |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
83 |
} |