2010-10-06 14:24:13 +02:00
|
|
|
package sbt
|
2011-03-02 12:46:28 +01:00
|
|
|
package compiler
|
2009-08-24 04:21:15 +02:00
|
|
|
|
2010-10-06 14:24:13 +02:00
|
|
|
import java.io.File
|
|
|
|
|
import IO.withTemporaryDirectory
|
|
|
|
|
import org.specs._
|
2009-08-24 04:21:15 +02:00
|
|
|
|
|
|
|
|
object CompileTest extends Specification
|
|
|
|
|
{
|
2010-03-29 02:20:17 +02:00
|
|
|
"Analysis compiler" should {
|
2009-08-24 04:21:15 +02:00
|
|
|
"compile basic sources" in {
|
2011-09-01 02:58:09 +02:00
|
|
|
WithCompiler( "2.9.1" )(testCompileAnalysis)
|
|
|
|
|
WithCompiler( "2.9.0-1" )(testCompileAnalysis)
|
2010-10-06 14:24:13 +02:00
|
|
|
WithCompiler( "2.8.0" )(testCompileAnalysis)
|
2011-02-26 00:35:52 +01:00
|
|
|
WithCompiler( "2.8.1" )(testCompileAnalysis)
|
2009-08-24 04:21:15 +02:00
|
|
|
}
|
2010-03-29 02:20:17 +02:00
|
|
|
}
|
2011-02-26 00:35:52 +01:00
|
|
|
|
2010-03-23 01:42:59 +01:00
|
|
|
"Raw compiler" should {
|
|
|
|
|
"Properly handle classpaths" in {
|
2011-09-01 02:58:09 +02:00
|
|
|
testClasspath("2.9.1")
|
|
|
|
|
testClasspath("2.9.0-1")
|
2011-02-26 00:35:52 +01:00
|
|
|
testClasspath("2.8.1")
|
2011-09-01 02:58:09 +02:00
|
|
|
testClasspath("2.8.0")
|
2010-03-23 01:42:59 +01:00
|
|
|
}
|
2009-08-24 04:21:15 +02:00
|
|
|
}
|
2010-03-23 01:42:59 +01:00
|
|
|
|
2010-10-06 14:24:13 +02:00
|
|
|
private def testCompileAnalysis(compiler: AnalyzingCompiler, log: Logger)
|
2009-08-24 04:21:15 +02:00
|
|
|
{
|
|
|
|
|
WithFiles( new File("Test.scala") -> "object Test" ) { sources =>
|
|
|
|
|
withTemporaryDirectory { temp =>
|
2010-10-06 14:24:13 +02:00
|
|
|
val callback = new xsbti.TestCallback
|
|
|
|
|
compiler(sources, Nil, temp, Nil, callback, 10, log)
|
2009-08-24 04:21:15 +02:00
|
|
|
(callback.beganSources) must haveTheSameElementsAs(sources)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-03-23 01:42:59 +01:00
|
|
|
|
|
|
|
|
val UsingCompiler = "object Test { classOf[scala.tools.nsc.Global] }"
|
|
|
|
|
|
|
|
|
|
private def shouldFail(act: => Unit) =
|
|
|
|
|
{
|
2011-02-26 00:35:52 +01:00
|
|
|
val success = try { act; true } catch { case t if expectedException(t) => false }
|
2010-03-23 01:42:59 +01:00
|
|
|
if(success) error("Expected exception not thrown")
|
|
|
|
|
}
|
2011-02-26 00:35:52 +01:00
|
|
|
private def expectedException(t: Throwable) =
|
|
|
|
|
t match
|
|
|
|
|
{
|
|
|
|
|
case e: Exception => true
|
|
|
|
|
case t if isMissingRequirementError(t) => true
|
|
|
|
|
case _ => false
|
|
|
|
|
}
|
2011-04-09 01:19:08 +02:00
|
|
|
private def shouldSucceed(act: => Unit) =
|
|
|
|
|
try { act } catch { case c: xsbti.CompileFailed => error(c.toString) }
|
|
|
|
|
|
2010-03-23 01:42:59 +01:00
|
|
|
private def isMissingRequirementError(t: Throwable) = t.getClass.getName == "scala.tools.nsc.MissingRequirementError"
|
|
|
|
|
private def testClasspath(scalaVersion: String) =
|
|
|
|
|
WithCompiler.launcher { (launch, log) =>
|
2011-03-23 12:06:51 +01:00
|
|
|
def compiler(bootLibrary: Boolean, compilerOnClasspath: Boolean): RawCompiler =
|
2011-06-10 13:48:53 +02:00
|
|
|
new RawCompiler(ScalaInstance(scalaVersion, launch), new ClasspathOptions(bootLibrary, compilerOnClasspath, true, true, bootLibrary), log)
|
2010-03-23 01:42:59 +01:00
|
|
|
|
2010-10-06 14:24:13 +02:00
|
|
|
val callback = new xsbti.TestCallback
|
2010-03-23 01:42:59 +01:00
|
|
|
|
|
|
|
|
val standard = compiler(true, true)
|
|
|
|
|
val noCompiler = compiler(true, false)
|
|
|
|
|
val fullExplicit = compiler(false, false)
|
|
|
|
|
|
|
|
|
|
val fullBoot = "-bootclasspath" :: fullExplicit.compilerArguments.createBootClasspath :: Nil
|
2010-10-06 14:24:13 +02:00
|
|
|
val withCompiler = noCompiler.scalaInstance.compilerJar :: Nil
|
2011-04-09 01:19:08 +02:00
|
|
|
val withLibrary = noCompiler.scalaInstance.libraryJar :: Nil
|
|
|
|
|
val withLibraryCompiler = withLibrary ++ withCompiler
|
2010-03-23 01:42:59 +01:00
|
|
|
|
2010-10-06 14:24:13 +02:00
|
|
|
WithFiles( new File("Test.scala") -> "object Test", new File("Test2.scala") -> UsingCompiler ) { case Seq(plain, useCompiler) =>
|
|
|
|
|
val plainSrcs = Seq[File](plain)
|
|
|
|
|
val compSrcs = Seq[File](useCompiler)
|
|
|
|
|
withTemporaryDirectory { out =>
|
2011-06-10 13:48:53 +02:00
|
|
|
shouldSucceed( standard(plainSrcs, Nil, out, Nil) )
|
|
|
|
|
shouldSucceed( standard(compSrcs, Nil, out, Nil) )
|
2010-03-23 01:42:59 +01:00
|
|
|
|
2011-06-10 13:48:53 +02:00
|
|
|
shouldSucceed( noCompiler(plainSrcs, Nil, out, Nil) )
|
2010-10-06 14:24:13 +02:00
|
|
|
shouldFail( noCompiler(compSrcs, Nil, out, Nil) )
|
2011-06-10 13:48:53 +02:00
|
|
|
shouldSucceed( noCompiler(compSrcs, withCompiler, out, Nil) )
|
2010-03-23 01:42:59 +01:00
|
|
|
|
2011-06-10 13:48:53 +02:00
|
|
|
shouldFail( fullExplicit(plainSrcs, Nil, out, Nil) )
|
|
|
|
|
shouldFail( fullExplicit(compSrcs, Nil, out, Nil) )
|
|
|
|
|
shouldSucceed( fullExplicit(plainSrcs, withLibrary, out, fullBoot) )
|
|
|
|
|
shouldSucceed( fullExplicit(compSrcs, withLibraryCompiler, out, fullBoot) )
|
2011-04-09 01:19:08 +02:00
|
|
|
true must beTrue
|
2010-03-23 01:42:59 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-08-31 16:46:22 +02:00
|
|
|
}
|