|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertThrows; |
5 | 5 |
|
6 | 6 | import fr.insee.vtl.engine.VtlScriptEngine; |
| 7 | +import fr.insee.vtl.engine.exceptions.UndefinedVariableException; |
7 | 8 | import fr.insee.vtl.engine.samples.DatasetSamples; |
8 | 9 | import fr.insee.vtl.model.Dataset; |
9 | 10 | import fr.insee.vtl.model.InMemoryDataset; |
|
15 | 16 | import java.util.*; |
16 | 17 | import java.util.stream.Stream; |
17 | 18 | import javax.script.ScriptContext; |
18 | | -import javax.script.ScriptEngine; |
19 | 19 | import javax.script.ScriptEngineManager; |
20 | 20 | import javax.script.ScriptException; |
21 | 21 | import org.junit.jupiter.api.BeforeEach; |
@@ -69,7 +69,7 @@ public class DagTest { |
69 | 69 | new Structured.Component("id2", Long.class, Dataset.Role.IDENTIFIER), |
70 | 70 | new Structured.Component("m2", Long.class, Dataset.Role.MEASURE))); |
71 | 71 |
|
72 | | - private ScriptEngine engine; |
| 72 | + private VtlScriptEngine engine; |
73 | 73 |
|
74 | 74 | public static Stream<Arguments> shuffledListSource() { |
75 | 75 | return permutations(List.of("b := a", "c := b", "d := c", "e := d + c")) |
@@ -153,21 +153,28 @@ private static Positioned.Position getPositionOfStatementInScript( |
153 | 153 |
|
154 | 154 | @BeforeEach |
155 | 155 | void setUp() { |
156 | | - engine = new ScriptEngineManager().getEngineByName("vtl"); |
157 | | - engine.put(VTL_ENGINE_USE_DAG, "true"); |
| 156 | + engine = (VtlScriptEngine) new ScriptEngineManager().getEngineByName("vtl"); |
158 | 157 | } |
159 | 158 |
|
160 | 159 | @Test |
161 | 160 | void testNoDagConfig() { |
162 | | - VtlScriptEngine vtlScriptEngine = (VtlScriptEngine) engine; |
163 | 161 | engine.put(VTL_ENGINE_USE_DAG, "false"); |
164 | | - assertThat(vtlScriptEngine.isUseDag()).isFalse(); |
| 162 | + assertThat(engine.isUseDag()).isFalse(); |
165 | 163 | } |
166 | 164 |
|
167 | 165 | @Test |
168 | 166 | void testUseDagConfig() { |
169 | | - VtlScriptEngine vtlScriptEngine = (VtlScriptEngine) engine; |
170 | | - assertThat(vtlScriptEngine.isUseDag()).isTrue(); |
| 167 | + assertThat(engine.isUseDag()).isTrue(); |
| 168 | + } |
| 169 | + |
| 170 | + @Test |
| 171 | + void testNoReorderingWhenDAGDeactivated() { |
| 172 | + engine.put(VTL_ENGINE_USE_DAG, "false"); |
| 173 | + ScriptContext context = engine.getContext(); |
| 174 | + context.setAttribute("a", 1L, ScriptContext.ENGINE_SCOPE); |
| 175 | + assertThatExceptionOfType(UndefinedVariableException.class) |
| 176 | + .isThrownBy(() -> engine.eval("b := a; d := c; c := b;")) |
| 177 | + .withMessage("undefined variable c"); |
171 | 178 | } |
172 | 179 |
|
173 | 180 | @Test |
|
0 commit comments