Skip to content

Commit

Permalink
Merge pull request #6637 from commercialhaskell/fix6636
Browse files Browse the repository at this point in the history
Re #6636 Add `--run-tests` and `--run-benchmarks`
  • Loading branch information
mpilgrem authored Aug 10, 2024
2 parents 7c70d29 + d32505a commit 34522bb
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 77 deletions.
27 changes: 19 additions & 8 deletions .stan.toml
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,36 @@

# Anti-pattern: unsafe functions
[[ignore]]
id = "OBS-STAN-0212-FNS1cF-59:17"
id = "OBS-STAN-0212-FNS1cF-60:17"
# ✦ Description: Usage of unsafe functions breaks referential transparency
# ✦ Category: #Unsafe #AntiPattern
# ✦ File: src\Stack\BuildOpts.hs
#
# 58
# 59 ┃ buildMonoid = undefined :: BuildOptsMonoid
# 60 ┃ ^^^^^^^^^
# 59
# 60 ┃ buildMonoid = undefined :: BuildOptsMonoid
# 61 ┃ ^^^^^^^^^

# Anti-pattern: unsafe functions
[[ignore]]
id = "OBS-STAN-0212-FNS1cF-71:14"
id = "OBS-STAN-0212-FNS1cF-72:14"
# ✦ Description: Usage of unsafe functions breaks referential transparency
# ✦ Category: #Unsafe #AntiPattern
# ✦ File: src\Stack\BuildOpts.hs
#
# 70 ┃
# 71 ┃ toMonoid = undefined :: TestOptsMonoid
# 72 ┃ ^^^^^^^^^
# 71 ┃
# 72 ┃ toMonoid = undefined :: TestOptsMonoid
# 73 ┃ ^^^^^^^^^

# Anti-pattern: unsafe functions
[[ignore]]
id = "OBS-STAN-0212-FNS1cF-83:15"
# ✦ Description: Usage of unsafe functions breaks referential transparency
# ✦ Category: #Unsafe #AntiPattern
# ✦ File: src/Stack/BuildOpts.hs
#
# 82 ┃
# 83 ┃ beoMonoid = undefined :: BenchmarkOptsMonoid
# 84 ┃ ^^^^^^^^^

# Anti-pattern: Pattern matching on '_'
# Pattern matching on '_' for sum types can create maintainability issues
Expand Down
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ Behavior changes:

Other enhancements:

* Add flags `--run-tests` and `--run-benchmarks` (the existing defaults) to
Stack's `build` command, which take precedence over the existing
`no-run-tests` and `no-run-benchmarks` configuration options, respectively.

Bug fixes:

* Stack's in-app messages refer to https://haskellstack.org as currently
Expand Down
4 changes: 2 additions & 2 deletions doc/commands/bench_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ stack bench [TARGET] [--dry-run] [--pedantic] [--fast] [--ghc-options OPTIONS]
[--[no-]copy-bins] [--[no-]copy-compiler-tool] [--[no-]prefetch]
[--[no-]keep-going] [--[no-]keep-tmp-files] [--[no-]force-dirty]
[--[no-]test] [--[no-]rerun-tests] [--ta|--test-arguments TEST_ARGS]
[--coverage] [--no-run-tests] [--test-suite-timeout ARG]
[--coverage] [--[no-]run-tests] [--test-suite-timeout ARG]
[--[no-]tests-allow-stdin] [--[no-]bench]
[--ba|--benchmark-arguments BENCH_ARGS] [--no-run-benchmarks]
[--ba|--benchmark-arguments BENCH_ARGS] [--[no-]run-benchmarks]
[--[no-]reconfigure] [--cabal-verbosity VERBOSITY |
--[no-]cabal-verbose] [--[no-]split-objs] [--skip ARG]
[--[no-]interleaved-output] [--ddump-dir ARG]
Expand Down
23 changes: 21 additions & 2 deletions doc/commands/build_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ stack build [TARGET] [--dry-run] [--pedantic] [--fast] [--ghc-options OPTIONS]
[--[no-]copy-bins] [--[no-]copy-compiler-tool] [--[no-]prefetch]
[--[no-]keep-going] [--[no-]keep-tmp-files] [--[no-]force-dirty]
[--[no-]test] [--[no-]rerun-tests] [--ta|--test-arguments TEST_ARGS]
[--coverage] [--no-run-tests] [--test-suite-timeout ARG]
[--coverage] [--[no-]run-tests] [--test-suite-timeout ARG]
[--[no-]tests-allow-stdin] [--[no-]bench]
[--ba|--benchmark-arguments BENCH_ARGS] [--no-run-benchmarks]
[--ba|--benchmark-arguments BENCH_ARGS] [--[no-]run-benchmarks]
[--[no-]reconfigure] [--cabal-verbosity VERBOSITY |
--[no-]cabal-verbose] [--[no-]split-objs] [--skip ARG]
[--[no-]interleaved-output] [--ddump-dir ARG]
Expand Down Expand Up @@ -661,6 +661,25 @@ command line arguments. For example, to pass `'a single quoted string'`:
The content of single quotes is taken literally. Within single quotes, `''`
escapes a single quote.

