Merge branch 'master' of github.com:harrah/xsbt

This commit is contained in:
Mark Harrah 2010-04-24 23:21:13 -04:00
commit dac3714558
8 changed files with 64 additions and 20 deletions

View File

@ -299,7 +299,7 @@ abstract class BasicScalaProject extends ScalaProject with BasicDependencyProjec
protected def packageProjectAction = zipTask(packageProjectPaths, packageProjectZip) describedAs ProjectPackageDescription
protected def docAllAction = (doc && docTest) describedAs DocAllDescription
protected def packageAllAction = task { None } dependsOn(`package`, packageTest, packageSrc, packageTestSrc, packageDocs) describedAs PackageAllDescription
protected def packageAllAction = Empty dependsOn(`package`, packageTest, packageSrc, packageTestSrc, packageDocs) describedAs PackageAllDescription
protected def graphSourcesAction = graphSourcesTask(graphSourcesPath, mainSourceRoots, mainCompileConditional.analysis).dependsOn(compile)
protected def graphPackagesAction = graphPackagesTask(graphPackagesPath, mainSourceRoots, mainCompileConditional.analysis).dependsOn(compile)
protected def incrementVersionAction = task { incrementVersionNumber(); None } describedAs IncrementVersionDescription

View File

@ -167,16 +167,20 @@ trait ScalaProject extends SimpleScalaProject with FileTasks with MultiTaskProje
testTask(frameworks, classpath, analysis, options)
def testTask(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, options: => Seq[TestOption]): Task =
{
def work =
def rawWork =
{
val (begin, work, end) = testTasks(frameworks, classpath, analysis, options)
val beginTasks = begin.map(toTask).toSeq // test setup tasks
val workTasks = work.map(w => toTask(w) dependsOn(beginTasks : _*)) // the actual tests
val endTasks = end.map(toTask).toSeq // tasks that perform test cleanup and are run regardless of success of tests
val endTask = task { None } named("test-cleanup") dependsOn(endTasks : _*)
val rootTask = task { None } named("test-complete") dependsOn(workTasks.toSeq : _*) // the task that depends on all test subtasks
val endTask = Empty named("test-cleanup") dependsOn(endTasks : _*)
val rootTask = Empty named("test-complete") dependsOn(workTasks.toSeq : _*) // the task that depends on all test subtasks
SubWork[Project#Task](rootTask, endTask)
}
def errorTask(e: TestSetupException) = task { Some(e.getMessage) } named("test-setup")
def work =
try { rawWork }
catch { case e: TestSetupException => SubWork[Project#Task](errorTask(e)) }
new CompoundTask(work)
}
private def toTask(testTask: NamedTestTask) = task(testTask.run()) named(testTask.name)
@ -381,6 +385,7 @@ object ScalaProject
def optionsAsString(options: Seq[ScalaProject#CompileOption]) = options.map(_.asString).filter(!_.isEmpty)
def javaOptionsAsString(options: Seq[ScalaProject#JavaCompileOption]) = options.map(_.asString)
}
final class TestSetupException(msg: String) extends RuntimeException(msg)
trait MultiTaskProject extends Project
{
def multiTask(allTests: => List[String])(run: (Seq[String], String => Boolean) => Task): MethodTask = {
@ -392,17 +397,24 @@ trait MultiTaskProject extends Project
def filterInclude =
{
val (exactFilters, testFilters) = testNames.toList.map(GlobFilter.apply).partition(_.isInstanceOf[ExactFilter])
val includeTests = exactFilters.map(_.asInstanceOf[ExactFilter].matchName)
val toCheck = scala.collection.mutable.HashSet(includeTests: _*)
toCheck --= allTests
if(!toCheck.isEmpty && log.atLevel(Level.Warn))
lazy val (exactFilters, testFilters) = testNames.toList.map(GlobFilter.apply).partition(_.isInstanceOf[ExactFilter])
lazy val includeTests = exactFilters.map(_.asInstanceOf[ExactFilter].matchName)
def checkExistence() =
{
log.warn("Test(s) not found:")
toCheck.foreach(test => log.warn("\t" + test))
val toCheck = Set() ++ includeTests -- allTests
if(!toCheck.isEmpty)
{
log.error("Test(s) not found:")
toCheck.foreach(test => log.error("\t" + test))
throw new TestSetupException("Invalid test name(s): " + toCheck.mkString(", "))
}
}
lazy val includeTestsSet =
{
checkExistence()
Set(includeTests: _*)
}
val includeTestsSet = Set(includeTests: _*)
(test: String) => includeTestsSet.contains(test) || testFilters.exists(_.accept(test))
}

View File

@ -98,6 +98,7 @@ trait TaskManager{
val interactiveDependencyIndex = dependencyList.findIndexOf(_.interactive)
require(interactiveDependencyIndex < 0, "Dependency (at index " + interactiveDependencyIndex + ") is interactive. Interactive tasks cannot be dependencies.")
}
lazy val Empty = task { None}
}
object TaskManager
{

View File

@ -100,7 +100,7 @@ object TestFramework
case _ => error("Could not call 'tests' on framework " + framework)
}
private val ScalaCompilerJarPackages = "scala.tools.nsc." :: "jline." :: "ch.epfl.lamp." :: Nil
private val ScalaCompilerJarPackages = "scala.tools." :: "jline." :: "ch.epfl.lamp." :: Nil
private val TestStartName = "test-start"
private val TestFinishName = "test-finish"

View File

@ -0,0 +1,8 @@
import sbt._
class P(info: ProjectInfo) extends DefaultProject(info)
{
val bryanjswift = "Bryan J Swift Repository" at "http://repos.bryanjswift.com/maven2/"
val junitInterface = "com.novocode" % "junit-interface" % "0.4.0" % "test"
val junit = "junit" % "junit" % "4.7" % "test"
}

View File

@ -1,18 +1,21 @@
package foo.bar
import java.io.File
import File.{pathSeparator => / }
import java.net.{URISyntaxException, URL}
class Holder { var value: Any = _ }
import scala.tools.nsc.{Interpreter, Settings}
import scala.tools.nsc.{GenericRunnerSettings, Interpreter, Settings}
class Foo {
val g = new GenericRunnerSettings(System.err.println)
val settings = new Settings()
settings.classpath.value = location(classOf[Holder])
settings.bootclasspath.value = settings.bootclasspath.value + File.pathSeparator + location(classOf[ScalaObject])
val inter = new Interpreter(settings)
settings.bootclasspath.value = settings.bootclasspath.value + / + location(classOf[ScalaObject]) + / + location(classOf[Settings])
val inter = new Interpreter(settings) {
override protected def parentClassLoader = Foo.this.getClass.getClassLoader
}
def eval(code: String): Any = {
val h = new Holder
inter.bind("$r_", h.getClass.getName, h)
@ -32,4 +35,4 @@ object Test
val foo = new Foo
args.foreach { arg => foo.eval(arg) == arg.toInt }
}
}
}

View File

@ -0,0 +1,15 @@
package foo.bar
import org.junit._
import org.junit.Assert._
class Basic
{
val foo = new Foo
@Test
def checkBind(): Unit =
{
try { assertTrue( foo.eval("3") == 3) }
catch { case e => e.printStackTrace; throw e}
}
}

View File

@ -1,8 +1,13 @@
> set build.scala.versions 2.7.7 2.8.0.RC1
> reload
> +update
> +run 1
> +test
> +clean
> +run 2
> +test
> +clean
> +run -1
> +clean
> +test