author | akulyakh |
Thu, 21 May 2015 11:41:04 -0700 | |
changeset 30730 | d3ce7619db2c |
parent 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
5520
diff
changeset
|
2 |
* Copyright (c) 2005, 2015, Oracle and/or its affiliates. All rights reserved. |
10 | 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. |
|
10 | 22 |
*/ |
23 |
||
24 |
/* |
|
25 |
* @test |
|
26 |
* @bug 4164450 |
|
27 |
* @summary JSR 199: Standard interface for Java compilers |
|
28 |
* @author Peter von der Ah\u00e9 |
|
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
5520
diff
changeset
|
29 |
* @modules java.compiler |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
5520
diff
changeset
|
30 |
* java.desktop |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
5520
diff
changeset
|
31 |
* jdk.compiler |
10 | 32 |
* @compile TestEvalExpression.java evalexpr/ByteArrayClassLoader.java evalexpr/CompileFromString.java evalexpr/MemoryFileManager.java |
33 |
* @run main TestEvalExpression |
|
34 |
*/ |
|
35 |
||
36 |
import java.lang.reflect.Method; |
|
37 |
import java.util.*; |
|
38 |
import javax.swing.JOptionPane; |
|
39 |
import javax.tools.*; |
|
40 |
import static evalexpr.CompileFromString.*; |
|
41 |
||
42 |
public class TestEvalExpression { |
|
43 |
static int errorCount = 0; |
|
44 |
static class Listener implements DiagnosticListener<JavaFileObject> { |
|
45 |
public void report(Diagnostic<? extends JavaFileObject> message) { |
|
46 |
if (message.getKind() == Diagnostic.Kind.ERROR) |
|
47 |
errorCount++; |
|
48 |
System.err.println(message); |
|
49 |
} |
|
50 |
} |
|
51 |
||
52 |
public static void main(String[] args) { |
|
53 |
// Get a compiler tool |
|
54 |
final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
|
55 |
final List<String> compilerFlags = new ArrayList(); |
|
56 |
compilerFlags.add("-Xlint:all"); // report all warnings |
|
57 |
compilerFlags.add("-g:none"); // don't generate debug info |
|
58 |
final DiagnosticListener<JavaFileObject> listener = new Listener(); |
|
59 |
String expression = "System.getProperty(\"java.vendor\")"; |
|
60 |
Object result = null; |
|
61 |
try { |
|
62 |
result = evalExpression(compiler, listener, compilerFlags, expression); |
|
63 |
} catch (Exception e) { |
|
64 |
throw new AssertionError(e); |
|
65 |
} |
|
66 |
if (result == ERROR) |
|
67 |
throw new AssertionError(result); |
|
68 |
System.out.format("%s => %s%n", expression, result); |
|
69 |
if (!System.getProperty("java.vendor").equals(result)) |
|
70 |
throw new AssertionError(result); |
|
71 |
if (errorCount != 0) |
|
72 |
throw new AssertionError(errorCount); |
|
73 |
try { |
|
74 |
result = evalExpression(compiler, listener, compilerFlags, "fisk hest"); |
|
75 |
} catch (Exception e) { |
|
76 |
throw new AssertionError(e); |
|
77 |
} |
|
78 |
if (errorCount == 0) |
|
79 |
throw new AssertionError(errorCount); |
|
80 |
} |
|
81 |
} |