|
32 | 32 | package org.scijava.script; |
33 | 33 |
|
34 | 34 | import static org.junit.Assert.assertEquals; |
| 35 | +import static org.junit.Assert.assertFalse; |
35 | 36 | import static org.junit.Assert.assertSame; |
36 | 37 | import static org.junit.Assert.assertTrue; |
37 | 38 | import static org.junit.Assert.fail; |
|
45 | 46 | import java.util.Collections; |
46 | 47 | import java.util.HashMap; |
47 | 48 | import java.util.List; |
| 49 | +import java.util.Map; |
48 | 50 |
|
49 | 51 | import javax.script.Bindings; |
50 | 52 | import javax.script.ScriptContext; |
@@ -84,6 +86,42 @@ public static void tearDown() { |
84 | 86 |
|
85 | 87 | // -- Tests -- |
86 | 88 |
|
| 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 | + |
87 | 125 | /** |
88 | 126 | * Ensures parameters are parsed correctly from scripts, even in the presence |
89 | 127 | * of noise like e-mail addresses. |
|
0 commit comments