Skip to content

Commit 38e3c26

Browse files
committed
Add a regression test for load(path)
Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 01686e6 commit 38e3c26

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/test/java/org/scijava/plugins/scripting/javascript/JavaScriptTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
import static org.junit.Assert.assertNull;
3636
import static org.junit.Assert.assertTrue;
3737

38+
import java.io.File;
39+
import java.io.FileWriter;
3840
import java.io.IOException;
41+
import java.io.Writer;
3942
import java.util.concurrent.ExecutionException;
4043

4144
import javax.script.Bindings;
@@ -109,4 +112,18 @@ public void testParameters() throws InterruptedException, ExecutionException,
109112
assertEquals(expected, result);
110113
}
111114

115+
@Test
116+
public void testLoad() throws IOException, InterruptedException, ExecutionException, ScriptException {
117+
final File tmp = File.createTempFile("js-lib-", ".js");
118+
final Writer writer = new FileWriter(tmp);
119+
writer.write("function three() { return 4; }");
120+
writer.close();
121+
122+
final Context context = new Context(ScriptService.class);
123+
final ScriptService scriptService = context.getService(ScriptService.class);
124+
final String script = "load('" + tmp.getPath() + "'); three();";
125+
final Object result = scriptService.run("three.js", script, false).get().getReturnValue();
126+
assertEquals(4.0, (Number) result);
127+
assertTrue(tmp.delete());
128+
}
112129
}

0 commit comments

Comments
 (0)