### `--[no-]rerun-tests` flag

Default: Enabled

Unset the flag to disable the automatic running of targeted test-suites that
have already been successful.

### `--[no-]run-benchmarks` flag

Default: Enabled

Unset the flag to disable the automatic running of targeted benchmarks.

### `--[no-]run-tests` flag

Default: Enabled

Unset the flag to disable the automatic running of targeted test suites.

### `--test-arguments`, `--ta` option

`stack build --test --test-arguments=<argument(s)>` will pass the specified
Expand Down
4 changes: 2 additions & 2 deletions doc/commands/haddock_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ stack haddock [TARGET] [--dry-run] [--pedantic] [--fast] [--ghc-options OPTIONS]
[--[no-]copy-bins] [--[no-]copy-compiler-tool] [--[no-]prefetch]
[--[no-]keep-going] [--[no-]keep-tmp-files] [--[no-]force-dirty]
[--[no-]test] [--[no-]rerun-tests]
[--ta|--test-arguments TEST_ARGS] [--coverage] [--no-run-tests]
[--ta|--test-arguments TEST_ARGS] [--coverage] [--[no-]run-tests]
[--test-suite-timeout ARG] [--[no-]tests-allow-stdin]
[--[no-]bench] [--ba|--benchmark-arguments BENCH_ARGS]
[--no-run-benchmarks] [--[no-]reconfigure]
[--[no-]run-benchmarks] [--[no-]reconfigure]
[--cabal-verbosity VERBOSITY | --[no-]cabal-verbose]
[--[no-]split-objs] [--skip ARG] [--[no-]interleaved-output]
[--ddump-dir ARG]
Expand Down
4 changes: 2 additions & 2 deletions doc/commands/install_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ stack install [TARGET] [--dry-run] [--pedantic] [--fast] [--ghc-options OPTIONS]
[--[no-]copy-bins] [--[no-]copy-compiler-tool] [--[no-]prefetch]
[--[no-]keep-going] [--[no-]keep-tmp-files] [--[no-]force-dirty]
[--[no-]test] [--[no-]rerun-tests]
[--ta|--test-arguments TEST_ARGS] [--coverage] [--no-run-tests]
[--ta|--test-arguments TEST_ARGS] [--coverage] [--[no-]run-tests]
[--test-suite-timeout ARG] [--[no-]tests-allow-stdin]
[--[no-]bench] [--ba|--benchmark-arguments BENCH_ARGS]
[--no-run-benchmarks] [--[no-]reconfigure]
[--[no-]run-benchmarks] [--[no-]reconfigure]
[--cabal-verbosity VERBOSITY | --[no-]cabal-verbose]
[--[no-]split-objs] [--skip ARG] [--[no-]interleaved-output]
[--ddump-dir ARG]
Expand Down
4 changes: 2 additions & 2 deletions doc/commands/test_command.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ stack test [TARGET] [--dry-run] [--pedantic] [--fast] [--ghc-options OPTIONS]
[--[no-]copy-bins] [--[no-]copy-compiler-tool] [--[no-]prefetch]
[--[no-]keep-going] [--[no-]keep-tmp-files] [--[no-]force-dirty]
[--[no-]test] [--[no-]rerun-tests] [--ta|--test-arguments TEST_ARGS]
[--coverage] [--no-run-tests] [--test-suite-timeout ARG]
[--coverage] [--[no-]run-tests] [--test-suite-timeout ARG]
[--[no-]tests-allow-stdin] [--[no-]bench]
[--ba|--benchmark-arguments BENCH_ARGS] [--no-run-benchmarks]
[--ba|--benchmark-arguments BENCH_ARGS] [--[no-]run-benchmarks]
[--[no-]reconfigure] [--cabal-verbosity VERBOSITY |
--[no-]cabal-verbose] [--[no-]split-objs] [--skip ARG]
[--[no-]interleaved-output] [--ddump-dir ARG]
Expand Down
14 changes: 13 additions & 1 deletion doc/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,19 @@
top-level `dependencies` key.

