factor out context for compile test

This commit is contained in:
Mark Harrah 2009-08-31 10:46:22 -04:00
parent b9c227ecb6
commit edca6620e4
1 changed files with 18 additions and 10 deletions

View File

@ -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)