2009-08-24 04:21:15 +02:00
|
|
|
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 {
|
|
|
|
|
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])
|
2009-08-30 17:10:37 +02:00
|
|
|
testCompileAnalysis(new AnalyzeCompiler(scalaVersion, launch, manager), log)
|
2009-08-24 04:21:15 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-30 17:10:37 +02:00
|
|
|
private def testCompileAnalysis(compiler: AnalyzeCompiler, log: xsbti.Logger)
|
2009-08-24 04:21:15 +02:00
|
|
|
{
|
|
|
|
|
WithFiles( new File("Test.scala") -> "object Test" ) { sources =>
|
|
|
|
|
withTemporaryDirectory { temp =>
|
|
|
|
|
val arguments = "-d" :: temp.getAbsolutePath :: sources.map(_.getAbsolutePath).toList
|
|
|
|
|
val callback = new xsbti.TestCallback(Array())
|
|
|
|
|
compiler(arguments, callback, 10, log)
|
|
|
|
|
(callback.beganSources) must haveTheSameElementsAs(sources)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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))
|
|
|
|
|
}
|
2009-08-29 16:19:00 +02:00
|
|
|
import Paths._
|
2009-08-24 04:21:15 +02:00
|
|
|
private def prepare(manager: ComponentManager, id: String, file: File): Unit =
|
2009-08-29 16:19:00 +02:00
|
|
|
FileUtilities.copy(file x FileMapper.flat(manager.location(id)))
|
2009-08-24 04:21:15 +02:00
|
|
|
}
|