Alternatively, build all components of project packages without running
tests or benchmarks once built. Command:
tests or benchmarks once built. Add the following to a configuration file:

~~~yaml
build:
test: true
test-arguments:
no-run-tests: true
bench: true
benchmark-opts:
no-run-benchmarks: true
~~~

or command:

~~~text
stack build --test --no-run-tests --bench --no-run-benchmarks
Expand Down
16 changes: 8 additions & 8 deletions src/Stack/Build/ExecutePackage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,8 @@ singleTest topts testsToRun ac ee task installedMap = do
config <- view configL
let needHpc = topts.coverage
toRun <-
if topts.disableRun
then do
announce "Test running disabled by --no-run-tests flag."
pure False
else if topts.rerunTests
if topts.runTests
then if topts.rerunTests
then pure True
else do
status <- getTestStatus pkgDir
Expand All @@ -999,6 +996,9 @@ singleTest topts testsToRun ac ee task installedMap = do
announce "rerunning previously failed test"
pure True
TSUnknown -> pure True
else do
announce "Test running disabled by --no-run-tests flag."
pure False

when toRun $ do
buildDir <- distDirFromDir pkgDir
Expand Down Expand Up @@ -1262,11 +1262,11 @@ singleBench beopts benchesToRun ac ee task installedMap = do
beopts.additionalArgs

toRun <-
if beopts.disableRun
then do
if beopts.runBenchmarks
then pure True
else do
announce "Benchmark running disabled by --no-run-benchmarks flag."
pure False
else pure True

