< prev index next >

test/jdk/tools/launcher/SourceMode.java

Print this page
rev 59383 : [mq]: final
   1 /*
   2  * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
   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  *
  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  */


 306             error(tr, "Expected output not found");
 307         show(tr);
 308     }
 309 
 310     // java --source N -m jdk.compiler
 311     @Test
 312     void testSourceModuleConflict() throws IOException {
 313         starting("testSourceModuleConflict");
 314         TestResult tr = doExec(javaCmd, "--source", thisVersion, "-m", "jdk.compiler");
 315         if (tr.isOK())
 316             error(tr, "Command succeeded unexpectedly");
 317         if (!tr.contains("Option -m is not allowed with --source"))
 318             error(tr, "Expected output not found");
 319         show(tr);
 320     }
 321 
 322     // #!.../java --source N -version
 323     @Test
 324     void testTerminalOptionInShebang() throws IOException {
 325         starting("testTerminalOptionInShebang");
 326         if (skipShebangTest || isAIX || isMacOSX || isSolaris) {
 327             // On MacOSX, we cannot distinguish between terminal options on the
 328             // shebang line and those on the command line.
 329             // On Solaris, all options after the first on the shebang line are
 330             // ignored. Similar on AIX.
 331             log.println("SKIPPED");
 332             return;
 333         }
 334         Path base = Files.createDirectories(
 335             Paths.get("testTerminalOptionInShebang"));
 336         Path bad = base.resolve("bad");
 337         createFile(bad, List.of(
 338             "#!" + shebangJavaCmd + " --source " + thisVersion + " -version"));
 339         setExecutable(bad);
 340         TestResult tr = doExec(bad.toString());
 341         if (!tr.contains("Option -version is not allowed in this context"))
 342             error(tr, "Expected output not found");
 343         show(tr);
 344     }
 345 
 346     // #!.../java --source N @bad.at  (contains -version)
 347     @Test
 348     void testTerminalOptionInShebangAtFile() throws IOException {
 349         starting("testTerminalOptionInShebangAtFile");
 350         if (skipShebangTest || isAIX || isMacOSX || isSolaris) {
 351             // On MacOSX, we cannot distinguish between terminal options in a
 352             // shebang @-file and those on the command line.
 353             // On Solaris, all options after the first on the shebang line are
 354             // ignored. Similar on AIX.
 355             log.println("SKIPPED");
 356             return;
 357         }
 358         // Use a short directory name, to avoid line length limitations
 359         Path base = Files.createDirectories(Paths.get("testBadAtFile"));
 360         Path bad_at = base.resolve("bad.at");
 361         createFile(bad_at, List.of("-version"));
 362         Path bad = base.resolve("bad");
 363         createFile(bad, List.of(
 364             "#!" + shebangJavaCmd + " --source " + thisVersion + " @" + bad_at));
 365         setExecutable(bad);
 366         TestResult tr = doExec(bad.toString());
 367         if (!tr.contains("Option -version in @testBadAtFile/bad.at is "
 368                 + "not allowed in this context"))
 369             error(tr, "Expected output not found");
 370         show(tr);
 371     }
 372 
 373     // #!.../java --source N HelloWorld
 374     @Test
 375     void testMainClassInShebang() throws IOException {
 376         starting("testMainClassInShebang");
 377         if (skipShebangTest || isAIX || isMacOSX || isSolaris) {
 378             // On MacOSX, we cannot distinguish between a main class on the
 379             // shebang line and one on the command line.
 380             // On Solaris, all options after the first on the shebang line are
 381             // ignored. Similar on AIX.
 382             log.println("SKIPPED");
 383             return;
 384         }
 385         Path base = Files.createDirectories(Paths.get("testMainClassInShebang"));
 386         Path bad = base.resolve("bad");
 387         createFile(bad, List.of(
 388             "#!" + shebangJavaCmd + " --source " + thisVersion + " HelloWorld"));
 389         setExecutable(bad);
 390         TestResult tr = doExec(bad.toString());
 391         if (!tr.contains("Cannot specify main class in this context"))
 392             error(tr, "Expected output not found");
 393         show(tr);
 394     }
 395 
 396     //--------------------------------------------------------------------------
 397 


   1 /*
   2  * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
   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  *
  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  */


 306             error(tr, "Expected output not found");
 307         show(tr);
 308     }
 309 
 310     // java --source N -m jdk.compiler
 311     @Test
 312     void testSourceModuleConflict() throws IOException {
 313         starting("testSourceModuleConflict");
 314         TestResult tr = doExec(javaCmd, "--source", thisVersion, "-m", "jdk.compiler");
 315         if (tr.isOK())
 316             error(tr, "Command succeeded unexpectedly");
 317         if (!tr.contains("Option -m is not allowed with --source"))
 318             error(tr, "Expected output not found");
 319         show(tr);
 320     }
 321 
 322     // #!.../java --source N -version
 323     @Test
 324     void testTerminalOptionInShebang() throws IOException {
 325         starting("testTerminalOptionInShebang");
 326         if (skipShebangTest || isAIX || isMacOSX) {
 327             // On MacOSX, we cannot distinguish between terminal options on the
 328             // shebang line and those on the command line.
 329             // On Solaris, all options after the first on the shebang line are
 330             // ignored. Similar on AIX.
 331             log.println("SKIPPED");
 332             return;
 333         }
 334         Path base = Files.createDirectories(
 335             Paths.get("testTerminalOptionInShebang"));
 336         Path bad = base.resolve("bad");
 337         createFile(bad, List.of(
 338             "#!" + shebangJavaCmd + " --source " + thisVersion + " -version"));
 339         setExecutable(bad);
 340         TestResult tr = doExec(bad.toString());
 341         if (!tr.contains("Option -version is not allowed in this context"))
 342             error(tr, "Expected output not found");
 343         show(tr);
 344     }
 345 
 346     // #!.../java --source N @bad.at  (contains -version)
 347     @Test
 348     void testTerminalOptionInShebangAtFile() throws IOException {
 349         starting("testTerminalOptionInShebangAtFile");
 350         if (skipShebangTest || isAIX || isMacOSX) {
 351             // On MacOSX, we cannot distinguish between terminal options in a
 352             // shebang @-file and those on the command line.
 353             // On Solaris, all options after the first on the shebang line are
 354             // ignored. Similar on AIX.
 355             log.println("SKIPPED");
 356             return;
 357         }
 358         // Use a short directory name, to avoid line length limitations
 359         Path base = Files.createDirectories(Paths.get("testBadAtFile"));
 360         Path bad_at = base.resolve("bad.at");
 361         createFile(bad_at, List.of("-version"));
 362         Path bad = base.resolve("bad");
 363         createFile(bad, List.of(
 364             "#!" + shebangJavaCmd + " --source " + thisVersion + " @" + bad_at));
 365         setExecutable(bad);
 366         TestResult tr = doExec(bad.toString());
 367         if (!tr.contains("Option -version in @testBadAtFile/bad.at is "
 368                 + "not allowed in this context"))
 369             error(tr, "Expected output not found");
 370         show(tr);
 371     }
 372 
 373     // #!.../java --source N HelloWorld
 374     @Test
 375     void testMainClassInShebang() throws IOException {
 376         starting("testMainClassInShebang");
 377         if (skipShebangTest || isAIX || isMacOSX) {
 378             // On MacOSX, we cannot distinguish between a main class on the
 379             // shebang line and one on the command line.
 380             // On Solaris, all options after the first on the shebang line are
 381             // ignored. Similar on AIX.
 382             log.println("SKIPPED");
 383             return;
 384         }
 385         Path base = Files.createDirectories(Paths.get("testMainClassInShebang"));
 386         Path bad = base.resolve("bad");
 387         createFile(bad, List.of(
 388             "#!" + shebangJavaCmd + " --source " + thisVersion + " HelloWorld"));
 389         setExecutable(bad);
 390         TestResult tr = doExec(bad.toString());
 391         if (!tr.contains("Cannot specify main class in this context"))
 392             error(tr, "Expected output not found");
 393         show(tr);
 394     }
 395 
 396     //--------------------------------------------------------------------------
 397 


< prev index next >