Skip to content

Commit c1f21f1

Browse files
committed
Fix #6643 Respect --no-run-tests, --no-run-benchmarks when listing actions
1 parent 4fb994f commit c1f21f1

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ Behavior changes:
1717
consequently, if a Docker container is not being run 'detached', its standard
1818
input channel will always be kept open. (Before Docker 1.9.1 the use of an
1919
interactive container could hang in certain circumstances.)
20+
* Stack respects the `--no-run-tests` and `--no-run-benchmarks` flags when
21+
determining build actions. Previously Stack respected the flags when executing
22+
the run test suites or run benchmarks actions for each targeted project
23+
package.
2024

2125
Other enhancements:
2226

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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,6 +997,9 @@ singleTest topts testsToRun ac ee task installedMap = do
997997
pure True
998998
TSUnknown -> pure True
999999
else do
1000+
-- This should never be reached, because the action should have been
1001+
-- filtered out in Stack.Build.Execute.toActions. However, we leave
1002+
-- it as is, for now. The alternative would be to throw a Stack bug.
10001003
notifyIfNoRunTests <- view $ configL . to (.notifyIfNoRunTests)
10011004
when notifyIfNoRunTests $
10021005
announce "Test running disabled by --no-run-tests flag."
@@ -1267,6 +1270,9 @@ singleBench beopts benchesToRun ac ee task installedMap = do
12671270
if beopts.runBenchmarks
12681271
then pure True
12691272
else do
1273+
-- This should never be reached, because the action should have been
1274+
-- filtered out in Stack.Build.Execute.toActions. However, we leave
1275+
-- it as is, for now. The alternative would be to throw a Stack bug.
12701276
notifyIfNoRunBenchmarks <-
12711277
view $ configL . to (.notifyIfNoRunBenchmarks)
12721278
when notifyIfNoRunBenchmarks $

0 commit comments

Comments
 (0)