From eac1af364e99a6712c5e54e257216027b2ab127e Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 16 May 2016 16:04:17 +1000 Subject: Reduce boilerplate in compiler JUnit tests (#5158) Many JUnit tests share a compiler instance between all test cases in a class to reduce overhead. This commit refactors the mechanism to reduce the boilerplate. In the new scheme: - Using the `@ClassRule` hook in JUnit, we create a per-class map for each test class. - Per-class values are registered from the test class itself by calling `cached("someKey", () => mkExpensiveThing)` - At the end of the test, the entries in this map are `close()`-ed (if they implement `Closable`), and are released for garbage collection.) --- .../tools/nsc/backend/jvm/opt/UnusedLocalVariablesTest.scala | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'test/junit/scala/tools/nsc/backend/jvm/opt/UnusedLocalVariablesTest.scala') diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/UnusedLocalVariablesTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/UnusedLocalVariablesTest.scala index 4f71df1822..77e73e64b9 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/UnusedLocalVariablesTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/UnusedLocalVariablesTest.scala @@ -14,16 +14,9 @@ import scala.tools.partest.ASMConverters import ASMConverters._ import scala.tools.testing.ClearAfterClass -object UnusedLocalVariablesTest extends ClearAfterClass.Clearable { - var dceCompiler = newCompiler(extraArgs = "-Yopt:unreachable-code") - def clear(): Unit = { dceCompiler = null } -} - @RunWith(classOf[JUnit4]) class UnusedLocalVariablesTest extends ClearAfterClass { - ClearAfterClass.stateToClear = UnusedLocalVariablesTest - - val dceCompiler = UnusedLocalVariablesTest.dceCompiler + val dceCompiler = cached("dceCompiler", () => newCompiler(extraArgs = "-Yopt:unreachable-code")) @Test def removeUnusedVar(): Unit = { -- cgit v1.2.3