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 *
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.
22 */
23
24 /*
25 * @test
26 * @bug 8192920 8204588
27 * @summary Test source mode
28 * @modules jdk.compiler jdk.jlink
29 * @run main SourceMode
30 */
31
32
33 import java.io.IOException;
34 import java.io.PrintStream;
35 import java.nio.file.Files;
36 import java.nio.file.Path;
37 import java.nio.file.Paths;
38 import java.nio.file.attribute.PosixFilePermission;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Map;
44 import java.util.Set;
281 error(tr, "Expected output not found");
282 show(tr);
283 }
284
285 // java --source N -m jdk.compiler
286 @Test
287 void testSourceModuleConflict() throws IOException {
288 starting("testSourceModuleConflict");
289 TestResult tr = doExec(javaCmd, "--source", thisVersion, "-m", "jdk.compiler");
290 if (tr.isOK())
291 error(tr, "Command succeeded unexpectedly");
292 if (!tr.contains("Option -m is not allowed with --source"))
293 error(tr, "Expected output not found");
294 show(tr);
295 }
296
297 // #!.../java --source N -version
298 @Test
299 void testTerminalOptionInShebang() throws IOException {
300 starting("testTerminalOptionInShebang");
301 if (skipShebangTest || isMacOSX || isSolaris) {
302 // On MacOSX, we cannot distinguish between terminal options on the
303 // shebang line and those on the command line.
304 // On Solaris, all options after the first on the shebang line are
305 // ignored.
306 log.println("SKIPPED");
307 return;
308 }
309 Path base = Files.createDirectories(
310 Paths.get("testTerminalOptionInShebang"));
311 Path bad = base.resolve("bad");
312 createFile(bad, List.of(
313 "#!" + shebangJavaCmd + " --source " + thisVersion + " -version"));
314 setExecutable(bad);
315 TestResult tr = doExec(bad.toString());
316 if (!tr.contains("Option -version is not allowed in this context"))
317 error(tr, "Expected output not found");
318 show(tr);
319 }
320
321 // #!.../java --source N @bad.at (contains -version)
322 @Test
323 void testTerminalOptionInShebangAtFile() throws IOException {
324 starting("testTerminalOptionInShebangAtFile");
325 if (skipShebangTest || isMacOSX || isSolaris) {
326 // On MacOSX, we cannot distinguish between terminal options in a
327 // shebang @-file and those on the command line.
328 // On Solaris, all options after the first on the shebang line are
329 // ignored.
330 log.println("SKIPPED");
331 return;
332 }
333 // Use a short directory name, to avoid line length limitations
334 Path base = Files.createDirectories(Paths.get("testBadAtFile"));
335 Path bad_at = base.resolve("bad.at");
336 createFile(bad_at, List.of("-version"));
337 Path bad = base.resolve("bad");
338 createFile(bad, List.of(
339 "#!" + shebangJavaCmd + " --source " + thisVersion + " @" + bad_at));
340 setExecutable(bad);
341 TestResult tr = doExec(bad.toString());
342 if (!tr.contains("Option -version in @testBadAtFile/bad.at is "
343 + "not allowed in this context"))
344 error(tr, "Expected output not found");
345 show(tr);
346 }
347
348 // #!.../java --source N HelloWorld
349 @Test
350 void testMainClassInShebang() throws IOException {
351 starting("testMainClassInShebang");
352 if (skipShebangTest || isMacOSX || isSolaris) {
353 // On MacOSX, we cannot distinguish between a main class on the
354 // shebang line and one on the command line.
355 // On Solaris, all options after the first on the shebang line are
356 // ignored.
357 log.println("SKIPPED");
358 return;
359 }
360 Path base = Files.createDirectories(Paths.get("testMainClassInShebang"));
361 Path bad = base.resolve("bad");
362 createFile(bad, List.of(
363 "#!" + shebangJavaCmd + " --source " + thisVersion + " HelloWorld"));
364 setExecutable(bad);
365 TestResult tr = doExec(bad.toString());
366 if (!tr.contains("Cannot specify main class in this context"))
367 error(tr, "Expected output not found");
368 show(tr);
369 }
370
371 //--------------------------------------------------------------------------
372
373 private void starting(String label) {
374 System.out.println();
375 System.out.println("*** Starting: " + label + " (stdout)");
376
|
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 *
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.
22 */
23
24 /**
25 * @test
26 * @bug 8192920 8204588
27 * @summary Test source mode
28 * @modules jdk.compiler jdk.jlink
29 * @run main SourceMode
30 */
31
32
33 import java.io.IOException;
34 import java.io.PrintStream;
35 import java.nio.file.Files;
36 import java.nio.file.Path;
37 import java.nio.file.Paths;
38 import java.nio.file.attribute.PosixFilePermission;
39 import java.util.ArrayList;
40 import java.util.Arrays;
41 import java.util.HashMap;
42 import java.util.List;
43 import java.util.Map;
44 import java.util.Set;
281 error(tr, "Expected output not found");
282 show(tr);
283 }
284
285 // java --source N -m jdk.compiler
286 @Test
287 void testSourceModuleConflict() throws IOException {
288 starting("testSourceModuleConflict");
289 TestResult tr = doExec(javaCmd, "--source", thisVersion, "-m", "jdk.compiler");
290 if (tr.isOK())
291 error(tr, "Command succeeded unexpectedly");
292 if (!tr.contains("Option -m is not allowed with --source"))
293 error(tr, "Expected output not found");
294 show(tr);
295 }
296
297 // #!.../java --source N -version
298 @Test
299 void testTerminalOptionInShebang() throws IOException {
300 starting("testTerminalOptionInShebang");
301 if (skipShebangTest || isAIX || isMacOSX || isSolaris) {
302 // On MacOSX, we cannot distinguish between terminal options on the
303 // shebang line and those on the command line.
304 // On Solaris, all options after the first on the shebang line are
305 // ignored. Similar on AIX.
306 log.println("SKIPPED");
307 return;
308 }
309 Path base = Files.createDirectories(
310 Paths.get("testTerminalOptionInShebang"));
311 Path bad = base.resolve("bad");
312 createFile(bad, List.of(
313 "#!" + shebangJavaCmd + " --source " + thisVersion + " -version"));
314 setExecutable(bad);
315 TestResult tr = doExec(bad.toString());
316 if (!tr.contains("Option -version is not allowed in this context"))
317 error(tr, "Expected output not found");
318 show(tr);
319 }
320
321 // #!.../java --source N @bad.at (contains -version)
322 @Test
323 void testTerminalOptionInShebangAtFile() throws IOException {
324 starting("testTerminalOptionInShebangAtFile");
325 if (skipShebangTest || isAIX || isMacOSX || isSolaris) {
326 // On MacOSX, we cannot distinguish between terminal options in a
327 // shebang @-file and those on the command line.
328 // On Solaris, all options after the first on the shebang line are
329 // ignored. Similar on AIX.
330 log.println("SKIPPED");
331 return;
332 }
333 // Use a short directory name, to avoid line length limitations
334 Path base = Files.createDirectories(Paths.get("testBadAtFile"));
335 Path bad_at = base.resolve("bad.at");
336 createFile(bad_at, List.of("-version"));
337 Path bad = base.resolve("bad");
338 createFile(bad, List.of(
339 "#!" + shebangJavaCmd + " --source " + thisVersion + " @" + bad_at));
340 setExecutable(bad);
341 TestResult tr = doExec(bad.toString());
342 if (!tr.contains("Option -version in @testBadAtFile/bad.at is "
343 + "not allowed in this context"))
344 error(tr, "Expected output not found");
345 show(tr);
346 }
347
348 // #!.../java --source N HelloWorld
349 @Test
350 void testMainClassInShebang() throws IOException {
351 starting("testMainClassInShebang");
352 if (skipShebangTest || isAIX || isMacOSX || isSolaris) {
353 // On MacOSX, we cannot distinguish between a main class on the
354 // shebang line and one on the command line.
355 // On Solaris, all options after the first on the shebang line are
356 // ignored. Similar on AIX.
357 log.println("SKIPPED");
358 return;
359 }
360 Path base = Files.createDirectories(Paths.get("testMainClassInShebang"));
361 Path bad = base.resolve("bad");
362 createFile(bad, List.of(
363 "#!" + shebangJavaCmd + " --source " + thisVersion + " HelloWorld"));
364 setExecutable(bad);
365 TestResult tr = doExec(bad.toString());
366 if (!tr.contains("Cannot specify main class in this context"))
367 error(tr, "Expected output not found");
368 show(tr);
369 }
370
371 //--------------------------------------------------------------------------
372
373 private void starting(String label) {
374 System.out.println();
375 System.out.println("*** Starting: " + label + " (stdout)");
376
|