diff --git a/alchemist-loading/src/test/kotlin/it/unibo/alchemist/test/TestKtVariable.kt b/alchemist-loading/src/test/kotlin/it/unibo/alchemist/test/TestKtVariable.kt index d44752a1bf..6684ea07a5 100644 --- a/alchemist-loading/src/test/kotlin/it/unibo/alchemist/test/TestKtVariable.kt +++ b/alchemist-loading/src/test/kotlin/it/unibo/alchemist/test/TestKtVariable.kt @@ -77,4 +77,15 @@ class TestKtVariable> : assertNotNull(loader.getWith(emptyMap())) loader.variables["seed"] shouldNot beNull() } + + // This is a regression test, when using Alchemist variables inside a JSR223Variable scope, + // the simulation does not inherit the external variables into the JSR scope. + // Caused by: javax.script.ScriptException: ERROR Unresolved reference: *externalVariableName* + "simulation should load external variables inside function scope" { + val file = ResourceLoader.getResource("regression/testJSRVariable.yml") + assertNotNull(file) + val loader = LoadAlchemist.from(file) + assertNotNull(loader.getWith(emptyMap())) + loader.variables["simple"] shouldNot beNull() + } }) diff --git a/alchemist-loading/src/test/resources/regression/testJSRVariable.yml b/alchemist-loading/src/test/resources/regression/testJSRVariable.yml new file mode 100644 index 0000000000..dbb03c84b6 --- /dev/null +++ b/alchemist-loading/src/test/resources/regression/testJSRVariable.yml @@ -0,0 +1,14 @@ +incarnation: sapere + +_constants: + name: "test" + +variables: + number: 1 + other: + type: ArbitraryVariable + parameters: [ 1, [1, 2]] + simple: &simple + language: kotlin + formula: | + val couple: Pair = (number + other) to name