when toRun $ do
announce "benchmarks"
Expand Down
11 changes: 7 additions & 4 deletions src/Stack/BuildOpts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import Stack.Types.BuildOpts
, TestOpts (..)
)
import Stack.Types.BuildOptsMonoid
( BuildOptsMonoid (..), CabalVerbosity (..)
, ProgressBarFormat (..), TestOptsMonoid (..)
( BenchmarkOptsMonoid (..), BuildOptsMonoid (..)
, CabalVerbosity (..), ProgressBarFormat (..)
, TestOptsMonoid (..)
)

defaultBuildOpts :: BuildOpts
Expand Down Expand Up @@ -63,7 +64,7 @@ defaultTestOpts = TestOpts
{ rerunTests = defaultFirstTrue toMonoid.rerunTests
, additionalArgs = []
, coverage = defaultFirstFalse toMonoid.coverage
, disableRun = defaultFirstFalse toMonoid.disableRun
, runTests = defaultFirstTrue toMonoid.runTests
, maximumTimeSeconds = Nothing
, allowStdin = defaultFirstTrue toMonoid.allowStdin
}
Expand All @@ -76,5 +77,7 @@ defaultHaddockOpts = HaddockOpts { additionalArgs = [] }
defaultBenchmarkOpts :: BenchmarkOpts
defaultBenchmarkOpts = BenchmarkOpts
{ additionalArgs = Nothing
, disableRun = False
, runBenchmarks = defaultFirstTrue beoMonoid.runBenchmarks
}
where
beoMonoid = undefined :: BenchmarkOptsMonoid
17 changes: 7 additions & 10 deletions src/Stack/Config/Build.hs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ testOptsFromMonoid toMonoid madditional = defaultTestOpts
, TestOpts.additionalArgs =
fromMaybe [] madditional <> toMonoid.additionalArgs
, TestOpts.coverage = fromFirstFalse toMonoid.coverage
, TestOpts.disableRun = fromFirstFalse toMonoid.disableRun
, TestOpts.runTests = fromFirstTrue toMonoid.runTests
, TestOpts.maximumTimeSeconds =
fromFirst
defaultTestOpts.maximumTimeSeconds
Expand All @@ -135,12 +135,9 @@ benchmarkOptsFromMonoid ::
BenchmarkOptsMonoid
-> Maybe [String]
-> BenchmarkOpts
benchmarkOptsFromMonoid beoMonoid madditional =
defaultBenchmarkOpts
{ BenchmarkOpts.additionalArgs =
fmap (\args -> unwords args <> " ") madditional <>
getFirst beoMonoid.additionalArgs
, BenchmarkOpts.disableRun = fromFirst
defaultBenchmarkOpts.disableRun
beoMonoid.disableRun
}
benchmarkOptsFromMonoid beoMonoid madditional = defaultBenchmarkOpts
{ BenchmarkOpts.additionalArgs =
fmap (\args -> unwords args <> " ") madditional <>
getFirst beoMonoid.additionalArgs
, BenchmarkOpts.runBenchmarks = fromFirstTrue beoMonoid.runBenchmarks
}
4 changes: 2 additions & 2 deletions src/Stack/Ghci.hs
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ ghciCmd ghciOpts =
bopts <- view buildOptsL
-- override env so running of tests and benchmarks is disabled
let boptsLocal = bopts
{ testOpts = bopts.testOpts { TestOpts.disableRun = True }
{ testOpts = bopts.testOpts { TestOpts.runTests = False }
, benchmarkOpts =
bopts.benchmarkOpts { BenchmarkOpts.disableRun = True }
bopts.benchmarkOpts { BenchmarkOpts.runBenchmarks = False }
}
local (set buildOptsL boptsLocal) (ghci ghciOpts)

Expand Down
20 changes: 9 additions & 11 deletions src/Stack/Options/BenchParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ module Stack.Options.BenchParser
( benchOptsParser
) where

import Options.Applicative
( Parser, flag', help, long, metavar, strOption )
import Options.Applicative.Builder.Extra ( optionalFirst )
import Options.Applicative ( Parser, help, long, metavar, strOption )
import Options.Applicative.Builder.Extra
( firstBoolFlagsTrue, optionalFirst )
import Stack.Prelude
import Stack.Options.Utils ( hideMods )
import Stack.Types.BuildOptsMonoid ( BenchmarkOptsMonoid (..) )
Expand All @@ -20,15 +20,13 @@ benchOptsParser hide0 = BenchmarkOptsMonoid
( long "benchmark-arguments"
<> long "ba"
<> metavar "BENCH_ARGS"
<> help "Forward BENCH_ARGS to the benchmark suite. Supports templates \
\from 'cabal bench'."
<> hide
))
<*> optionalFirst (flag' True
( long "no-run-benchmarks"
<> help "Disable running of benchmarks. (Benchmarks will still be \
\built.)"
<> help "Arguments passed to the benchmarks. Supports path variables \
\provided by the Cabal build system."
<> hide
))
<*> firstBoolFlagsTrue
"run-benchmarks"
"running of targeted benchmarks."
hide
where
hide = hideMods hide0
15 changes: 7 additions & 8 deletions src/Stack/Options/TestParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,32 @@ testOptsParser :: Bool -> Parser TestOptsMonoid
testOptsParser hide0 = TestOptsMonoid
<$> firstBoolFlagsTrue
"rerun-tests"
"running already successful tests."
"running already successful test suites."
hide
<*> fmap concat (many (argsOption
( long "test-arguments"
<> long "ta"
<> metavar "TEST_ARGS"
<> help "Arguments passed in to the test suite program."
<> help "Arguments passed to the test suites."
<> hide
)))
<*> optionalFirstFalse (flag' True
( long "coverage"
<> help "Generate a code coverage report."
<> hide
))
<*> optionalFirstFalse (flag' True
( long "no-run-tests"
<> help "Disable running of tests. (Tests will still be built.)"
<> hide
))
<*> firstBoolFlagsTrue
"run-tests"
"running of targeted test suites."
hide
<*> optionalFirst (option (fmap Just auto)
( long "test-suite-timeout"
<> help "Maximum test suite run time in seconds."
<> hide
))
<*> firstBoolFlagsTrue
"tests-allow-stdin"
"allow standard input in test executables."
"allow standard input in test suites."
hide
where
hide = hideMods hide0
6 changes: 3 additions & 3 deletions src/Stack/Types/BuildOpts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ data TestOpts = TestOpts
{ rerunTests :: !Bool -- ^ Whether successful tests will be run gain
, additionalArgs :: ![String] -- ^ Arguments passed to the test program
, coverage :: !Bool -- ^ Generate a code coverage report
, disableRun :: !Bool -- ^ Disable running of tests
, runTests :: !Bool -- ^ Enable running of tests
, maximumTimeSeconds :: !(Maybe Int) -- ^ test suite timeout in seconds
, allowStdin :: !Bool -- ^ Whether to allow standard input
}
Expand All @@ -112,8 +112,8 @@ data TestOpts = TestOpts
data BenchmarkOpts = BenchmarkOpts
{ additionalArgs :: !(Maybe String)
-- ^ Arguments passed to the benchmark program
, disableRun :: !Bool
-- ^ Disable running of benchmarks
, runBenchmarks :: !Bool
-- ^ Enable running of benchmarks
}
deriving (Eq, Show)

Expand Down
Loading

0 comments on commit 34522bb

Please sign in to comment.