show test key in no tests message. fixes #102

This commit is contained in:
Mark Harrah 2011-07-12 23:09:57 -04:00
parent 555b1c04a4
commit 3eef6229db
3 changed files with 13 additions and 10 deletions

View File

@ -240,12 +240,14 @@ object Defaults extends BuildCommon
definedTests <<= TaskData.writeRelated(detectTests)(_.map(_.name).distinct) triggeredBy compile, definedTests <<= TaskData.writeRelated(detectTests)(_.map(_.name).distinct) triggeredBy compile,
testListeners in GlobalScope :== Nil, testListeners in GlobalScope :== Nil,
testOptions in GlobalScope :== Nil, testOptions in GlobalScope :== Nil,
executeTests <<= (streams in test, loadedTestFrameworks, parallelExecution in test, testOptions in test, testLoader, definedTests) flatMap { executeTests <<= (streams in test, loadedTestFrameworks, parallelExecution in test, testOptions in test, testLoader, definedTests, resolvedScoped) flatMap {
(s, frameworkMap, par, options, loader, discovered) => Tests(frameworkMap, loader, discovered, options, par, s.log) (s, frameworkMap, par, options, loader, discovered, scoped) => Tests(frameworkMap, loader, discovered, options, par, noTestsMessage(ScopedKey(scoped.scope, test.key)), s.log)
}, },
test <<= (executeTests, streams) map { (results, s) => Tests.showResults(s.log, results) }, test <<= (executeTests, streams) map { (results, s) => Tests.showResults(s.log, results) },
testOnly <<= testOnlyTask testOnly <<= testOnlyTask
) )
private[this] def noTestsMessage(scoped: ScopedKey[_]): String =
"No tests to run for " + Project.display(scoped)
lazy val TaskGlobal: Scope = ThisScope.copy(task = Global) lazy val TaskGlobal: Scope = ThisScope.copy(task = Global)
def testTaskOptions(key: Scoped): Seq[Setting[_]] = inTask(key)( Seq( def testTaskOptions(key: Scoped): Seq[Setting[_]] = inTask(key)( Seq(
@ -270,11 +272,11 @@ object Defaults extends BuildCommon
def testOnlyTask = def testOnlyTask =
InputTask( TaskData(definedTests)(testOnlyParser)(Nil) ) { result => InputTask( TaskData(definedTests)(testOnlyParser)(Nil) ) { result =>
(streams, loadedTestFrameworks, parallelExecution in testOnly, testOptions in testOnly, testLoader, definedTests, result) flatMap { (streams, loadedTestFrameworks, parallelExecution in testOnly, testOptions in testOnly, testLoader, definedTests, resolvedScoped, result) flatMap {
case (s, frameworks, par, opts, loader, discovered, (tests, frameworkOptions)) => case (s, frameworks, par, opts, loader, discovered, scoped, (tests, frameworkOptions)) =>
val filter = selectedFilter(tests) val filter = selectedFilter(tests)
val modifiedOpts = Tests.Filter(filter) +: Tests.Argument(frameworkOptions : _*) +: opts val modifiedOpts = Tests.Filter(filter) +: Tests.Argument(frameworkOptions : _*) +: opts
Tests(frameworks, loader, discovered, modifiedOpts, par, s.log) map { results => Tests(frameworks, loader, discovered, modifiedOpts, par, noTestsMessage(ScopedKey(scoped.scope, testOnly.key)), s.log) map { results =>
Tests.showResults(s.log, results) Tests.showResults(s.log, results)
} }
} }

View File

@ -40,7 +40,7 @@ object Tests
final case class Argument(framework: Option[TestFramework], args: List[String]) extends TestOption final case class Argument(framework: Option[TestFramework], args: List[String]) extends TestOption
def apply(frameworks: Map[TestFramework, Framework], testLoader: ClassLoader, discovered: Seq[TestDefinition], options: Seq[TestOption], parallel: Boolean, log: Logger): Task[Output] = def apply(frameworks: Map[TestFramework, Framework], testLoader: ClassLoader, discovered: Seq[TestDefinition], options: Seq[TestOption], parallel: Boolean, noTestsMessage: => String, log: Logger): Task[Output] =
{ {
import mutable.{HashSet, ListBuffer, Map, Set} import mutable.{HashSet, ListBuffer, Map, Set}
val testFilters = new ListBuffer[String => Boolean] val testFilters = new ListBuffer[String => Boolean]
@ -88,10 +88,10 @@ object Tests
def includeTest(test: TestDefinition) = !excludeTestsSet.contains(test.name) && testFilters.forall(filter => filter(test.name)) def includeTest(test: TestDefinition) = !excludeTestsSet.contains(test.name) && testFilters.forall(filter => filter(test.name))
val tests = discovered.filter(includeTest).toSet.toSeq val tests = discovered.filter(includeTest).toSet.toSeq
val arguments = testArgsByFramework.map { case (k,v) => (k, v.toList) } toMap; val arguments = testArgsByFramework.map { case (k,v) => (k, v.toList) } toMap;
testTask(frameworks.values.toSeq, testLoader, tests, setup.readOnly, cleanup.readOnly, log, testListeners.readOnly, arguments, parallel) testTask(frameworks.values.toSeq, testLoader, tests, noTestsMessage, setup.readOnly, cleanup.readOnly, log, testListeners.readOnly, arguments, parallel)
} }
def testTask(frameworks: Seq[Framework], loader: ClassLoader, tests: Seq[TestDefinition], def testTask(frameworks: Seq[Framework], loader: ClassLoader, tests: Seq[TestDefinition], noTestsMessage: => String,
userSetup: Iterable[ClassLoader => Unit], userCleanup: Iterable[ClassLoader => Unit], userSetup: Iterable[ClassLoader => Unit], userCleanup: Iterable[ClassLoader => Unit],
log: Logger, testListeners: Seq[TestReportListener], arguments: Map[Framework, Seq[String]], parallel: Boolean): Task[Output] = log: Logger, testListeners: Seq[TestReportListener], arguments: Map[Framework, Seq[String]], parallel: Boolean): Task[Output] =
{ {
@ -99,7 +99,7 @@ object Tests
def partApp(actions: Iterable[ClassLoader => Unit]) = actions.toSeq map {a => () => a(loader) } def partApp(actions: Iterable[ClassLoader => Unit]) = actions.toSeq map {a => () => a(loader) }
val (frameworkSetup, runnables, frameworkCleanup) = val (frameworkSetup, runnables, frameworkCleanup) =
TestFramework.testTasks(frameworks, loader, tests, log, testListeners, arguments) TestFramework.testTasks(frameworks, loader, tests, noTestsMessage, log, testListeners, arguments)
val setupTasks = fj(partApp(userSetup) :+ frameworkSetup) val setupTasks = fj(partApp(userSetup) :+ frameworkSetup)
val mainTasks = if(parallel) makeParallel(runnables, setupTasks).toSeq.join else makeSerial(runnables, setupTasks) val mainTasks = if(parallel) makeParallel(runnables, setupTasks).toSeq.join else makeSerial(runnables, setupTasks)

View File

@ -133,6 +133,7 @@ object TestFramework
def testTasks(frameworks: Seq[Framework], def testTasks(frameworks: Seq[Framework],
testLoader: ClassLoader, testLoader: ClassLoader,
tests: Seq[TestDefinition], tests: Seq[TestDefinition],
noTestsMessage: => String,
log: Logger, log: Logger,
listeners: Seq[TestReportListener], listeners: Seq[TestReportListener],
testArgsByFramework: Map[Framework, Seq[String]]): testArgsByFramework: Map[Framework, Seq[String]]):
@ -141,7 +142,7 @@ object TestFramework
val arguments = testArgsByFramework withDefaultValue Nil val arguments = testArgsByFramework withDefaultValue Nil
val mappedTests = testMap(frameworks, tests, arguments) val mappedTests = testMap(frameworks, tests, arguments)
if(mappedTests.isEmpty) if(mappedTests.isEmpty)
(() => (), Nil, _ => () => log.info("No tests to run.") ) (() => (), Nil, _ => () => log.info(noTestsMessage) )
else else
createTestTasks(testLoader, mappedTests, log, listeners) createTestTasks(testLoader, mappedTests, log, listeners)
} }