mirror of https://github.com/sbt/sbt.git
Josh's patch for passing arguments to test-* tasks.
This commit is contained in:
parent
04e50bd218
commit
3fcdca4ef7
|
|
@ -1,5 +1,5 @@
|
||||||
/* sbt -- Simple Build Tool
|
/* sbt -- Simple Build Tool
|
||||||
* Copyright 2008, 2009 Mark Harrah, David MacIver
|
* Copyright 2008, 2009 Mark Harrah, David MacIver, Josh Cough
|
||||||
*/
|
*/
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
|
|
@ -255,15 +255,17 @@ abstract class BasicScalaProject extends ScalaProject with BasicDependencyProjec
|
||||||
protected def consoleAction = basicConsoleTask.dependsOn(testCompile, copyResources, copyTestResources) describedAs ConsoleDescription
|
protected def consoleAction = basicConsoleTask.dependsOn(testCompile, copyResources, copyTestResources) describedAs ConsoleDescription
|
||||||
protected def docAction = scaladocTask(mainLabel, mainSources, mainDocPath, docClasspath, documentOptions).dependsOn(compile) describedAs DocDescription
|
protected def docAction = scaladocTask(mainLabel, mainSources, mainDocPath, docClasspath, documentOptions).dependsOn(compile) describedAs DocDescription
|
||||||
protected def docTestAction = scaladocTask(testLabel, testSources, testDocPath, docClasspath, documentOptions).dependsOn(testCompile) describedAs TestDocDescription
|
protected def docTestAction = scaladocTask(testLabel, testSources, testDocPath, docClasspath, documentOptions).dependsOn(testCompile) describedAs TestDocDescription
|
||||||
protected def testAction = defaultTestTask(testOptions)
|
|
||||||
protected def testOnlyAction = testQuickMethod(testCompileConditional.analysis, testOptions)(options =>
|
protected def testAction = defaultTestTask(Nil, testOptions)
|
||||||
defaultTestTask(options)) describedAs(TestOnlyDescription)
|
protected def testOnlyAction = testQuickMethod(testCompileConditional.analysis, testOptions)((testArgs, options) => {
|
||||||
protected def testQuickAction = defaultTestQuickMethod(false) describedAs(TestQuickDescription)
|
defaultTestTask(testArgs, options)
|
||||||
protected def testFailedAction = defaultTestQuickMethod(true) describedAs(TestFailedDescription)
|
}) describedAs(TestOnlyDescription)
|
||||||
protected def defaultTestQuickMethod(failedOnly: Boolean) =
|
protected def testQuickAction = defaultTestQuickMethod(false) describedAs(TestQuickDescription)
|
||||||
testQuickMethod(testCompileConditional.analysis, testOptions)(options => defaultTestTask(quickOptions(failedOnly) ::: options.toList))
|
protected def testFailedAction = defaultTestQuickMethod(true) describedAs(TestFailedDescription)
|
||||||
protected def defaultTestTask(testOptions: => Seq[TestOption]) =
|
protected def defaultTestQuickMethod(failedOnly: Boolean) =
|
||||||
testTask(testFrameworks, testClasspath, testCompileConditional.analysis, testOptions).dependsOn(testCompile, copyResources, copyTestResources) describedAs TestDescription
|
testQuickMethod(testCompileConditional.analysis, testOptions)((args, options) => defaultTestTask(args, quickOptions(failedOnly) ::: options.toList))
|
||||||
|
protected def defaultTestTask(testArgs: Seq[String], testOptions: => Seq[TestOption]) =
|
||||||
|
testTask(testFrameworks, testClasspath, testCompileConditional.analysis, testArgs, testOptions).dependsOn(testCompile, copyResources, copyTestResources) describedAs TestDescription
|
||||||
|
|
||||||
override def packageToPublishActions: Seq[ManagedTask] = `package` :: Nil
|
override def packageToPublishActions: Seq[ManagedTask] = `package` :: Nil
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/* sbt -- Simple Build Tool
|
/* sbt -- Simple Build Tool
|
||||||
* Copyright 2009 Steven Blundy, Mark Harrah
|
* Copyright 2009 Steven Blundy, Mark Harrah, Josh Cough
|
||||||
*/
|
*/
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
|
|
@ -15,8 +15,8 @@ trait IntegrationTesting extends NotNull
|
||||||
trait ScalaIntegrationTesting extends IntegrationTesting
|
trait ScalaIntegrationTesting extends IntegrationTesting
|
||||||
{ self: ScalaProject =>
|
{ self: ScalaProject =>
|
||||||
|
|
||||||
protected def integrationTestTask(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, options: => Seq[TestOption]) =
|
protected def integrationTestTask(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, testArgs: Seq[String], options: => Seq[TestOption]) =
|
||||||
testTask(frameworks, classpath, analysis, options)
|
testTask(frameworks, classpath, analysis, testArgs, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
trait BasicScalaIntegrationTesting extends BasicIntegrationTesting with MavenStyleIntegrationTestPaths
|
trait BasicScalaIntegrationTesting extends BasicIntegrationTesting with MavenStyleIntegrationTestPaths
|
||||||
|
|
@ -34,7 +34,7 @@ trait BasicIntegrationTesting extends ScalaIntegrationTesting with IntegrationTe
|
||||||
|
|
||||||
val integrationTestCompileConditional = new CompileConditional(integrationTestCompileConfiguration, buildCompiler)
|
val integrationTestCompileConditional = new CompileConditional(integrationTestCompileConfiguration, buildCompiler)
|
||||||
|
|
||||||
protected def integrationTestAction = integrationTestTask(integrationTestFrameworks, integrationTestClasspath, integrationTestCompileConditional.analysis, integrationTestOptions) dependsOn integrationTestCompile describedAs IntegrationTestCompileDescription
|
protected def integrationTestAction = integrationTestTask(integrationTestFrameworks, integrationTestClasspath, integrationTestCompileConditional.analysis, Nil, integrationTestOptions) dependsOn integrationTestCompile describedAs IntegrationTestCompileDescription
|
||||||
protected def integrationTestCompileAction = integrationTestCompileTask() dependsOn compile describedAs IntegrationTestDescription
|
protected def integrationTestCompileAction = integrationTestCompileTask() dependsOn compile describedAs IntegrationTestDescription
|
||||||
|
|
||||||
protected def integrationTestCompileTask() = task{ integrationTestCompileConditional.run }
|
protected def integrationTestCompileTask() = task{ integrationTestCompileConditional.run }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/* sbt -- Simple Build Tool
|
/* sbt -- Simple Build Tool
|
||||||
* Copyright 2008, 2009 Mark Harrah, David MacIver
|
* Copyright 2008, 2009 Mark Harrah, David MacIver, Josh Cough
|
||||||
*/
|
*/
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
|
|
@ -67,6 +67,7 @@ trait ScalaProject extends SimpleScalaProject with FileTasks with MultiTaskProje
|
||||||
case class ExcludeTests(tests: Iterable[String]) extends TestOption
|
case class ExcludeTests(tests: Iterable[String]) extends TestOption
|
||||||
case class TestListeners(listeners: Iterable[TestReportListener]) extends TestOption
|
case class TestListeners(listeners: Iterable[TestReportListener]) extends TestOption
|
||||||
case class TestFilter(filterTest: String => Boolean) extends TestOption
|
case class TestFilter(filterTest: String => Boolean) extends TestOption
|
||||||
|
case class TestFrameworkArgument(arg: String) extends TestOption
|
||||||
|
|
||||||
case class JarManifest(m: Manifest) extends PackageOption
|
case class JarManifest(m: Manifest) extends PackageOption
|
||||||
{
|
{
|
||||||
|
|
@ -149,13 +150,14 @@ trait ScalaProject extends SimpleScalaProject with FileTasks with MultiTaskProje
|
||||||
def copyTask(sources: PathFinder, destinationDirectory: Path): Task =
|
def copyTask(sources: PathFinder, destinationDirectory: Path): Task =
|
||||||
task { FileUtilities.copy(sources.get, destinationDirectory, log).left.toOption }
|
task { FileUtilities.copy(sources.get, destinationDirectory, log).left.toOption }
|
||||||
|
|
||||||
def testTask(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, options: TestOption*): Task =
|
def testTask(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, testArgs: Seq[String], options: TestOption*): Task =
|
||||||
testTask(frameworks, classpath, analysis, options)
|
testTask(frameworks, classpath, analysis, testArgs, options)
|
||||||
def testTask(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, options: => Seq[TestOption]): Task =
|
def testTask(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis,
|
||||||
|
testArgs: Seq[String], options: => Seq[TestOption]): Task =
|
||||||
{
|
{
|
||||||
def work =
|
def work =
|
||||||
{
|
{
|
||||||
val (begin, work, end) = testTasks(frameworks, classpath, analysis, options)
|
val (begin, work, end) = testTasks(frameworks, classpath, analysis, testArgs, options)
|
||||||
val beginTasks = begin.map(toTask).toSeq // test setup tasks
|
val beginTasks = begin.map(toTask).toSeq // test setup tasks
|
||||||
val workTasks = work.map(w => toTask(w) dependsOn(beginTasks : _*)) // the actual tests
|
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 endTasks = end.map(toTask).toSeq // tasks that perform test cleanup and are run regardless of success of tests
|
||||||
|
|
@ -249,7 +251,8 @@ trait ScalaProject extends SimpleScalaProject with FileTasks with MultiTaskProje
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
protected def incrementImpl(v: BasicVersion): Version = v.incrementMicro
|
protected def incrementImpl(v: BasicVersion): Version = v.incrementMicro
|
||||||
protected def testTasks(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, options: => Seq[TestOption]) = {
|
protected def testTasks(frameworks: Seq[TestFramework], classpath: PathFinder, analysis: CompileAnalysis, testArgs: Seq[String],
|
||||||
|
options: => Seq[TestOption]) = {
|
||||||
import scala.collection.mutable.HashSet
|
import scala.collection.mutable.HashSet
|
||||||
|
|
||||||
val testFilters = new ListBuffer[String => Boolean]
|
val testFilters = new ListBuffer[String => Boolean]
|
||||||
|
|
@ -276,18 +279,22 @@ trait ScalaProject extends SimpleScalaProject with FileTasks with MultiTaskProje
|
||||||
}
|
}
|
||||||
def includeTest(test: TestDefinition) = !excludeTestsSet.contains(test.testClassName) && testFilters.forall(filter => filter(test.testClassName))
|
def includeTest(test: TestDefinition) = !excludeTestsSet.contains(test.testClassName) && testFilters.forall(filter => filter(test.testClassName))
|
||||||
val tests = HashSet.empty[TestDefinition] ++ analysis.allTests.filter(includeTest)
|
val tests = HashSet.empty[TestDefinition] ++ analysis.allTests.filter(includeTest)
|
||||||
TestFramework.testTasks(frameworks, classpath.get, buildScalaInstance.loader, tests.toSeq, log, testListeners.readOnly, false, setup.readOnly, cleanup.readOnly)
|
TestFramework.testTasks(frameworks, classpath.get, buildScalaInstance.loader, tests.toSeq, log, testListeners.readOnly, false, setup.readOnly, cleanup.readOnly, testArgs)
|
||||||
}
|
}
|
||||||
private def flatten[T](i: Iterable[Iterable[T]]) = i.flatMap(x => x)
|
private def flatten[T](i: Iterable[Iterable[T]]) = i.flatMap(x => x)
|
||||||
|
|
||||||
protected def testQuickMethod(testAnalysis: CompileAnalysis, options: => Seq[TestOption])(toRun: Seq[TestOption] => Task) =
|
protected def testQuickMethod(testAnalysis: CompileAnalysis, options: => Seq[TestOption])(toRun: (Seq[String],Seq[TestOption]) => Task) = {
|
||||||
multiTask(testAnalysis.allTests.map(_.testClassName).toList) { includeFunction =>
|
val analysis = testAnalysis.allTests.map(_.testClassName).toList
|
||||||
toRun(TestFilter(includeFunction) :: options.toList)
|
multiTask(analysis) { (args,includeFunction) => {
|
||||||
|
toRun(args, TestFilter(includeFunction) :: options.toList)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected final def maximumErrors[T <: ActionOption](options: Seq[T]) =
|
protected final def maximumErrors[T <: ActionOption](options: Seq[T]) =
|
||||||
(for( MaxCompileErrors(maxErrors) <- options) yield maxErrors).firstOption.getOrElse(DefaultMaximumCompileErrors)
|
(for( MaxCompileErrors(maxErrors) <- options) yield maxErrors).firstOption.getOrElse(DefaultMaximumCompileErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
trait WebScalaProject extends ScalaProject
|
trait WebScalaProject extends ScalaProject
|
||||||
{
|
{
|
||||||
@deprecated protected def prepareWebappTask(webappContents: PathFinder, warPath: => Path, classpath: PathFinder, extraJars: => Iterable[File]): Task =
|
@deprecated protected def prepareWebappTask(webappContents: PathFinder, warPath: => Path, classpath: PathFinder, extraJars: => Iterable[File]): Task =
|
||||||
|
|
@ -344,14 +351,19 @@ object ScalaProject
|
||||||
}
|
}
|
||||||
trait MultiTaskProject extends Project
|
trait MultiTaskProject extends Project
|
||||||
{
|
{
|
||||||
def multiTask(allTests: => List[String])(run: (String => Boolean) => Task) =
|
def multiTask(allTests: => List[String])(run: (List[String], (String => Boolean)) => Task): MethodTask = {
|
||||||
|
|
||||||
task { tests =>
|
task { tests =>
|
||||||
|
|
||||||
|
val (testNames, separator :: testArgs) = tests.toList.span(! _.startsWith("--"))
|
||||||
|
|
||||||
def filterInclude =
|
def filterInclude =
|
||||||
{
|
{
|
||||||
val (exactFilters, testFilters) = tests.toList.map(GlobFilter.apply).partition(_.isInstanceOf[ExactFilter])
|
val (exactFilters, testFilters) = testNames.toList.map(GlobFilter.apply).partition(_.isInstanceOf[ExactFilter])
|
||||||
val includeTests = exactFilters.map(_.asInstanceOf[ExactFilter].matchName)
|
val includeTests = exactFilters.map(_.asInstanceOf[ExactFilter].matchName)
|
||||||
val toCheck = scala.collection.mutable.HashSet(includeTests: _*)
|
val toCheck = scala.collection.mutable.HashSet(includeTests: _*)
|
||||||
toCheck --= allTests
|
toCheck --= allTests
|
||||||
|
|
||||||
if(!toCheck.isEmpty && log.atLevel(Level.Warn))
|
if(!toCheck.isEmpty && log.atLevel(Level.Warn))
|
||||||
{
|
{
|
||||||
log.warn("Test(s) not found:")
|
log.warn("Test(s) not found:")
|
||||||
|
|
@ -361,13 +373,13 @@ trait MultiTaskProject extends Project
|
||||||
(test: String) => includeTestsSet.contains(test) || testFilters.exists(_.accept(test))
|
(test: String) => includeTestsSet.contains(test) || testFilters.exists(_.accept(test))
|
||||||
}
|
}
|
||||||
val includeFunction =
|
val includeFunction =
|
||||||
if(tests.isEmpty)
|
if(testNames.isEmpty)
|
||||||
(test: String) => true
|
(test: String) => true
|
||||||
else
|
else
|
||||||
filterInclude
|
filterInclude
|
||||||
run(includeFunction)
|
run(testArgs, includeFunction)
|
||||||
} completeWith allTests
|
} completeWith allTests
|
||||||
|
}
|
||||||
}
|
}
|
||||||
trait ExecProject extends Project
|
trait ExecProject extends Project
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/* sbt -- Simple Build Tool
|
/* sbt -- Simple Build Tool
|
||||||
* Copyright 2008, 2009 Steven Blundy, Mark Harrah
|
* Copyright 2008, 2009 Steven Blundy, Mark Harrah, Josh Cough
|
||||||
*/
|
*/
|
||||||
package sbt
|
package sbt
|
||||||
|
|
||||||
|
|
@ -69,15 +69,15 @@ final class NamedTestTask(val name: String, action: => Option[String]) extends N
|
||||||
|
|
||||||
object TestFramework
|
object TestFramework
|
||||||
{
|
{
|
||||||
def runTests(frameworks: Seq[TestFramework], classpath: Iterable[Path], scalaLoader: ClassLoader, tests: Seq[TestDefinition], log: Logger,
|
// def runTests(frameworks: Seq[TestFramework], classpath: Iterable[Path], scalaLoader: ClassLoader,
|
||||||
listeners: Seq[TestReportListener]) =
|
// tests: Seq[TestDefinition], testArgs: Seq[String], log: Logger, listeners: Seq[TestReportListener]) =
|
||||||
{
|
// {
|
||||||
val (start, runTests, end) = testTasks(frameworks, classpath, scalaLoader, tests, log, listeners, true, Nil, Nil)
|
// val (start, runTests, end) = testTasks(frameworks, classpath, scalaLoader, tests, log, listeners, true, Nil, Nil, Nil)
|
||||||
def run(tasks: Iterable[NamedTestTask]) = tasks.foreach(_.run())
|
// def run(tasks: Iterable[NamedTestTask]) = tasks.foreach(_.run())
|
||||||
run(start)
|
// run(start)
|
||||||
run(runTests)
|
// run(runTests)
|
||||||
run(end)
|
// run(end)
|
||||||
}
|
// }
|
||||||
|
|
||||||
private val ScalaCompilerJarPackages = "scala.tools.nsc." :: "jline." :: "ch.epfl.lamp." :: Nil
|
private val ScalaCompilerJarPackages = "scala.tools.nsc." :: "jline." :: "ch.epfl.lamp." :: Nil
|
||||||
|
|
||||||
|
|
@ -89,9 +89,16 @@ object TestFramework
|
||||||
|
|
||||||
import scala.collection.{Map, Set}
|
import scala.collection.{Map, Set}
|
||||||
|
|
||||||
def testTasks(frameworks: Seq[TestFramework], classpath: Iterable[Path], scalaLoader: ClassLoader, tests: Seq[TestDefinition], log: Logger,
|
def testTasks(frameworks: Seq[TestFramework],
|
||||||
listeners: Seq[TestReportListener], endErrorsEnabled: Boolean, setup: Iterable[() => Option[String]],
|
classpath: Iterable[Path],
|
||||||
cleanup: Iterable[() => Option[String]]): (Iterable[NamedTestTask], Iterable[NamedTestTask], Iterable[NamedTestTask]) =
|
scalaLoader: ClassLoader,
|
||||||
|
tests: Seq[TestDefinition],
|
||||||
|
log: Logger,
|
||||||
|
listeners: Seq[TestReportListener],
|
||||||
|
endErrorsEnabled: Boolean,
|
||||||
|
setup: Iterable[() => Option[String]],
|
||||||
|
cleanup: Iterable[() => Option[String]],
|
||||||
|
testArgs: Seq[String]): (Iterable[NamedTestTask], Iterable[NamedTestTask], Iterable[NamedTestTask]) =
|
||||||
{
|
{
|
||||||
val loader = createTestLoader(classpath, scalaLoader)
|
val loader = createTestLoader(classpath, scalaLoader)
|
||||||
val rawFrameworks = frameworks.flatMap(_.create(loader, log))
|
val rawFrameworks = frameworks.flatMap(_.create(loader, log))
|
||||||
|
|
@ -99,7 +106,7 @@ object TestFramework
|
||||||
if(mappedTests.isEmpty)
|
if(mappedTests.isEmpty)
|
||||||
(new NamedTestTask(TestStartName, None) :: Nil, Nil, new NamedTestTask(TestFinishName, { log.info("No tests to run."); None }) :: Nil )
|
(new NamedTestTask(TestStartName, None) :: Nil, Nil, new NamedTestTask(TestFinishName, { log.info("No tests to run."); None }) :: Nil )
|
||||||
else
|
else
|
||||||
createTestTasks(loader, mappedTests, log, listeners, endErrorsEnabled, setup, cleanup)
|
createTestTasks(loader, mappedTests, log, listeners, endErrorsEnabled, setup, cleanup, testArgs)
|
||||||
}
|
}
|
||||||
private def testMap(frameworks: Seq[Framework], tests: Seq[TestDefinition]): Map[Framework, Set[TestDefinition]] =
|
private def testMap(frameworks: Seq[Framework], tests: Seq[TestDefinition]): Map[Framework, Set[TestDefinition]] =
|
||||||
{
|
{
|
||||||
|
|
@ -127,7 +134,7 @@ object TestFramework
|
||||||
|
|
||||||
private def createTestTasks(loader: ClassLoader, tests: Map[Framework, Set[TestDefinition]], log: Logger,
|
private def createTestTasks(loader: ClassLoader, tests: Map[Framework, Set[TestDefinition]], log: Logger,
|
||||||
listeners: Seq[TestReportListener], endErrorsEnabled: Boolean, setup: Iterable[() => Option[String]],
|
listeners: Seq[TestReportListener], endErrorsEnabled: Boolean, setup: Iterable[() => Option[String]],
|
||||||
cleanup: Iterable[() => Option[String]]) =
|
cleanup: Iterable[() => Option[String]], testArgs: Seq[String]) =
|
||||||
{
|
{
|
||||||
val testsListeners = listeners.filter(_.isInstanceOf[TestsListener]).map(_.asInstanceOf[TestsListener])
|
val testsListeners = listeners.filter(_.isInstanceOf[TestsListener]).map(_.asInstanceOf[TestsListener])
|
||||||
def foreachListenerSafe(f: TestsListener => Unit): Unit = safeForeach(testsListeners, log)(f)
|
def foreachListenerSafe(f: TestsListener => Unit): Unit = safeForeach(testsListeners, log)(f)
|
||||||
|
|
@ -151,7 +158,7 @@ object TestFramework
|
||||||
val oldLoader = Thread.currentThread.getContextClassLoader
|
val oldLoader = Thread.currentThread.getContextClassLoader
|
||||||
Thread.currentThread.setContextClassLoader(loader)
|
Thread.currentThread.setContextClassLoader(loader)
|
||||||
try {
|
try {
|
||||||
runner.run(testDefinition, Nil) match
|
runner.run(testDefinition, testArgs) match
|
||||||
{
|
{
|
||||||
case Error => result() = Error; Some("ERROR occurred during testing.")
|
case Error => result() = Error; Some("ERROR occurred during testing.")
|
||||||
case Failed => result() = Failed; Some("Test FAILED")
|
case Failed => result() = Failed; Some("Test FAILED")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue