test/script/currently-failing/JDK-8144221.js

changeset 1826
11bf0d1b18c1
parent 1825
8673bde5227d
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/script/currently-failing/JDK-8144221.js	Mon May 23 09:25:36 2016 +0200
     1.3 @@ -0,0 +1,155 @@
     1.4 +/*
     1.5 + * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + */
    1.26 +
    1.27 +/**
    1.28 + * Test that shebang handling works properly.
    1.29 + *
    1.30 + * @test
    1.31 + * @option -scripting
    1.32 + * @run
    1.33 + */
    1.34 +
    1.35 +// The test generates three different JavaScript source files. The first two
    1.36 +// are generated at the beginning of the test and do not change.
    1.37 +// * a.js
    1.38 +//   print("A: " + arguments)
    1.39 +// * b.js
    1.40 +//   #!<path_to_jjs> -lalelu -- ignore
    1.41 +//   print("B: " + arguments)
    1.42 +//
    1.43 +// The third file, shebang.js, is generated differently for each particular
    1.44 +// test case, containing different shebang lines and one statement:
    1.45 +// * shebang.js
    1.46 +//   #!<path_to_jjs> <shebang_line>
    1.47 +//   print("S: " + arguments)
    1.48 +//
    1.49 +// The path_to_jjs is extracted from the environment based on JAVA_HOME, so the
    1.50 +// latter must be set properly.
    1.51 +//
    1.52 +// Each shebang.js is run four times, in all possible combinations of values
    1.53 +// from the following two axes:
    1.54 +// * without passing any arguments, and passing the arguments 'a.js' and
    1.55 +//   '"hello world"' (the latter being a quoted string);
    1.56 +// * run via jjs, and via direct shell execution (using shebang).
    1.57 +
    1.58 +var pseudosheb  = "#!${jjs} -lalelu -- ignore",
    1.59 +    System      = Java.type('java.lang.System'),
    1.60 +    Paths       = Java.type('java.nio.file.Paths'),
    1.61 +    Files       = Java.type('java.nio.file.Files'),
    1.62 +    Opt         = Java.type('java.nio.file.StandardOpenOption'),
    1.63 +    Arrays      = Java.type('java.util.Arrays')
    1.64 +
    1.65 +var sep      = Java.type('java.io.File').separator,
    1.66 +    win      = System.getProperty("os.name").startsWith("Windows"),
    1.67 +    jjsName  = "jjs" + (win ? ".exe" : ""),
    1.68 +    javaHome = System.getProperty("java.home")
    1.69 +
    1.70 +var jjs = javaHome + "/../bin/".replace(/\//g, sep) + jjsName
    1.71 +if (!Files.exists(Paths.get(jjs))) {
    1.72 +    jjs = javaHome + "/bin/".replace(/\//g, sep) + jjsName
    1.73 +}
    1.74 +
    1.75 +// Create and cwd to a temporary directory.
    1.76 +
    1.77 +var tmpdir = Files.createTempDirectory(null),
    1.78 +    tmp    = tmpdir.toAbsolutePath().toString(),
    1.79 +    curpwd = $ENV.PWD
    1.80 +
    1.81 +$ENV.PWD = tmp
    1.82 +
    1.83 +// Test cases. Each case is documented with the expected output for the four
    1.84 +// different executions.
    1.85 +
    1.86 +var shebs = [
    1.87 +        // No arguments on the shebang line.
    1.88 +        // noargs jjs/shebang -> no output but "S" prefix
    1.89 +        // args jjs/shebang   -> output the arguments with "S" prefix
    1.90 +        "",
    1.91 +        // One interpreter argument.
    1.92 +        // noargs jjs/shebang -> no output but "S" prefix
    1.93 +        // args jjs/shebang   -> output the arguments with "S" prefix
    1.94 +        "--language=es6",
    1.95 +        // Two interpreter arguments.
    1.96 +        // noargs jjs/shebang -> no output but "S" prefix
    1.97 +        // args jjs/shebang   -> output the arguments with "S" prefix
    1.98 +        "--language=es6 -scripting",
    1.99 +        // One interpreter argument and a JavaScript file without shebang.
   1.100 +        // (For shebang execution, this is a pathological example, as the
   1.101 +        // JavaScript file passed as a shebang argument will be analyzed and
   1.102 +        // shebang mode will not be entered.)
   1.103 +        // noargs jjs     -> no output but "S" prefix
   1.104 +        // args jjs       -> output the arguments with "S" prefix
   1.105 +        // noargs shebang -> no output but "A" and "S" prefixes
   1.106 +        // args shebang   -> output "A", "S", and "A" prefixes, then the error
   1.107 +        //                   message:
   1.108 +        //                   "java.io.IOException: hello world is not a file"
   1.109 +        "-scripting a.js",
   1.110 +        // One interpreter argument and a JavaScript file with shebang. (This
   1.111 +        // is another pathological example, as it will force shebang mode,
   1.112 +        // leading to all subsequent arguments, including shebang.js, being
   1.113 +        // treated as arguments to the script b.js.)
   1.114 +        // noargs jjs     -> no output but the "S" prefix
   1.115 +        // args jjs       -> output the arguments with "S" prefix
   1.116 +        // noargs shebang -> output shebang.js with "B" prefix
   1.117 +        // args shebang   -> output shebang.js and the arguments with "B"
   1.118 +        //                   prefix
   1.119 +        "-scripting b.js"
   1.120 +    ]
   1.121 +
   1.122 +function write(file, lines) {
   1.123 +    Files.write(Paths.get(tmp, file), Arrays.asList(lines), Opt.CREATE, Opt.WRITE)
   1.124 +}
   1.125 +
   1.126 +function insn(name) {
   1.127 +    return "print('${name}:' + arguments)"
   1.128 +}
   1.129 +
   1.130 +function run(viajjs, name, arg1, arg2) {
   1.131 +    var prefix = viajjs ? "${jjs} -scripting " : win ? 'sh -c "' : '',
   1.132 +        suffix = viajjs ? '' : win ? '"' : ''
   1.133 +    $EXEC("${prefix}./shebang.js ${arg1} ${arg2}${suffix}")
   1.134 +    print("* ${name} via ${viajjs ? 'jjs' : 'shebang'}")
   1.135 +    print($OUT.trim())
   1.136 +    print($ERR.trim())
   1.137 +}
   1.138 +
   1.139 +write('a.js', insn('A'))
   1.140 +write('b.js', [pseudosheb, insn('B')])
   1.141 +
   1.142 +shebs.forEach(function(sheb) {
   1.143 +    var shebang = "#!${jjs} ${sheb}"
   1.144 +    print("<<< ${sheb} >>>")
   1.145 +    write('shebang.js', [shebang, insn('S')])
   1.146 +    $EXEC('chmod +x shebang.js')
   1.147 +    run(false, 'noargs', '', '')
   1.148 +    run(true, 'noargs', '', '')
   1.149 +    run(false, 'withargs', 'a.js', "'hello world'")
   1.150 +    run(true, 'withargs', 'a.js', "'hello world'")
   1.151 +    $EXEC('rm shebang.js')
   1.152 +})
   1.153 +
   1.154 +// Cleanup.
   1.155 +
   1.156 +$EXEC('rm a.js b.js')
   1.157 +$ENV.PWD = curpwd
   1.158 +Files.delete(tmpdir)

mercurial