author | lana |
Thu, 21 Jan 2016 09:46:01 -0800 | |
changeset 35340 | 38f7386ed942 |
parent 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 |
/* |
27579 | 2 |
* Copyright (c) 2010, 2014, 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 |
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
|
41 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
42 |
// propogate classpath |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
43 |
cmd.add("-classpath"); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
44 |
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
|
45 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
46 |
// 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
|
47 |
cmd.add("-da"); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
48 |
cmd.add("-dsa"); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
49 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
50 |
cmd.add("EarlyAssert"); |
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 |
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
|
53 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
54 |
ProcessBuilder pb = new ProcessBuilder(cmd); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
55 |
pb.redirectErrorStream(true); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
56 |
Process p = pb.start(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
57 |
p.getOutputStream().close(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
58 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
59 |
StringWriter sw = new StringWriter(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
60 |
PrintWriter pw = new PrintWriter(sw); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
61 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
62 |
String line; |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
63 |
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
|
64 |
try { |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
65 |
while ((line = in.readLine()) != null) |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
66 |
pw.println(line); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
67 |
} finally { |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
68 |
in.close(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
69 |
} |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
70 |
pw.close(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
71 |
|
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
72 |
String out = sw.toString(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
73 |
int rc = p.waitFor(); |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
74 |
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
|
75 |
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
|
76 |
} |
256e46854879
6927797: langtools/test/tools/javac/EarlyAssert.java fails when run with assertions enabled (-ea)
jjg
parents:
diff
changeset
|
77 |
} |