author | duke |
Wed, 05 Jul 2017 23:01:50 +0200 | |
changeset 44228 | e46434c65a2b |
parent 40599 | be40838eb215 |
permissions | -rw-r--r-- |
1261 | 1 |
/* |
40599
be40838eb215
8164887: update tests to remove use of old-style options
jjg
parents:
36526
diff
changeset
|
2 |
* Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved. |
1261 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
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. |
|
1261 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 6728697 |
|
27 |
* @summary tools/javac/versionOpt.sh fails on OpenJDK builds |
|
28 |
* Test checks the version strings displayed by javac, using |
|
29 |
* strings that come out of the Java runtime. |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27850
diff
changeset
|
30 |
* @modules jdk.compiler |
1261 | 31 |
*/ |
32 |
||
33 |
import java.io.File; |
|
34 |
import java.io.PrintWriter; |
|
35 |
import java.io.StringWriter; |
|
36 |
import java.net.URL; |
|
37 |
||
38 |
public class VersionOpt { |
|
39 |
public static void main(String... args) throws Exception { |
|
40 |
new VersionOpt().run(); |
|
41 |
} |
|
42 |
||
43 |
void run() throws Exception { |
|
44 |
// Test functions by comparing the version string from javac against |
|
45 |
// a "golden" version generated automatically from the underlying JVM. |
|
46 |
// As such, it is only effective in testing the "standard" compiler, |
|
40599
be40838eb215
8164887: update tests to remove use of old-style options
jjg
parents:
36526
diff
changeset
|
47 |
// and not any development version being tested via --patch-modules. |
1261 | 48 |
// Check the version of the compiler being used, and let the test pass |
49 |
// automatically if is is a development version. |
|
50 |
Class<?> javacClass = com.sun.tools.javac.Main.class; |
|
36526 | 51 |
URL location = javacClass.getProtectionDomain().getCodeSource().getLocation(); |
52 |
if (!location.toString().equals("jrt:/jdk.compiler")) { |
|
53 |
System.err.println("javac not found in system image: " + location); |
|
1261 | 54 |
System.err.println("rest of test skipped"); |
55 |
return; |
|
56 |
} |
|
57 |
||
36526 | 58 |
System.out.println("javac found in " + location); |
1261 | 59 |
|
60 |
String javaVersion = System.getProperty("java.version"); |
|
61 |
String javaRuntimeVersion = System.getProperty("java.runtime.version"); |
|
62 |
System.out.println("java.version: " + javaVersion); |
|
63 |
System.out.println("java.runtime.version: " + javaRuntimeVersion); |
|
64 |
||
65 |
StringWriter sw = new StringWriter(); |
|
66 |
com.sun.tools.javac.Main.compile(new String[] { "-version" }, new PrintWriter(sw)); |
|
67 |
String javacVersion = sw.toString().trim(); |
|
68 |
||
69 |
sw = new StringWriter(); |
|
70 |
com.sun.tools.javac.Main.compile(new String[] { "-fullversion" }, new PrintWriter(sw)); |
|
71 |
String javacFullVersion = sw.toString().trim(); |
|
72 |
System.out.println("javac -version: " + javacVersion); |
|
73 |
System.out.println("javac -fullversion: " + javacFullVersion); |
|
74 |
||
75 |
checkEqual("javac -version", javacVersion, "javac " + javaVersion); |
|
76 |
checkEqual("javac -fullversion", javacFullVersion, "javac full version \"" + javaRuntimeVersion + "\""); |
|
77 |
||
78 |
if (errors > 0) |
|
79 |
throw new Exception(errors + " errors found"); |
|
80 |
} |
|
81 |
||
82 |
void checkEqual(String kind, String found, String expect) { |
|
83 |
if (!found.equals(expect)) { |
|
84 |
System.err.println("error: unexpected value for " + kind); |
|
85 |
System.err.println("expect: >>" + expect + "<<"); |
|
86 |
System.err.println(" found: >>" + found + "<<"); |
|
87 |
errors++; |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
int errors; |
|
92 |
} |