Skip to content
Permalink
Browse files
8241982: Make TestSearchScript.java run with GraalJS
Reviewed-by: sundar, jjg
  • Loading branch information
hns committed Apr 14, 2020
1 parent 165fa24 commit 1cc71b41deb34c0238b024c31676a329ddc21ef2
Showing 1 changed file with 24 additions and 3 deletions.
@@ -23,7 +23,7 @@

/*
* @test
* @bug 8178982 8220497 8210683
* @bug 8178982 8220497 8210683 8241982
* @summary Test the search feature of javadoc.
* @library ../../lib
* @modules jdk.javadoc/jdk.javadoc.internal.tool
@@ -33,7 +33,9 @@

import javadoc.tester.JavadocTester;

import javax.script.Bindings;
import javax.script.Invocable;
import javax.script.ScriptContext;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;
@@ -44,7 +46,8 @@
import java.util.List;

/*
* Tests for the search feature using Nashorn JavaScript engine.
* Tests for the search feature using any available javax.script JavaScript engine.
* The test is skipped if no JavaScript engine is available.
*/
public class TestSearchScript extends JavadocTester {

@@ -55,7 +58,15 @@ public static void main(String... args) throws Exception {

private Invocable getEngine() throws ScriptException, IOException, NoSuchMethodException {
ScriptEngineManager engineManager = new ScriptEngineManager();
ScriptEngine engine = engineManager.getEngineByName("nashorn");
// Use "js" engine name to use any available JavaScript engine.
ScriptEngine engine = engineManager.getEngineByName("js");
if (engine == null) {
return null;
}
// For GraalJS set Nashorn compatibility mode via Bindings,
// see https://github.com/graalvm/graaljs/blob/master/docs/user/ScriptEngine.md
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("polyglot.js.nashorn-compat", true);
engine.eval(new BufferedReader(new FileReader(new File(testSrc, "javadoc-search.js"))));
Invocable inv = (Invocable) engine;
inv.invokeFunction("loadIndexFiles", outputDir.getAbsolutePath());
@@ -74,6 +85,11 @@ public void testModuleSearch() throws ScriptException, IOException, NoSuchMethod

Invocable inv = getEngine();

if (inv == null) {
out.println("No JavaScript engine available. Test skipped.");
return;
}

// exact match, case sensitivity
checkSearch(inv, "mapmodule", List.of("mapmodule"));
checkSearch(inv, "mappkg", List.of("mapmodule/mappkg", "mapmodule/mappkg.impl", "mappkg.system.property"));
@@ -170,6 +186,11 @@ public void testPackageSource() throws ScriptException, IOException, NoSuchMetho

Invocable inv = getEngine();

if (inv == null) {
out.println("No JavaScript engine available. Test skipped.");
return;
}

// exact match, case sensitvity, left boundaries
checkSearch(inv, "list", List.of("listpkg", "listpkg.List", "listpkg.ListProvider", "listpkg.MyList",
"listpkg.MyListFactory", "listpkg.ListProvider.ListProvider()",

0 comments on commit 1cc71b4

Please sign in to comment.