--- a/langtools/test/tools/javac/fatalErrors/NoJavaLangTest.java Tue Mar 15 13:48:30 2016 -0700
+++ b/langtools/test/tools/javac/fatalErrors/NoJavaLangTest.java Thu Mar 17 19:04:28 2016 +0000
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -29,11 +29,13 @@
* @modules jdk.compiler/com.sun.tools.javac.api
* jdk.compiler/com.sun.tools.javac.file
* jdk.compiler/com.sun.tools.javac.main
+ * jdk.jdeps/com.sun.tools.javap
* @build ToolBox
* @run main NoJavaLangTest
*/
-// Original test: test/tools/javac/fatalErrors/NoJavaLang.sh
+import java.nio.file.*;
+
public class NoJavaLangTest {
private static final String noJavaLangSrc =
@@ -49,22 +51,60 @@
"Fatal Error: Unable to find package java.lang in classpath or bootclasspath";
public static void main(String[] args) throws Exception {
- ToolBox tb = new ToolBox();
+ new NoJavaLangTest().run();
+ }
+
+ final ToolBox tb = new ToolBox();
+ void run() throws Exception {
+ testStandard();
+ testBootClassPath();
+ testModulePath();
+ }
+
+ // sanity check, with java.lang available
+ void testStandard() {
tb.new JavacTask()
.sources(noJavaLangSrc)
.run();
+ }
+
+
+ // test with bootclasspath, for as long as its around
+ void testBootClassPath() {
+ String[] bcpOpts = { "-Xlint:-options", "-source", "8", "-bootclasspath", "." };
+ test(bcpOpts, compilerErrorMessage);
+ }
+
+ // test with module path
+ void testModulePath() throws Exception {
+ // need to ensure there is an empty java.base to avoid different error message
+ Files.createDirectories(Paths.get("modules/java.base"));
+ tb.new JavacTask()
+ .sources("module java.base { }")
+ .outdir("modules/java.base")
+ .run();
+
+ // ideally we'd have a better message for this case
+ String[] mpOpts = { "-system", "none", "-modulepath", "modules" };
+ test(mpOpts, compilerErrorMessage);
+ }
+
+ private void test(String[] options, String expect) {
+ System.err.println("Testing " + java.util.Arrays.toString(options));
String out = tb.new JavacTask()
- .options("-bootclasspath", ".")
+ .options(options)
.sources(noJavaLangSrc)
.run(ToolBox.Expect.FAIL, 3)
.writeAll()
.getOutput(ToolBox.OutputKind.DIRECT);
- if (!out.trim().equals(compilerErrorMessage)) {
+ if (!out.trim().equals(expect)) {
throw new AssertionError("javac generated error output is not correct");
}
+
+ System.err.println("OK");
}
}