Skip to content

Commit d1438e7

Browse files
committed
Test the improved script return value behavior
When _no_ explicit @output is given, the return value _is_ appended. When an explicit @output _is_ given, the return value is _not_ appended.
1 parent dc4faa0 commit d1438e7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/test/java/org/scijava/script/ScriptInfoTest.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
package org.scijava.script;
3333

3434
import static org.junit.Assert.assertEquals;
35+
import static org.junit.Assert.assertFalse;
3536
import static org.junit.Assert.assertSame;
3637
import static org.junit.Assert.assertTrue;
3738
import static org.junit.Assert.fail;
@@ -45,6 +46,7 @@
4546
import java.util.Collections;
4647
import java.util.HashMap;
4748
import java.util.List;
49+
import java.util.Map;
4850

4951
import javax.script.Bindings;
5052
import javax.script.ScriptContext;
@@ -84,6 +86,42 @@ public static void tearDown() {
8486

8587
// -- Tests --
8688

89+
/**
90+
* Tests that the return value <em>is</em> appended as an extra output when no
91+
* explicit outputs were declared.
92+
*/
93+
@Test
94+
public void testReturnValueAppended() throws Exception {
95+
final String script = "" + //
96+
"% @LogService log\n" + //
97+
"% @int value\n";
98+
final ScriptModule scriptModule =
99+
scriptService.run("include-return-value.bsizes", script, true).get();
100+
101+
final Map<String, Object> outputs = scriptModule.getOutputs();
102+
assertEquals(1, outputs.size());
103+
assertTrue(outputs.containsKey(ScriptModule.RETURN_VALUE));
104+
}
105+
106+
/**
107+
* Tests that the return value is <em>not</em> appended as an extra output
108+
* when explicit outputs were declared.
109+
*/
110+
@Test
111+
public void testReturnValueExcluded() throws Exception {
112+
final String script = "" + //
113+
"% @LogService log\n" + //
114+
"% @OUTPUT int value\n";
115+
final ScriptModule scriptModule =
116+
scriptService.run("exclude-return-value.bsizes", script, true).get();
117+
118+
final Map<String, Object> outputs = scriptModule.getOutputs();
119+
assertEquals(1, outputs.size());
120+
assertTrue(outputs.containsKey("value"));
121+
assertFalse(outputs.containsKey(ScriptModule.RETURN_VALUE));
122+
}
123+
124+
87125
/**
88126
* Ensures parameters are parsed correctly from scripts, even in the presence
89127
* of noise like e-mail addresses.

0 commit comments

Comments
 (0)