From edca6620e42c539df271cf5c1224a00e5bc3018c Mon Sep 17 00:00:00 2001 From: Mark Harrah Date: Mon, 31 Aug 2009 10:46:22 -0400 Subject: [PATCH] factor out context for compile test --- compile/src/test/scala/CompileTest.scala | 28 +++++++++++++++--------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/compile/src/test/scala/CompileTest.scala b/compile/src/test/scala/CompileTest.scala index 2ee207873..74e3793f8 100644 --- a/compile/src/test/scala/CompileTest.scala +++ b/compile/src/test/scala/CompileTest.scala @@ -10,16 +10,7 @@ object CompileTest extends Specification { "Analysis compiler" should { "compile basic sources" in { - TestIvyLogger { log => - LoadHelpers.withLaunch { launch => - val scalaVersion = "2.7.2" - val sbtVersion = xsbti.Versions.Sbt - val manager = new ComponentManager(launch.getSbtHome(sbtVersion, scalaVersion), log) - prepare(manager, ComponentCompiler.compilerInterfaceSrcID, "CompilerInterface.scala") - prepare(manager, ComponentCompiler.xsbtiID, classOf[xsbti.AnalysisCallback]) - testCompileAnalysis(new AnalyzeCompiler(scalaVersion, launch, manager), log) - } - } + WithCompiler( "2.7.2" )(testCompileAnalysis) } } private def testCompileAnalysis(compiler: AnalyzeCompiler, log: xsbti.Logger) @@ -33,6 +24,23 @@ object CompileTest extends Specification } } } +} +object WithCompiler +{ + def apply[T](scalaVersion: String)(f: (AnalyzeCompiler, xsbti.Logger) => T): T = + { + TestIvyLogger { log => + FileUtilities.withTemporaryDirectory { temp => + val launch = new xsbt.boot.Launch(temp) + val scalaVersion = "2.7.2" + val sbtVersion = xsbti.Versions.Sbt + val manager = new ComponentManager(launch.getSbtHome(sbtVersion, scalaVersion), log) + prepare(manager, ComponentCompiler.compilerInterfaceSrcID, "CompilerInterface.scala") + prepare(manager, ComponentCompiler.xsbtiID, classOf[xsbti.AnalysisCallback]) + f(new AnalyzeCompiler(scalaVersion, launch, manager), log) + } + } + } private def prepare(manager: ComponentManager, id: String, resource: Class[_]): Unit = { val src = FileUtilities.classLocationFile(resource)