From f16cb5d92e89963062fc9ede07b07d18015c654d Mon Sep 17 00:00:00 2001 From: Mike Pilgrem Date: Sun, 11 Aug 2024 01:07:43 +0100 Subject: [PATCH] Fix #6641 `--dry-run` respects `--no-run-tests`, `--no-run-benchmarks` --- ChangeLog.md | 5 +++- src/Stack/Build/Execute.hs | 56 +++++++++++++++++++++++++++----------- 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/ChangeLog.md b/ChangeLog.md index 3909285d17..4239f8f4e4 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -31,10 +31,13 @@ Bug fixes: * Stack's in-app messages refer to https://haskellstack.org as currently structured. (Most URLs in older Stack versions are redirected.) - * Stack's `upgrade` command only treats the current running Stack executable as '`stack`' if the executable file is named `stack` or, on Windows, `stack.exe`. Previously only how it was invoked was considered. +* `stack test --no-run-tests --dry-run` no longer reports that Stack would test + project packages with test suites and + `stack bench --no-run-benchmarks --dry-run` no longer reports that Stack + would benchmark project packages with benchmarks. ## v3.1.1 - 2024-07-28 diff --git a/src/Stack/Build/Execute.hs b/src/Stack/Build/Execute.hs index d05f84d554..4196efa68c 100644 --- a/src/Stack/Build/Execute.hs +++ b/src/Stack/Build/Execute.hs @@ -58,7 +58,8 @@ import Stack.Types.Build , taskProvides ) import Stack.Types.Build.Exception ( BuildPrettyException (..) ) -import Stack.Types.BuildOpts ( BuildOpts (..), TestOpts (..) ) +import Stack.Types.BuildOpts + ( BenchmarkOpts (..), BuildOpts (..), TestOpts (..) ) import Stack.Types.BuildOptsCLI ( BuildOptsCLI (..) ) import Stack.Types.BuildOptsMonoid ( ProgressBarFormat (..) ) import Stack.Types.Compiler ( ActualCompiler (..) ) @@ -84,7 +85,7 @@ import Stack.Types.NamedComponent import Stack.Types.Package ( LocalPackage (..), Package (..), packageIdentifier ) import Stack.Types.Platform ( HasPlatform (..) ) -import Stack.Types.Runner ( HasRunner, terminalL, viewExecutablePath ) +import Stack.Types.Runner ( terminalL, viewExecutablePath ) import Stack.Types.SourceMap ( Target ) import qualified System.Directory as D import qualified System.FilePath as FP @@ -108,7 +109,7 @@ preFetch plan TTRemotePackage _ _ pkgloc -> Set.singleton pkgloc -- | Print a description of build plan for human consumption. -printPlan :: (HasRunner env, HasTerm env) => Plan -> RIO env () +printPlan :: HasEnvConfig env => Plan -> RIO env () printPlan plan = do case Map.elems plan.unregisterLocal of [] -> prettyInfo $ @@ -135,24 +136,47 @@ printPlan plan = do <> bulletedList (map displayTask xs) <> line + buildOpts <- view buildOptsL let hasTests = not . Set.null . testComponents . taskComponents hasBenches = not . Set.null . benchComponents . taskComponents tests = Map.elems $ Map.filter hasTests plan.finals benches = Map.elems $ Map.filter hasBenches plan.finals + runTests = buildOpts.testOpts.runTests + runBenchmarks = buildOpts.benchmarkOpts.runBenchmarks - unless (null tests) $ do - prettyInfo $ - flow "Would test:" - <> line - <> bulletedList (map displayTask tests) - <> line - - unless (null benches) $ do - prettyInfo $ - flow "Would benchmark:" - <> line - <> bulletedList (map displayTask benches) - <> line + unless (null tests) $ + if runTests + then + prettyInfo $ + flow "Would test:" + <> line + <> bulletedList (map displayTask tests) + <> line + else + prettyInfo $ + fillSep + [ flow "Would not test, as running disabled by" + , style Shell "--no-run-tests" + , "flag." + ] + <> line + + unless (null benches) $ + if runBenchmarks + then + prettyInfo $ + flow "Would benchmark:" + <> line + <> bulletedList (map displayTask benches) + <> line + else + prettyInfo $ + fillSep + [ flow "Would not benchmark, as running disabled by" + , style Shell "--no-run-benchmarks" + , "flag." + ] + <> line case Map.toList plan.installExes of [] -> prettyInfo $