8007456: Nashorn test framework @argument does not handle quoted strings

Wed, 27 May 2015 16:52:49 +0530

author
sundar
date
Wed, 27 May 2015 16:52:49 +0530
changeset 1377
aa83c9841e3c
parent 1376
103c04f15c38
child 1378
45c33270c300

8007456: Nashorn test framework @argument does not handle quoted strings
Reviewed-by: hannesw, lagergren

src/jdk/nashorn/internal/runtime/ScriptingFunctions.java file | annotate | diff | comparison | revisions
test/src/jdk/nashorn/internal/test/framework/TestFinder.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Tue May 26 10:00:55 2015 -0700
     1.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java	Wed May 27 16:52:49 2015 +0530
     1.3 @@ -245,7 +245,7 @@
     1.4       * constitute the command line.
     1.5       * @throws IOException in case {@link StreamTokenizer#nextToken()} raises it.
     1.6       */
     1.7 -    private static List<String> tokenizeCommandLine(final String execString) throws IOException {
     1.8 +    public static List<String> tokenizeCommandLine(final String execString) throws IOException {
     1.9          final StreamTokenizer tokenizer = new StreamTokenizer(new StringReader(execString));
    1.10          tokenizer.resetSyntax();
    1.11          tokenizer.wordChars(0, 255);
     2.1 --- a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java	Tue May 26 10:00:55 2015 -0700
     2.2 +++ b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java	Wed May 27 16:52:49 2015 +0530
     2.3 @@ -22,7 +22,6 @@
     2.4   * or visit www.oracle.com if you need additional information or have any
     2.5   * questions.
     2.6   */
     2.7 -
     2.8  package jdk.nashorn.internal.test.framework;
     2.9  
    2.10  import static jdk.nashorn.internal.test.framework.TestConfig.OPTIONS_CHECK_COMPILE_MSG;
    2.11 @@ -61,14 +60,15 @@
    2.12  import java.util.EnumSet;
    2.13  import java.util.HashMap;
    2.14  import java.util.HashSet;
    2.15 +import java.util.Iterator;
    2.16  import java.util.List;
    2.17  import java.util.Map;
    2.18 -import java.util.Scanner;
    2.19  import java.util.Set;
    2.20  import javax.xml.xpath.XPath;
    2.21  import javax.xml.xpath.XPathConstants;
    2.22  import javax.xml.xpath.XPathExpressionException;
    2.23  import javax.xml.xpath.XPathFactory;
    2.24 +import jdk.nashorn.internal.runtime.ScriptingFunctions;
    2.25  import org.w3c.dom.NodeList;
    2.26  import org.xml.sax.InputSource;
    2.27  
    2.28 @@ -78,28 +78,33 @@
    2.29   */
    2.30  @SuppressWarnings("javadoc")
    2.31  public final class TestFinder {
    2.32 -    private TestFinder() {}
    2.33 +
    2.34 +    private TestFinder() {
    2.35 +    }
    2.36  
    2.37      interface TestFactory<T> {
    2.38 +
    2.39          // 'test' instance type is decided by the client.
    2.40 +
    2.41          T createTest(final String framework, final File testFile, final List<String> engineOptions, final Map<String, String> testOptions, final List<String> arguments);
    2.42 +
    2.43          // place to log messages from TestFinder
    2.44 +
    2.45          void log(String mg);
    2.46      }
    2.47  
    2.48 -
    2.49      // finds all tests from configuration and calls TestFactory to create 'test' instance for each script test found
    2.50      static <T> void findAllTests(final List<T> tests, final Set<String> orphans, final TestFactory<T> testFactory) throws Exception {
    2.51          final String framework = System.getProperty(TEST_JS_FRAMEWORK);
    2.52          final String testList = System.getProperty(TEST_JS_LIST);
    2.53          final String failedTestFileName = System.getProperty(TEST_FAILED_LIST_FILE);
    2.54 -        if(failedTestFileName != null) {
    2.55 +        if (failedTestFileName != null) {
    2.56              final File failedTestFile = new File(failedTestFileName);
    2.57 -            if(failedTestFile.exists() && failedTestFile.length() > 0L) {
    2.58 -                try(final BufferedReader r = new BufferedReader(new FileReader(failedTestFile))) {
    2.59 -                    for(;;) {
    2.60 +            if (failedTestFile.exists() && failedTestFile.length() > 0L) {
    2.61 +                try (final BufferedReader r = new BufferedReader(new FileReader(failedTestFile))) {
    2.62 +                    for (;;) {
    2.63                          final String testFileName = r.readLine();
    2.64 -                        if(testFileName == null) {
    2.65 +                        if (testFileName == null) {
    2.66                              break;
    2.67                          }
    2.68                          handleOneTest(framework, new File(testFileName).toPath(), tests, orphans, testFactory);
    2.69 @@ -151,7 +156,7 @@
    2.70          final Exception[] exceptions = new Exception[1];
    2.71          final List<String> excludedActualTests = new ArrayList<>();
    2.72  
    2.73 -        if (! dir.toFile().isDirectory()) {
    2.74 +        if (!dir.toFile().isDirectory()) {
    2.75              factory.log("WARNING: " + dir + " not found or not a directory");
    2.76          }
    2.77  
    2.78 @@ -219,27 +224,28 @@
    2.79  
    2.80          boolean explicitOptimistic = false;
    2.81  
    2.82 -        try (Scanner scanner = new Scanner(testFile)) {
    2.83 -            while (scanner.hasNext()) {
    2.84 -                // TODO: Scan for /ref=file qualifiers, etc, to determine run
    2.85 -                // behavior
    2.86 -                String token = scanner.next();
    2.87 -                if (token.startsWith("/*")) {
    2.88 -                    inComment = true;
    2.89 -                } else if (token.endsWith(("*/"))) {
    2.90 -                    inComment = false;
    2.91 -                } else if (!inComment) {
    2.92 -                    continue;
    2.93 -                }
    2.94 +        String allContent = new String(Files.readAllBytes(testFile));
    2.95 +        Iterator<String> scanner = ScriptingFunctions.tokenizeCommandLine(allContent).iterator();
    2.96 +        while (scanner.hasNext()) {
    2.97 +            // TODO: Scan for /ref=file qualifiers, etc, to determine run
    2.98 +            // behavior
    2.99 +            String token = scanner.next();
   2.100 +            if (token.startsWith("/*")) {
   2.101 +                inComment = true;
   2.102 +            } else if (token.endsWith(("*/"))) {
   2.103 +                inComment = false;
   2.104 +            } else if (!inComment) {
   2.105 +                continue;
   2.106 +            }
   2.107  
   2.108 -                // remove whitespace and trailing semicolons, if any
   2.109 -                // (trailing semicolons are found in some sputnik tests)
   2.110 -                token = token.trim();
   2.111 -                final int semicolon = token.indexOf(';');
   2.112 -                if (semicolon > 0) {
   2.113 -                    token = token.substring(0, semicolon);
   2.114 -                }
   2.115 -                switch (token) {
   2.116 +            // remove whitespace and trailing semicolons, if any
   2.117 +            // (trailing semicolons are found in some sputnik tests)
   2.118 +            token = token.trim();
   2.119 +            final int semicolon = token.indexOf(';');
   2.120 +            if (semicolon > 0) {
   2.121 +                token = token.substring(0, semicolon);
   2.122 +            }
   2.123 +            switch (token) {
   2.124                  case "@test":
   2.125                      isTest = true;
   2.126                      break;
   2.127 @@ -308,24 +314,21 @@
   2.128                      break;
   2.129                  default:
   2.130                      break;
   2.131 -                }
   2.132 +            }
   2.133  
   2.134 -                // negative tests are expected to fail at runtime only
   2.135 -                // for those tests that are expected to fail at compile time,
   2.136 -                // add @test/compile-error
   2.137 -                if (token.equals("@negative") || token.equals("@strict_mode_negative")) {
   2.138 -                    shouldRun = true;
   2.139 -                    runFailure = true;
   2.140 -                }
   2.141 +            // negative tests are expected to fail at runtime only
   2.142 +            // for those tests that are expected to fail at compile time,
   2.143 +            // add @test/compile-error
   2.144 +            if (token.equals("@negative") || token.equals("@strict_mode_negative")) {
   2.145 +                shouldRun = true;
   2.146 +                runFailure = true;
   2.147 +            }
   2.148  
   2.149 -                if (token.equals("@strict_mode") || token.equals("@strict_mode_negative") || token.equals("@onlyStrict") || token.equals("@noStrict")) {
   2.150 -                    if (!strictModeEnabled()) {
   2.151 -                        return;
   2.152 -                    }
   2.153 +            if (token.equals("@strict_mode") || token.equals("@strict_mode_negative") || token.equals("@onlyStrict") || token.equals("@noStrict")) {
   2.154 +                if (!strictModeEnabled()) {
   2.155 +                    return;
   2.156                  }
   2.157              }
   2.158 -        } catch (final Exception ignored) {
   2.159 -            return;
   2.160          }
   2.161  
   2.162          if (isTest) {
   2.163 @@ -369,8 +372,8 @@
   2.164      private static final boolean OPTIMISTIC_OVERRIDE = true;
   2.165  
   2.166      /**
   2.167 -     * Check if there is an optimistic override, that disables the default
   2.168 -     * false optimistic types and sets them to true, for testing purposes
   2.169 +     * Check if there is an optimistic override, that disables the default false
   2.170 +     * optimistic types and sets them to true, for testing purposes
   2.171       *
   2.172       * @return true if optimistic type override has been set by test suite
   2.173       */
   2.174 @@ -379,10 +382,9 @@
   2.175      }
   2.176  
   2.177      /**
   2.178 -     * Add an optimistic-types=true option to an argument list if this
   2.179 -     * is set to override the default false. Add an optimistic-types=true
   2.180 -     * options to an argument list if this is set to override the default
   2.181 -     * true
   2.182 +     * Add an optimistic-types=true option to an argument list if this is set to
   2.183 +     * override the default false. Add an optimistic-types=true options to an
   2.184 +     * argument list if this is set to override the default true
   2.185       *
   2.186       * @args new argument list array
   2.187       */
   2.188 @@ -396,8 +398,8 @@
   2.189      }
   2.190  
   2.191      /**
   2.192 -     * Add an optimistic-types=true option to an argument list if this
   2.193 -     * is set to override the default false
   2.194 +     * Add an optimistic-types=true option to an argument list if this is set to
   2.195 +     * override the default false
   2.196       *
   2.197       * @args argument list
   2.198       */
   2.199 @@ -438,7 +440,7 @@
   2.200  
   2.201      private static void loadExcludesFile(final String testExcludesFile, final Set<String> testExcludeSet) throws XPathExpressionException {
   2.202          final XPath xpath = XPathFactory.newInstance().newXPath();
   2.203 -        final NodeList testIds = (NodeList)xpath.evaluate("/excludeList/test/@id", new InputSource(testExcludesFile), XPathConstants.NODESET);
   2.204 +        final NodeList testIds = (NodeList) xpath.evaluate("/excludeList/test/@id", new InputSource(testExcludesFile), XPathConstants.NODESET);
   2.205          for (int i = testIds.getLength() - 1; i >= 0; i--) {
   2.206              testExcludeSet.add(testIds.item(i).getNodeValue());
   2.207          }

mercurial