Skip to content

Commit 4cb95b4

Browse files
authored
Merge pull request #6645 from commercialhaskell/fix6643
Fix #6643 Respect `--no-run-tests`, `--no-run-benchmarks` when listing actions
2 parents 671cb09 + eb4eefc commit 4cb95b4

File tree

6 files changed

+50
-19
lines changed

6 files changed

+50
-19
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Behavior changes:
2121
character in Stack's 'programs' path, as GHC 9.4.1 and later do not work if
2222
there is a space in the path to the `ghc` executable. S-8432 now presents as a
2323
warning and not an error.
24+
* Stack respects the `--no-run-tests` and `--no-run-benchmarks` flags when
25+
determining build actions. Previously Stack respected the flags when executing
26+
the run test suites or run benchmarks actions for each targeted project
27+
package.
2428

2529
Other enhancements:
2630

doc/maintainers/stack_errors.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
In connection with considering Stack's support of the
66
[Haskell Error Index](https://errors.haskell.org/) initiative, this page seeks
77
to take stock of the errors that Stack itself can raise, by reference to the
8-
`master` branch of the Stack repository. Last updated: 2024-08-02.
8+
`master` branch of the Stack repository. Last updated: 2024-09-07.
99

1010
* `Stack.main`: catches exceptions from action `commandLineHandler`.
1111

@@ -385,6 +385,7 @@ to take stock of the errors that Stack itself can raise, by reference to the
385385
[S-8100] | GHCProfOptionInvalid
386386
[S-1727] | NotOnlyLocal [PackageName] [Text]
387387
[S-6362] | CompilerVersionMismatch (Maybe (ActualCompiler, Arch)) (WantedCompiler, Arch) GHCVariant CompilerBuild VersionCheck WantedCompilerSetter Text
388+
[S-4660] | ActionNotFilteredBug StyleDoc
388389
~~~
389390

390391
- `Stack.Types.Compiler.CompilerException`

src/Stack/Build/Execute.hs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,18 @@ executePlan' :: HasEnvConfig env
367367
-> ExecuteEnv
368368
-> RIO env ()
369369
executePlan' installedMap0 targets plan ee = do
370+
config <- view configL
370371
let !buildOpts = ee.buildOpts
371372
!testOpts = buildOpts.testOpts
373+
!benchmarkOpts = buildOpts.benchmarkOpts
374+
runTests = testOpts.runTests
375+
runBenchmarks = benchmarkOpts.runBenchmarks
376+
noNotifyIfNoRunTests = not config.notifyIfNoRunTests
377+
noNotifyIfNoRunBenchmarks = not config.notifyIfNoRunBenchmarks
378+
hasTests = not . Set.null . testComponents . taskComponents
379+
hasBenches = not . Set.null . benchComponents . taskComponents
380+
tests = Map.elems $ Map.filter hasTests plan.finals
381+
benches = Map.elems $ Map.filter hasBenches plan.finals
372382
when testOpts.coverage deleteHpcReports
373383
cv <- view actualCompilerVersionL
374384
whenJust (nonEmpty $ Map.toList plan.unregisterLocal) $ \ids -> do
@@ -400,6 +410,24 @@ executePlan' installedMap0 targets plan ee = do
400410
buildOpts.keepGoing
401411
terminal <- view terminalL
402412
terminalWidth <- view termWidthL
413+
unless (noNotifyIfNoRunTests || runTests || null tests) $
414+
prettyInfo $
415+
fillSep
416+
[ flow "All test running disabled by"
417+
, style Shell "--no-run-tests"
418+
, flow "flag. To mute this message in future, set"
419+
, style Shell (flow "notify-if-no-run-tests: false")
420+
, flow "in Stack's configuration."
421+
]
422+
unless (noNotifyIfNoRunBenchmarks || runBenchmarks || null benches) $
423+
prettyInfo $
424+
fillSep
425+
[ flow "All benchmark running disabled by"
426+
, style Shell "--no-run-benchmarks"
427+
, flow "flag. To mute this message in future, set"
428+
, style Shell (flow "notify-if-no-run-benchmarks: false")
429+
, flow "in Stack's configuration."
430+
]
403431
errs <- liftIO $ runActions threads keepGoing actions $
404432
\doneVar actionsVar -> do
405433
let total = length actions
@@ -564,8 +592,9 @@ toActions installedMap mtestLock runInBase ee (mbuild, mfinal) =
564592
, concurrency = ConcurrencyAllowed
565593
}
566594
) $
567-
-- These are the "final" actions - running tests and benchmarks.
568-
( if Set.null tests
595+
-- These are the "final" actions - running test suites and benchmarks,
596+
-- unless --no-run-tests or --no-run-benchmarks is enabled.
597+
( if Set.null tests || not runTests
569598
then id
570599
else (:) Action
571600
{ actionId = ActionId pkgId ATRunTests
@@ -578,7 +607,7 @@ toActions installedMap mtestLock runInBase ee (mbuild, mfinal) =
578607
, concurrency = ConcurrencyAllowed
579608
}
580609
) $
581-
( if Set.null benches
610+
( if Set.null benches || not runBenchmarks
582611
then id
583612
else (:) Action
584613
{ actionId = ActionId pkgId ATRunBenchmarks
@@ -615,6 +644,8 @@ toActions installedMap mtestLock runInBase ee (mbuild, mfinal) =
615644
bopts = ee.buildOpts
616645
topts = bopts.testOpts
617646
beopts = bopts.benchmarkOpts
647+
runTests = topts.runTests
648+
runBenchmarks = beopts.runBenchmarks
618649

619650
taskComponents :: Task -> Set NamedComponent
620651
taskComponents task =

src/Stack/Build/ExecutePackage.hs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -996,12 +996,7 @@ singleTest topts testsToRun ac ee task installedMap = do
996996
announce "rerunning previously failed test"
997997
pure True
998998
TSUnknown -> pure True
999-
else do
1000-
notifyIfNoRunTests <- view $ configL . to (.notifyIfNoRunTests)
1001-
when notifyIfNoRunTests $
1002-
announce "Test running disabled by --no-run-tests flag."
1003-
pure False
1004-
999+
else prettyThrowM $ ActionNotFilteredBug "singleTest"
10051000
when toRun $ do
10061001
buildDir <- distDirFromDir pkgDir
10071002
hpcDir <- hpcDirFromDir pkgDir
@@ -1262,17 +1257,10 @@ singleBench beopts benchesToRun ac ee task installedMap = do
12621257
let args = map unqualCompToString benchesToRun <> maybe []
12631258
((:[]) . ("--benchmark-options=" <>))
12641259
beopts.additionalArgs
1265-
12661260
toRun <-
12671261
if beopts.runBenchmarks
12681262
then pure True
1269-
else do
1270-
notifyIfNoRunBenchmarks <-
1271-
view $ configL . to (.notifyIfNoRunBenchmarks)
1272-
when notifyIfNoRunBenchmarks $
1273-
announce "Benchmark running disabled by --no-run-benchmarks flag."
1274-
pure False
1275-
1263+
else prettyThrowM $ ActionNotFilteredBug "singleBench"
12761264
when toRun $ do
12771265
announce "benchmarks"
12781266
cabal CloseOnException KeepTHLoading ("bench" : args)

src/Stack/Types/Build/Exception.hs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,7 @@ data BuildPrettyException
261261
VersionCheck
262262
WantedCompilerSetter -- Way that the wanted compiler is set
263263
StyleDoc -- recommended resolution
264+
| ActionNotFilteredBug StyleDoc
264265
deriving (Show, Typeable)
265266

266267
instance Pretty BuildPrettyException where
@@ -450,6 +451,12 @@ instance Pretty BuildPrettyException where
450451
]
451452
<> blankLine
452453
<> resolution
454+
pretty (ActionNotFilteredBug source) = bugPrettyReport "S-4660" $
455+
fillSep
456+
[ source
457+
, flow "is seeking to run an action that should have been filtered from \
458+
\the list of actions."
459+
]
453460

454461
instance Exception BuildPrettyException
455462

tests/integration/tests/3959-order-of-flags/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ checkFlagsAfterCommand = stackCheckStderr ["build", "--test", "--no-run-tests"]
1717

1818
checker :: String -> IO ()
1919
checker output = do
20-
let testsAreDisabled = any (\ln -> "Test running disabled by" `isInfixOf` ln) (lines output)
20+
let testsAreDisabled = any (\ln -> "All test running disabled by" `isInfixOf` ln) (lines output)
2121
unless testsAreDisabled $ fail "Tests should not be run"

0 commit comments

Comments
 (0)