I have a strange behaviour concerning Testing Scala Script Engine.
I have the following code:
val manager = new ScriptEngineManager(getClass.getClassLoader)
val e = manager.getEngineByExtension("scala")
log.info(s"Script Engine: $e from: ${manager.getEngineFactories.asScala.map(f => s"names: ${f.getNames} - extensions: ${f.getExtensions}")}")
Running a test with Mill
or sbt
the Engine is null, even if there is an Engine for scala, as the log message shows:
Script Engine: null from: ArrayBuffer(Groovy Scripting Engine - extensions: [groovy], Scala REPL - extensions: [scala], juel - extensions: [juel])
Running the same test with Intellij
works.
Script Engine: scala.tools.nsc.interpreter.shell.Scripted@3d5dfb97 from: ArrayBuffer(juel - [juel], Groovy Scripting Engine - [groovy], Scala REPL - [scala], Oracle Nashorn - [js])
Update
After trying to get the Factory by Filtering, I get an Exception when getting the Script Engine (factory.getScriptEngine
):
javax.script.ScriptException: Failed to compile dynamicBindings
at scala.tools.nsc.interpreter.shell.Scripted.<init>(Scripted.scala:105)
at scala.tools.nsc.interpreter.shell.Scripted$.apply(Scripted.scala:278)
at scala.tools.nsc.interpreter.shell.Scripted$Factory.getScriptEngine(Scripted.scala:271)
at pme123.camundala.services.StandardApp$.$anonfun$layer$15(StandardApp.scala:43)
at zio.internal.FiberContext.evaluateNow(FiberContext.scala:458)
at zio.internal.FiberContext.$anonfun$evaluateLater$1(FiberContext.scala:687)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)