sbt/compile/src/test/scala/CompileTest.scala

60 lines
2.2 KiB
Scala
Raw Normal View History

package xsbt
import java.io.File
import FileUtilities.withTemporaryDirectory
import org.specs._
// compile w/ analysis a bit hard to test properly right now:
// requires compile project to depend on +publish-local, which is not possible in sbt (addressed in xsbt, but that doesn't help here!)
object CompileTest extends Specification
{
"Analysis compiler" should {
"compile basic sources" in {
2009-08-31 16:46:22 +02:00
WithCompiler( "2.7.2" )(testCompileAnalysis)
}
}
private def testCompileAnalysis(compiler: AnalyzingCompiler, log: CompileLogger)
{
WithFiles( new File("Test.scala") -> "object Test" ) { sources =>
withTemporaryDirectory { temp =>
val callback = new xsbti.TestCallback(Array())
compiler(Set() ++ sources, Set.empty, temp, Nil, callback, 10, log)
(callback.beganSources) must haveTheSameElementsAs(sources)
}
}
}
2009-08-31 16:46:22 +02:00
}
object WithCompiler
{
def apply[T](scalaVersion: String)(f: (AnalyzingCompiler, CompileLogger) => T): T =
2009-08-31 16:46:22 +02:00
{
System.setProperty("scala.home", "") // need to make sure scala.home is unset
val log = new TestIvyLogger with CompileLogger
log.setLevel(Level.Debug)
log.bufferQuietly {
2009-08-31 16:46:22 +02:00
FileUtilities.withTemporaryDirectory { temp =>
val launch = new xsbt.boot.Launch(temp)
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(AnalyzingCompiler(scalaVersion, launch, manager), log)
2009-08-31 16:46:22 +02:00
}
}
}
private def prepare(manager: ComponentManager, id: String, resource: Class[_]): Unit =
{
val src = FileUtilities.classLocationFile(resource)
prepare(manager, id, src)
}
private def prepare(manager: ComponentManager, id: String, resource: String): Unit =
{
val src = getClass.getClassLoader.getResource(resource)
if(src eq null)
error("Resource not found: " + resource)
prepare(manager, id, FileUtilities.asFile(src))
}
import Paths._
private def prepare(manager: ComponentManager, id: String, file: File): Unit =
FileUtilities.copy(file x FileMapper.flat(manager.location(id)))
}