aboutsummaryrefslogtreecommitdiff
path: root/test/src/jdk/nashorn/internal/test/framework/TestFinder.java
diff options
context:
space:
mode:
Diffstat (limited to 'test/src/jdk/nashorn/internal/test/framework/TestFinder.java')
-rw-r--r--test/src/jdk/nashorn/internal/test/framework/TestFinder.java82
1 files changed, 75 insertions, 7 deletions
diff --git a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java
index d879976d..32b1cbd5 100644
--- a/test/src/jdk/nashorn/internal/test/framework/TestFinder.java
+++ b/test/src/jdk/nashorn/internal/test/framework/TestFinder.java
@@ -42,11 +42,11 @@ import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_INCLUDES;
import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_LIST;
import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_ROOTS;
import static jdk.nashorn.internal.test.framework.TestConfig.TEST_JS_UNCHECKED_DIR;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
+import java.nio.ByteOrder;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.FileVisitOption;
@@ -56,6 +56,7 @@ import java.nio.file.Path;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
@@ -75,7 +76,8 @@ import org.xml.sax.InputSource;
* Utility class to find/parse script test files and to create 'test' instances.
* Actual 'test' object type is decided by clients of this class.
*/
-final class TestFinder {
+@SuppressWarnings("javadoc")
+public final class TestFinder {
private TestFinder() {}
interface TestFactory<T> {
@@ -92,7 +94,7 @@ final class TestFinder {
final String testList = System.getProperty(TEST_JS_LIST);
final String failedTestFileName = System.getProperty(TEST_FAILED_LIST_FILE);
if(failedTestFileName != null) {
- File failedTestFile = new File(failedTestFileName);
+ final File failedTestFile = new File(failedTestFileName);
if(failedTestFile.exists() && failedTestFile.length() > 0L) {
try(final BufferedReader r = new BufferedReader(new FileReader(failedTestFile))) {
for(;;) {
@@ -195,7 +197,7 @@ final class TestFinder {
return false;
}
- private static <T> void handleOneTest(final String framework, final Path testFile, final List<T> tests, final Set<String> orphans, TestFactory<T> factory) throws Exception {
+ private static <T> void handleOneTest(final String framework, final Path testFile, final List<T> tests, final Set<String> orphans, final TestFactory<T> factory) throws Exception {
final String name = testFile.getFileName().toString();
assert name.lastIndexOf(".js") > 0 : "not a JavaScript: " + name;
@@ -215,6 +217,8 @@ final class TestFinder {
final List<String> scriptArguments = new ArrayList<>();
boolean inComment = false;
+ boolean explicitOptimistic = false;
+
try (Scanner scanner = new Scanner(testFile)) {
while (scanner.hasNext()) {
// TODO: Scan for /ref=file qualifiers, etc, to determine run
@@ -261,14 +265,23 @@ final class TestFinder {
isTest = false;
isNotTest = true;
break;
- case "@runif":
- if (System.getProperty(scanner.next()) != null) {
+ case "@bigendian":
+ shouldRun = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
+ break;
+ case "@littleendian":
+ shouldRun = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
+ break;
+ case "@runif": {
+ final String prop = scanner.next();
+ if (System.getProperty(prop) != null) {
shouldRun = true;
} else {
+ factory.log("WARNING: (" + prop + ") skipping " + testFile);
isTest = false;
isNotTest = true;
}
break;
+ }
case "@run":
shouldRun = true;
break;
@@ -284,11 +297,17 @@ final class TestFinder {
scriptArguments.add(scanner.next());
break;
case "@option":
- engineOptions.add(scanner.next());
+ final String next = scanner.next();
+ engineOptions.add(next);
+ if (next.startsWith("--optimistic-types")) {
+ explicitOptimistic = true;
+ }
break;
case "@fork":
fork = true;
break;
+ default:
+ break;
}
// negative tests are expected to fail at runtime only
@@ -333,12 +352,61 @@ final class TestFinder {
testOptions.put(OPTIONS_FORK, "true");
}
+ //if there are explicit optimistic type settings, use those - do not override
+ //the test might only work with optimistic types on or off.
+ if (!explicitOptimistic) {
+ addExplicitOptimisticTypes(engineOptions);
+ }
+
tests.add(factory.createTest(framework, testFile.toFile(), engineOptions, testOptions, scriptArguments));
} else if (!isNotTest) {
orphans.add(name);
}
}
+ //the reverse of the default setting for optimistic types, if enabled, false, otherwise true
+ //thus, true for 8u40, false for 9
+ private static final boolean OPTIMISTIC_OVERRIDE = true;
+
+ /**
+ * Check if there is an optimistic override, that disables the default
+ * false optimistic types and sets them to true, for testing purposes
+ *
+ * @return true if optimistic type override has been set by test suite
+ */
+ public static boolean hasOptimisticOverride() {
+ return Boolean.valueOf(OPTIMISTIC_OVERRIDE).toString().equals(System.getProperty("optimistic.override"));
+ }
+
+ /**
+ * Add an optimistic-types=true option to an argument list if this
+ * is set to override the default false. Add an optimistic-types=true
+ * options to an argument list if this is set to override the default
+ * true
+ *
+ * @args new argument list array
+ */
+ public static String[] addExplicitOptimisticTypes(final String[] args) {
+ if (hasOptimisticOverride()) {
+ final List<String> newList = new ArrayList<>(Arrays.asList(args));
+ newList.add("--optimistic-types=" + Boolean.valueOf(OPTIMISTIC_OVERRIDE));
+ return newList.toArray(new String[0]);
+ }
+ return args;
+ }
+
+ /**
+ * Add an optimistic-types=true option to an argument list if this
+ * is set to override the default false
+ *
+ * @args argument list
+ */
+ public static void addExplicitOptimisticTypes(final List<String> args) {
+ if (hasOptimisticOverride()) {
+ args.add("--optimistic-types=" + Boolean.valueOf(OPTIMISTIC_OVERRIDE));
+ }
+ }
+
private static boolean strictModeEnabled() {
return Boolean.getBoolean(TEST_JS_ENABLE_STRICT_MODE);
}