diff options
Diffstat (limited to 'libraries/eval')
-rw-r--r-- | libraries/eval/Eval.scala | 11 | ||||
-rw-r--r-- | libraries/eval/test/EvalTest.scala | 18 |
2 files changed, 28 insertions, 1 deletions
diff --git a/libraries/eval/Eval.scala b/libraries/eval/Eval.scala index 92329d3..abd1836 100644 --- a/libraries/eval/Eval.scala +++ b/libraries/eval/Eval.scala @@ -242,6 +242,7 @@ class Eval(target: Option[File]) { val id = uniqueId(sourceForString(code)) val className = "Evaluator__" + id val wrappedCode = wrapCodeInClass(className, code) + resetReporter() compile(wrappedCode) // may throw CompilerException } @@ -266,6 +267,10 @@ class Eval(target: Option[File]) { compiler.findClass(className).getOrElse { throw new ClassNotFoundException("no such class: " + className) } } + private[util] def resetReporter(): Unit = { + compiler.resetReporter() + } + private[util] def uniqueId(code: String, idOpt: Option[Int] = Some(jvmId)): String = { val digest = MessageDigest.getInstance("SHA-1").digest(code.getBytes()) val sha = new BigInteger(1, digest).toString(16) @@ -533,6 +538,12 @@ class Eval(target: Option[File]) { classLoader = new AbstractFileClassLoader(target, this.getClass.getClassLoader) } + def resetReporter(): Unit = { + synchronized { + reporter.reset() + } + } + object Debug { val enabled = System.getProperty("eval.debug") != null diff --git a/libraries/eval/test/EvalTest.scala b/libraries/eval/test/EvalTest.scala index 52913ab..8b986e2 100644 --- a/libraries/eval/test/EvalTest.scala +++ b/libraries/eval/test/EvalTest.scala @@ -205,7 +205,7 @@ class EvalTest extends WordSpec { assert(eval.errors.nonEmpty) } - "reset reporter between invocations" in { + "reset state between invocations" in { val ctx = new Ctx import ctx._ @@ -216,6 +216,22 @@ class EvalTest extends WordSpec { assert(eval[Int]("val d = 3; val e = 2; d + e", true) == 5) assert(eval.errors.isEmpty) } + + "reporter should be reset between checks, but loaded class should remain" in { + val ctx = new Ctx + import ctx._ + + // compile and load compiled class + eval.compile("class A()") + + intercept[Throwable] { + eval.check("new B()") + } + assert(eval.errors.nonEmpty) + + eval.check("new A()") + assert(eval.errors.isEmpty) + } } } } |