From 68109b8adb4204c5e704158a1db817bcee8ca2e9 Mon Sep 17 00:00:00 2001 From: Eruis2579 Date: Wed, 11 Feb 2026 01:34:35 -0500 Subject: [PATCH] Address review: ExplicitlyRequestedNames (FQN only), testFull block in scripted test - Use ExplicitlyRequestedNames(selected) so explicitlySpecified=true only for complete FQNs (no * or ?), not patterns (per TaskDef) - Pass ExplicitlyRequestedNames from Defaults inputTests0 - Scripted test: add testFull block (exclude @DoNotDiscover), keep clean + testOnly block --- main-actions/src/main/scala/sbt/Tests.scala | 10 ++++------ main/src/main/scala/sbt/Defaults.scala | 3 ++- .../tests/i5609-do-not-discover-testonly/test | 12 +++++++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/main-actions/src/main/scala/sbt/Tests.scala b/main-actions/src/main/scala/sbt/Tests.scala index c5b7c82d7..891643365 100644 --- a/main-actions/src/main/scala/sbt/Tests.scala +++ b/main-actions/src/main/scala/sbt/Tests.scala @@ -281,18 +281,16 @@ object Tests { if (orderedFilters.isEmpty) filtered0 else orderedFilters.flatMap(f => filtered0.filter(d => f(d.name))).toList.distinct val uniqueTests = distinctBy(tests)(_.name) - // When user ran testOnly with explicit args and the filter restricted the set, mark matching - // tests as explicitlySpecified so frameworks (e.g. ScalaTest) can run @DoNotDiscover suites. - // Do not mark when orderedFilters is "run all" (e.g. test with no args -> selectedFilter(Nil) -> match all). - val filteredToSubset = orderedFilters.nonEmpty && uniqueTests.size < discovered.size + // Per TaskDef: explicitlySpecified=true only when user supplied a complete FQN (e.g. testOnly com.example.MySuite), + // not for patterns (testOnly *Spec) or plain "test". So only mark when test.name is in explicitlyRequestedNames. val testsToUse = - if (!filteredToSubset) uniqueTests + if (explicitlyRequestedNames.isEmpty) uniqueTests else uniqueTests.map(t => new TestDefinition( t.name, t.fingerprint, - explicitlySpecified = true, + explicitlySpecified = explicitlyRequestedNames.contains(t.name), Array(new SuiteSelector: Selector) ) ) diff --git a/main/src/main/scala/sbt/Defaults.scala b/main/src/main/scala/sbt/Defaults.scala index 1c24bda64..c80f24819 100644 --- a/main/src/main/scala/sbt/Defaults.scala +++ b/main/src/main/scala/sbt/Defaults.scala @@ -1354,7 +1354,8 @@ object Defaults extends BuildCommon { val st = state.value given display: Show[ScopedKey[?]] = Project.showContextKey(st) val modifiedOpts = - Tests.Filters(filter(selected)) +: Tests.Argument(frameworkOptions*) +: config.options + Tests.ExplicitlyRequestedNames(selected) +: Tests.Filters(filter(selected)) +: + Tests.Argument(frameworkOptions*) +: config.options val newConfig = config.copy(options = modifiedOpts) val output = allTestGroupsTask( s, diff --git a/sbt-app/src/sbt-test/tests/i5609-do-not-discover-testonly/test b/sbt-app/src/sbt-test/tests/i5609-do-not-discover-testonly/test index 2391b2260..f91c91f73 100644 --- a/sbt-app/src/sbt-test/tests/i5609-do-not-discover-testonly/test +++ b/sbt-app/src/sbt-test/tests/i5609-do-not-discover-testonly/test @@ -1,4 +1,14 @@ -# #5609: When explicitly requested via testOnly, @DoNotDiscover suite should run +# #5609: When explicitly requested via testOnly, @DoNotDiscover suite should run. +# First: full test run must exclude @DoNotDiscover (TestSpec2). +# Second: testOnly with explicit FQN must run TestSpec2. + +> clean +> testFull +$ exists target/SuiteStarting-TestSpec +$ exists target/SuiteCompleted-TestSpec +$ absent target/SuiteStarting-TestSpec2 +$ absent target/SuiteCompleted-TestSpec2 + > clean > testOnly com.test.TestSpec2 $ exists target/SuiteStarting-TestSpec2