Skip to content

Commit 4830bdc

Browse files
committed
test: add regression test for jsr variable failing when using external variables
1 parent 882b80d commit 4830bdc

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

alchemist-loading/src/test/kotlin/it/unibo/alchemist/test/TestKtVariable.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,17 @@ class TestKtVariable<T, P : Position<P>> :
7777
assertNotNull(loader.getWith<T, P>(emptyMap<String, String>()))
7878
loader.variables["seed"] shouldNot beNull()
7979
}
80+
81+
// This is a regression test, when using Alchemist variables inside a JSR223Variable scope,
82+
// the simulation does not inherit the external variables into the JSR scope.
83+
// Caused by: javax.script.ScriptException: ERROR Unresolved reference: *externalVariableName*
84+
"simulation should load external variables inside function scope" {
85+
val file = ResourceLoader.getResource("regression/testJSRVariable.yml")
86+
assertNotNull(file)
87+
val loader = LoadAlchemist.from(file)
88+
assertNotNull(loader.getWith<T, P>(emptyMap<String, String>()))
89+
loader.variables["simple"] shouldNot beNull()
90+
}
8091
})
92+
93+
data class SimpleDataClass(val number: Int, val name: String)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
incarnation: sapere
2+
3+
variables:
4+
number: 1
5+
name: "peppe"
6+
simple: &simple
7+
language: kotlin
8+
formula: |
9+
import it.unibo.alchemist.test.SimpleDataClass
10+
val simpleDataClass = SimpleDataClass(number, name)

0 commit comments

Comments
 (0)