2009-08-24 04:21:15 +02:00
|
|
|
package xsbt
|
|
|
|
|
|
2010-01-16 01:05:23 +01:00
|
|
|
import sbt.{ComponentManager, TestIvyLogger}
|
|
|
|
|
|
2009-08-24 04:21:15 +02:00
|
|
|
import java.io.File
|
|
|
|
|
import FileUtilities.withTemporaryDirectory
|
|
|
|
|
import org.specs._
|
|
|
|
|
|
|
|
|
|
object CompileTest extends Specification
|
|
|
|
|
{
|
|
|
|
|
"Analysis compiler" should {
|
|
|
|
|
"compile basic sources" in {
|
2009-08-31 16:46:22 +02:00
|
|
|
WithCompiler( "2.7.2" )(testCompileAnalysis)
|
2009-09-06 22:05:31 +02:00
|
|
|
WithCompiler( "2.7.3" )(testCompileAnalysis)
|
|
|
|
|
WithCompiler( "2.7.4" )(testCompileAnalysis)
|
|
|
|
|
WithCompiler( "2.7.5" )(testCompileAnalysis)
|
2010-01-31 03:40:25 +01:00
|
|
|
WithCompiler( "2.7.7" )(testCompileAnalysis)
|
|
|
|
|
WithCompiler( "2.8.0.Beta1" )(testCompileAnalysis)
|
2009-09-06 22:05:31 +02:00
|
|
|
WithCompiler( "2.8.0-SNAPSHOT" )(testCompileAnalysis)
|
2009-08-24 04:21:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
2009-09-05 21:01:04 +02:00
|
|
|
private def testCompileAnalysis(compiler: AnalyzingCompiler, log: CompileLogger)
|
2009-08-24 04:21:15 +02:00
|
|
|
{
|
|
|
|
|
WithFiles( new File("Test.scala") -> "object Test" ) { sources =>
|
|
|
|
|
withTemporaryDirectory { temp =>
|
|
|
|
|
val callback = new xsbti.TestCallback(Array())
|
2009-09-05 18:19:34 +02:00
|
|
|
compiler(Set() ++ sources, Set.empty, temp, Nil, callback, 10, log)
|
2009-08-24 04:21:15 +02:00
|
|
|
(callback.beganSources) must haveTheSameElementsAs(sources)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-31 16:46:22 +02:00
|
|
|
}
|
|
|
|
|
object WithCompiler
|
|
|
|
|
{
|
2009-09-05 21:01:04 +02:00
|
|
|
def apply[T](scalaVersion: String)(f: (AnalyzingCompiler, CompileLogger) => T): T =
|
2009-08-31 16:46:22 +02:00
|
|
|
{
|
2009-09-05 18:19:34 +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-09-27 20:39:26 +02:00
|
|
|
boot.LaunchTest.withLauncher { launch =>
|
|
|
|
|
FileUtilities.withTemporaryDirectory { componentDirectory =>
|
2009-10-16 00:06:57 +02:00
|
|
|
val manager = new ComponentManager(xsbt.boot.Locks, new boot.ComponentProvider(componentDirectory), log)
|
2009-10-03 15:39:16 +02:00
|
|
|
val compiler = new AnalyzingCompiler(ScalaInstance(scalaVersion, launch), manager)
|
|
|
|
|
compiler.newComponentCompiler(log).clearCache(ComponentCompiler.compilerInterfaceID)
|
2009-09-27 20:39:26 +02:00
|
|
|
prepare(manager, ComponentCompiler.compilerInterfaceSrcID, "CompilerInterface.scala")
|
|
|
|
|
prepare(manager, ComponentCompiler.xsbtiID, classOf[xsbti.AnalysisCallback])
|
2009-10-03 15:39:16 +02:00
|
|
|
f(compiler, log)
|
2009-09-27 20:39:26 +02:00
|
|
|
}
|
2009-08-31 16:46:22 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-10-03 15:39:16 +02:00
|
|
|
def prepare(manager: ComponentManager, id: String, resource: Class[_]): Unit = define(manager, id, FileUtilities.classLocationFile(resource) :: Nil)
|
|
|
|
|
def prepare(manager: ComponentManager, id: String, resource: String)
|
2009-08-24 04:21:15 +02:00
|
|
|
{
|
|
|
|
|
val src = getClass.getClassLoader.getResource(resource)
|
|
|
|
|
if(src eq null)
|
|
|
|
|
error("Resource not found: " + resource)
|
2009-10-03 15:39:16 +02:00
|
|
|
define(manager, id, FileUtilities.asFile(src) :: Nil)
|
|
|
|
|
}
|
|
|
|
|
def define(manager: ComponentManager, id: String, files: List[File])
|
|
|
|
|
{
|
|
|
|
|
manager.clearCache(id)
|
|
|
|
|
manager.define(id, files)
|
2009-08-24 04:21:15 +02:00
|
|
|
}
|
|
|
|
|
}
|