public void testJsApi() throws Exception { Context cx = RhinoAndroidHelper.prepareContext(); try { cx.setOptimizationLevel(-1); Script script = cx.compileString(TestUtils.readAsset("Bug482203.js"), "", 1, null); Scriptable scope = cx.initStandardObjects(); script.exec(cx, scope); int counter = 0; for(;;) { Object cont = ScriptableObject.getProperty(scope, "c"); if(cont == null) { break; } counter++; ((Callable)cont).call(cx, scope, scope, new Object[] { null }); } assertEquals(counter, 5); assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result")); } finally { Context.exit(); } }
public void testJavaApi() throws Exception { Context cx = RhinoAndroidHelper.prepareContext(); try { cx.setOptimizationLevel(-1); Script script = cx.compileString(TestUtils.readAsset("Bug482203.js"), "", 1, null); Scriptable scope = cx.initStandardObjects(); cx.executeScriptWithContinuations(script, scope); int counter = 0; for(;;) { Object cont = ScriptableObject.getProperty(scope, "c"); if(cont == null) { break; } counter++; cx.resumeContinuation(cont, scope, null); } assertEquals(counter, 5); assertEquals(Double.valueOf(3), ScriptableObject.getProperty(scope, "result")); } finally { Context.exit(); } }
@Test public void runDoctest() throws Exception { Context cx = RhinoAndroidHelper.prepareContext(); try { cx.setOptimizationLevel(optimizationLevel); Global global = new Global(cx); TestUtils.addAssetLoading(global); // global.runDoctest throws an exception on any failure int testsPassed = global.runDoctest(cx, global, source, name, 1); System.out.println(name + "(" + optimizationLevel + "): " + testsPassed + " passed."); assertTrue(testsPassed > 0); } catch (Exception ex) { System.out.println(name + "(" + optimizationLevel + "): FAILED due to "+ex); throw ex; } finally { Context.exit(); } }
public static File[] getTestFiles(int optimizationLevel) throws IOException { File testDir = getTestDir(); String[] tests = TestUtils.loadTestsFromResource( "/" + getTestFilename(optimizationLevel), null); Arrays.sort(tests); File[] files = new File[tests.length]; for (int i=0; i < files.length; i++) { files[i] = new File(testDir, tests[i]); } return files; }
public void runJsTests() throws IOException { File[] tests = TestUtils.recursiveListFiles(new File(baseDirectory), new FileFilter() { public boolean accept(File f) { return f.getName().endsWith(jstestsExtension); } }); runJsTests(tests); }
public static File[] getDoctestFiles() { return TestUtils.recursiveListFiles(new File(baseDirectory), new FileFilter() { public boolean accept(File f) { return f.getName().endsWith(doctestsExtension); } }); }
private void runTest(int optLevel) throws IOException { Context cx = RhinoAndroidHelper.prepareContext(); cx.setLanguageVersion(Context.VERSION_1_8); cx.setOptimizationLevel(optLevel); Global root = new Global(cx); TestUtils.addAssetLoading(root); root.put("RUN_NAME", root, "V8-Benchmark-" + optLevel); Object result = cx.evaluateString(root, TestUtils.readAsset(TEST_SRC), TEST_SRC, 1, null); results.put(optLevel, result.toString()); }
private void runTest(int optLevel) throws IOException { Context cx = RhinoAndroidHelper.prepareContext(); cx.setLanguageVersion(Context.VERSION_1_8); cx.setOptimizationLevel(optLevel); Global root = new Global(cx); TestUtils.addAssetLoading(root); root.put("RUN_NAME", root, "SunSpider-" + optLevel); Object result = cx.evaluateString(root, TestUtils.readAsset(TEST_SRC), TEST_SRC, 1, null); results.put(optLevel, result.toString()); }
public void testThrowing() throws Exception { cx = RhinoAndroidHelper.prepareContext(); try { Script script = cx.compileString(TestUtils.readAsset("Issue176.js"), "Issue176.js", 1, null); scope = cx.initStandardObjects(); scope.put("host", scope, this); script.exec(cx, scope); // calls our methods } finally { Context.exit(); } }
public void testNonSandboxed() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); final String jsFile = TestUtils.readAsset(dir + File.separator + "testNonSandboxed.js"); ScriptableObject.putProperty(scope, "moduleUri", jsFile); require.requireMain(cx, "testNonSandboxed"); }
public void testRelativeId() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); require.install(scope); cx.evaluateString(scope, TestUtils.readAsset(dir + File.separator + "testRelativeId.js"), "testRelativeId.js", 1, null); }
public void testSetMainForAlreadyLoadedModule() throws Exception { final Context cx = createContext(); final Scriptable scope = cx.initStandardObjects(); final Require require = getSandboxedRequire(cx, scope, false); require.install(scope); cx.evaluateString(scope, TestUtils.readAsset(dir + File.separator + "testSetMainForAlreadyLoadedModule.js"), "testSetMainForAlreadyLoadedModule.js", 1, null); try { require.requireMain(cx, "assert"); fail(); } catch (IllegalStateException e) { assertEquals(e.getMessage(), "Attempt to set main module after it was loaded"); } }
@Parameterized.Parameters(name = "/{0}") public static Collection<Object[]> data() { List<Object[]> retval = new ArrayList<Object[]>(16); final List<File> files = TestUtils.listAssetDirectories("org/mozilla/javascript/tests/commonjs/module/1.0"); for (File file : files) { retval.add(new Object[]{file.getName(), file}); } return retval; }
public void runJsTests() throws IOException { File[] tests = TestUtils.recursiveListAssets(new File(baseDirectory), new FileFilter() { public boolean accept(File f) { return f.getName().endsWith(jstestsExtension); } }); runJsTests(tests); }
public static File[] getDoctestFiles() { return TestUtils.recursiveListAssets(new File(baseDirectory), new FileFilter() { public boolean accept(File f) { return f.getName().endsWith(doctestsExtension); } }); }
@Parameters(name = "{0}") public static Collection<Object[]> doctestValues() throws IOException { File[] doctests = getDoctestFiles(); List<Object[]> result = new ArrayList<Object[]>(); for (File f : doctests) { String contents = TestUtils.readAsset(f); result.add(new Object[] { f.getName(), contents, -1 }); result.add(new Object[] { f.getName(), contents, 0 }); result.add(new Object[] { f.getName(), contents, 9 }); } return result; }
public static Collection<Object[]> singleDoctest() throws IOException { List<Object[]> result = new ArrayList<Object[]>(); File f = new File(baseDirectory, "Counter.doctest"); String contents = TestUtils.readAsset(f); result.add(new Object[] { f.getName(), contents, -1 }); return result; }
@Before public void init() { cx = RhinoAndroidHelper.prepareContext(); cx.setLanguageVersion(Context.VERSION_1_8); cx.setGeneratingDebug(true); Global global = new Global(cx); TestUtils.addAssetLoading(global); root = cx.newObject(global); }
/** * The main class will run all the test files that are *not* covered in * the *.tests files, and print out a list of all the tests that pass. */ public static void main(String[] args) throws IOException { PrintStream out = new PrintStream("fix-tests-files.sh"); try { for (int i=0; i < OPT_LEVELS.length; i++) { int optLevel = OPT_LEVELS[i]; File testDir = getTestDir(); File[] allTests = TestUtils.recursiveListFiles(testDir, new FileFilter() { public boolean accept(File pathname) { return ShellTest.DIRECTORY_FILTER.accept(pathname) || ShellTest.TEST_FILTER.accept(pathname); } }); HashSet<File> diff = new HashSet<File>(Arrays.asList(allTests)); File testFiles[] = getTestFiles(optLevel); diff.removeAll(Arrays.asList(testFiles)); ArrayList<String> skippedPassed = new ArrayList<String>(); int absolutePathLength = testDir.getAbsolutePath().length() + 1; for (File testFile: diff) { try { (new MozillaSuiteTest(testFile, optLevel)).runMozillaTest(); // strip off testDir String canonicalized = testFile.getAbsolutePath().substring(absolutePathLength); canonicalized = canonicalized.replace('\\', '/'); skippedPassed.add(canonicalized); } catch (Throwable t) { // failed, so skip } } // "skippedPassed" now contains all the tests that are currently // skipped but now pass. Print out shell commands to update the // appropriate *.tests file. if (skippedPassed.size() > 0) { out.println("cat >> " + getTestFilename(optLevel) + " <<EOF"); String[] sorted = skippedPassed.toArray(new String[0]); Arrays.sort(sorted); for (int j=0; j < sorted.length; j++) { out.println(sorted[j]); } out.println("EOF"); } } System.out.println("Done."); } finally { out.close(); } }
@Override protected void setUp() { TestUtils.setGlobalContextFactory(new MyFactory()); }
@Override protected void tearDown() { TestUtils.setGlobalContextFactory(null); }
@Override protected void setUp() { TestUtils.setGlobalContextFactory(contextFactory); }
public static List<File> getTestFiles() throws IOException { File testDir = new File("test262/test"); List<File> testFiles = new LinkedList<File>(); List<File> dirFiles = new LinkedList<File>(); Scanner scanner = new Scanner(TestUtils.readAsset("test262.properties")); String curLine = "", nxtLine = ""; while (true) { curLine = nxtLine; nxtLine = scanner.hasNextLine() ? scanner.nextLine() : null; if (curLine == null) break; if (curLine.isEmpty() || curLine.startsWith("#")) continue; File file = new File(testDir, curLine); if (file.isFile()) { testFiles.add(file); } else if (file.isDirectory()) { recursiveListAssetsHelper(file, JS_FILE_FILTER, dirFiles); while (true) { curLine = nxtLine; nxtLine = scanner.hasNextLine() ? scanner.nextLine() : null; if (curLine == null) { testFiles.addAll(dirFiles); break; } if (curLine.isEmpty() || curLine.startsWith("#")) continue; Matcher m = EXCLUDE_PATTERN.matcher(curLine); if (m.matches()) { Iterator<File> it = dirFiles.iterator(); while (it.hasNext()) { String path = it.next().getPath().replaceAll("\\\\", "/"); if (path.contains(m.group(1))) it.remove(); } } else { testFiles.addAll(dirFiles); dirFiles.clear(); file = new File(testDir, curLine); if (file.isFile()) { testFiles.add(file); break; } else if (file.isDirectory()) { recursiveListAssetsHelper(file, JS_FILE_FILTER, dirFiles); } } } } } scanner.close(); return testFiles; }
/** * The main class will run all the test files that are *not* covered in * the *.tests files, and print out a list of all the tests that pass. */ public static void main(String[] args) throws IOException { PrintStream out = new PrintStream("fix-tests-files.sh"); try { for (int i=0; i < OPT_LEVELS.length; i++) { int optLevel = OPT_LEVELS[i]; File testDir = getTestDir(); File[] allTests = TestUtils.recursiveListAssets(testDir, new FileFilter() { public boolean accept(File pathname) { return ShellTest.DIRECTORY_FILTER.accept(pathname) || ShellTest.TEST_FILTER.accept(pathname); } }); HashSet<File> diff = new HashSet<File>(Arrays.asList(allTests)); File testFiles[] = getTestFiles(optLevel); diff.removeAll(Arrays.asList(testFiles)); ArrayList<String> skippedPassed = new ArrayList<String>(); int absolutePathLength = testDir.getAbsolutePath().length() + 1; for (File testFile: diff) { try { (new MozillaSuiteTest(testFile, optLevel)).runMozillaTest(); // strip off testDir String canonicalized = testFile.getAbsolutePath().substring(absolutePathLength); canonicalized = canonicalized.replace('\\', '/'); skippedPassed.add(canonicalized); } catch (Throwable t) { // failed, so skip } } // "skippedPassed" now contains all the tests that are currently // skipped but now pass. Print out shell commands to update the // appropriate *.tests file. if (skippedPassed.size() > 0) { out.println("cat >> " + getTestFilename(optLevel) + " <<EOF"); String[] sorted = skippedPassed.toArray(new String[0]); Arrays.sort(sorted); for (int j=0; j < sorted.length; j++) { out.println(sorted[j]); } out.println("EOF"); } } System.out.println("Done."); } finally { out.close(); } }
private URI getDirectory() throws URISyntaxException { final String jsFile = TestUtils.readAsset(getClass().getPackage().getName() + File.separator + "testSandboxed.js"); return new URI(jsFile); }
private void runScript(String script, int opt) { cx.setOptimizationLevel(opt); cx.evaluateString(root, TestUtils.readAsset(script), script, 1, null); }