From 8f9e9c893893084129ea423ef7ff5d3e79074622 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Tue, 28 Oct 2014 19:12:29 +1000 Subject: SI-8941 Deterministic tests for pres. compiler idempotency A retrospective test case which covers typechecking idempotency which was introduced in 0b78a0196 / 148736c3df. It also tests the implicit class handling, which was fixed in the previous commit. It is difficult to test this using existing presentation compiler testing infrastructure, as one can't control at which point during the first typechecking the subesquent work item will be noticed. Instead, I've created a test with a custom subclass of `interactive.Global` that allows precise, deterministic control of when this happens. It overrides `signalDone`, which is called after each tree is typechecked, and watches for a defintion with a well known name. At that point, it triggers a targetted typecheck of the tree marked with a special comment. It is likely that this approach can be generalized to a reusable base class down the track. In particular, I expect that some of the nasty interactive ScalaDoc bugs could use this single-threaded approach to testing the presentation compiler. --- test/files/presentation/t8941b/Test.scala | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/files/presentation/t8941b/Test.scala (limited to 'test/files/presentation/t8941b/Test.scala') diff --git a/test/files/presentation/t8941b/Test.scala b/test/files/presentation/t8941b/Test.scala new file mode 100644 index 0000000000..7269a14286 --- /dev/null +++ b/test/files/presentation/t8941b/Test.scala @@ -0,0 +1,53 @@ +import scala.tools.nsc.interactive.tests.core.IdempotencyTest + +// At the time of writing this test, removing any part of `enterExistingSym` +// leads to a failure. +object Test { + def main(args: Array[String]) { + test(""" + object Foo { + def term { + def foo(c: String = "") = c + class MagicInterruptionMarker + foo()/*?*/ + } + } + """) + + test(""" + object Foo { + def term { + def foo = 42 + class MagicInterruptionMarker + foo/*?*/ + } + } + """) + + test(""" + object Foo { + def term { + lazy val foo = 42 + class MagicInterruptionMarker + foo/*?*/ + } + } + """) + + test(""" + object Foo { + implicit class C(val a: String) extends AnyVal + class MagicInterruptionMarker + ""/*?*/ + } + """) + } + + def test(code0: String) { + val t = new IdempotencyTest { + def code = code0 + } + t.show() + } +} + -- cgit v1.2.3