mirror of
https://github.com/sbt/sbt.git
synced 2026-10-08 02:53:10 +02:00
Added TestResultLogger for customising test feedback.
1) When `test` is run and there are no tests available, omit logging output. Especially useful for aggregate modules. `test-only` et al unaffected. (#1185) 2) Added a new setting `testResultLogger` to allow customisation of logging of test results.
This commit is contained in:
@@ -371,6 +371,7 @@ object Defaults extends BuildCommon
|
||||
},
|
||||
testListeners :== Nil,
|
||||
testOptions :== Nil,
|
||||
testResultLogger :== TestResultLogger.Default,
|
||||
testFilter in testOnly :== (selectedFilter _)
|
||||
))
|
||||
lazy val testTasks: Seq[Setting[_]] = testTaskOptions(test) ++ testTaskOptions(testOnly) ++ testTaskOptions(testQuick) ++ testDefaults ++ Seq(
|
||||
@@ -380,16 +381,15 @@ object Defaults extends BuildCommon
|
||||
definedTestNames <<= definedTests map ( _.map(_.name).distinct) storeAs definedTestNames triggeredBy compile,
|
||||
testFilter in testQuick <<= testQuickFilter,
|
||||
executeTests <<= (streams in test, loadedTestFrameworks, testLoader, testGrouping in test, testExecution in test, fullClasspath in test, javaHome in test, testForkedParallel) flatMap allTestGroupsTask,
|
||||
testResultLogger in (Test, test) :== TestResultLogger.SilentWhenNoTests, // https://github.com/sbt/sbt/issues/1185
|
||||
test := {
|
||||
implicit val display = Project.showContextKey(state.value)
|
||||
Tests.showResults(streams.value.log, executeTests.value, noTestsMessage(resolvedScoped.value))
|
||||
val trl = (testResultLogger in (Test, test)).value
|
||||
val taskName = Project.showContextKey(state.value)(resolvedScoped.value)
|
||||
trl.run(streams.value.log, executeTests.value, taskName)
|
||||
},
|
||||
testOnly <<= inputTests(testOnly),
|
||||
testQuick <<= inputTests(testQuick)
|
||||
)
|
||||
private[this] def noTestsMessage(scoped: ScopedKey[_])(implicit display: Show[ScopedKey[_]]): String =
|
||||
"No tests to run for " + display(scoped)
|
||||
|
||||
lazy val TaskGlobal: Scope = ThisScope.copy(task = Global)
|
||||
lazy val ConfigGlobal: Scope = ThisScope.copy(config = Global)
|
||||
def testTaskOptions(key: Scoped): Seq[Setting[_]] = inTask(key)( Seq(
|
||||
@@ -488,9 +488,9 @@ object Defaults extends BuildCommon
|
||||
val modifiedOpts = Tests.Filters(filter(selected)) +: Tests.Argument(frameworkOptions : _*) +: config.options
|
||||
val newConfig = config.copy(options = modifiedOpts)
|
||||
val output = allTestGroupsTask(s, loadedTestFrameworks.value, testLoader.value, testGrouping.value, newConfig, fullClasspath.value, javaHome.value, testForkedParallel.value)
|
||||
val processed =
|
||||
for(out <- output) yield
|
||||
Tests.showResults(s.log, out, noTestsMessage(resolvedScoped.value))
|
||||
val taskName = display(resolvedScoped.value)
|
||||
val trl = testResultLogger.value
|
||||
val processed = output.map(out => trl.run(s.log, out, taskName))
|
||||
Def.value(processed)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,6 +197,7 @@ object Keys
|
||||
val testForkedParallel = SettingKey[Boolean]("test-forked-parallel", "Whether forked tests should be executed in parallel", CTask)
|
||||
val testExecution = TaskKey[Tests.Execution]("test-execution", "Settings controlling test execution", DTask)
|
||||
val testFilter = TaskKey[Seq[String] => Seq[String => Boolean]]("test-filter", "Filter controlling whether the test is executed", DTask)
|
||||
val testResultLogger = SettingKey[TestResultLogger]("test-result-logger", "Logs results after a test task completes.", DTask)
|
||||
val testGrouping = TaskKey[Seq[Tests.Group]]("test-grouping", "Collects discovered tests into groups. Whether to fork and the options for forking are configurable on a per-group basis.", BMinusTask)
|
||||
val isModule = AttributeKey[Boolean]("is-module", "True if the target is a module.", DSetting)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user