mirror of https://github.com/sbt/sbt.git
[2.x] Suppress multiple main classes warning when running tests (#9372)
In a project with multiple main classes, the "multiple main classes detected" warning is unwanted noise when running tests. This message is already suppressed for explicit run commands, now also suppress it for test.
This commit is contained in:
parent
3a37da86f3
commit
7575c5a1be
|
|
@ -1140,19 +1140,20 @@ object Defaults extends BuildCommon with DefExtra {
|
|||
selectMainClass := mainClass.value orElse askForMainClass(discoveredMainClasses.value),
|
||||
run / mainClass := (run / selectMainClass).value,
|
||||
mainClass := Def.uncached {
|
||||
// Suppress warning for run commands (user is actively running, warning is noise)
|
||||
def isRunCommand(s: String): Boolean = s match
|
||||
// Suppress warning for run/test commands (user is actively running, warning is noise)
|
||||
def isRunOrTestCommand(s: String): Boolean = s match
|
||||
case "run" | "runMain" | "bgRun" | "bgRunMain" | "fgRun" | "fgRunMain" => true
|
||||
case "test" | "testFull" | "testOnly" | "testQuick" | "testSelected" => true
|
||||
case _ => false
|
||||
val logWarning = state.value.currentCommand.forall(!_.commandLine.split(" ").exists {
|
||||
case s if isRunCommand(s) => true
|
||||
case r =>
|
||||
case s if isRunOrTestCommand(s) => true
|
||||
case r =>
|
||||
// Handle both "/" (new syntax like Test/run) and ":" (old syntax like test:run)
|
||||
r.split("[/:]") match {
|
||||
case Array(parts*) =>
|
||||
parts.lastOption match {
|
||||
case Some(s) if isRunCommand(s) => true
|
||||
case _ => false
|
||||
case Some(s) if isRunOrTestCommand(s) => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue