Skip to content

Commit de5d2c5

Browse files
authored
Port 'TestFlags' to 'new-test' (#5455)
This means that old `test` flags can be passed in to `new-test`, `new-build`, `new-install`, `new-configure`, etc. These new flags are: * `--test-log` (see old `--log`) * `--test-machine-log` (see `--machine-log`) * `--test-show-details` (see `--show-details`) * `--test-keep-tix-files` (see `--keep-tix-files`) * `--test-options` * `--test-option` This fixes #4803, #4643, #4766, and #5416.
1 parent 3da088e commit de5d2c5

25 files changed

+352
-207
lines changed

Cabal/Distribution/Simple/Setup.hs

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module Distribution.Simple.Setup (
5757
defaultBenchmarkFlags, benchmarkCommand,
5858
CopyDest(..),
5959
configureArgs, configureOptions, configureCCompiler, configureLinker,
60-
buildOptions, haddockOptions, installDirsOptions,
60+
buildOptions, haddockOptions, installDirsOptions, testOptions',
6161
programDbOptions, programDbPaths',
6262
programConfigurationOptions, programConfigurationPaths',
6363
programFlagsDescription,
@@ -1830,7 +1830,9 @@ replOptions _ = [ option [] ["repl-options"] "use this option for the repl" id
18301830
-- ------------------------------------------------------------
18311831

18321832
data TestShowDetails = Never | Failures | Always | Streaming | Direct
1833-
deriving (Eq, Ord, Enum, Bounded, Show)
1833+
deriving (Eq, Ord, Enum, Bounded, Generic, Show)
1834+
1835+
instance Binary TestShowDetails
18341836

18351837
knownTestShowDetails :: [TestShowDetails]
18361838
knownTestShowDetails = [minBound..maxBound]
@@ -1898,60 +1900,63 @@ testCommand = CommandUI
18981900
, "TESTCOMPONENTS [FLAGS]"
18991901
]
19001902
, commandDefaultFlags = defaultTestFlags
1901-
, commandOptions = \showOrParseArgs ->
1902-
[ optionVerbosity testVerbosity (\v flags -> flags { testVerbosity = v })
1903-
, optionDistPref
1904-
testDistPref (\d flags -> flags { testDistPref = d })
1905-
showOrParseArgs
1906-
, option [] ["log"]
1907-
("Log all test suite results to file (name template can use "
1908-
++ "$pkgid, $compiler, $os, $arch, $test-suite, $result)")
1909-
testHumanLog (\v flags -> flags { testHumanLog = v })
1910-
(reqArg' "TEMPLATE"
1911-
(toFlag . toPathTemplate)
1912-
(flagToList . fmap fromPathTemplate))
1913-
, option [] ["machine-log"]
1914-
("Produce a machine-readable log file (name template can use "
1915-
++ "$pkgid, $compiler, $os, $arch, $result)")
1916-
testMachineLog (\v flags -> flags { testMachineLog = v })
1917-
(reqArg' "TEMPLATE"
1918-
(toFlag . toPathTemplate)
1919-
(flagToList . fmap fromPathTemplate))
1920-
, option [] ["show-details"]
1921-
("'always': always show results of individual test cases. "
1922-
++ "'never': never show results of individual test cases. "
1923-
++ "'failures': show results of failing test cases. "
1924-
++ "'streaming': show results of test cases in real time."
1925-
++ "'direct': send results of test cases in real time; no log file.")
1926-
testShowDetails (\v flags -> flags { testShowDetails = v })
1927-
(reqArg "FILTER"
1928-
(parsecToReadE (\_ -> "--show-details flag expects one of "
1929-
++ intercalate ", "
1930-
(map prettyShow knownTestShowDetails))
1931-
(fmap toFlag parsec))
1932-
(flagToList . fmap prettyShow))
1933-
, option [] ["keep-tix-files"]
1934-
"keep .tix files for HPC between test runs"
1935-
testKeepTix (\v flags -> flags { testKeepTix = v})
1936-
trueArg
1937-
, option [] ["test-options"]
1938-
("give extra options to test executables "
1939-
++ "(name templates can use $pkgid, $compiler, "
1940-
++ "$os, $arch, $test-suite)")
1941-
testOptions (\v flags -> flags { testOptions = v })
1942-
(reqArg' "TEMPLATES" (map toPathTemplate . splitArgs)
1943-
(const []))
1944-
, option [] ["test-option"]
1945-
("give extra option to test executables "
1946-
++ "(no need to quote options containing spaces, "
1947-
++ "name template can use $pkgid, $compiler, "
1948-
++ "$os, $arch, $test-suite)")
1949-
testOptions (\v flags -> flags { testOptions = v })
1950-
(reqArg' "TEMPLATE" (\x -> [toPathTemplate x])
1951-
(map fromPathTemplate))
1952-
]
1903+
, commandOptions = testOptions'
19531904
}
19541905

1906+
testOptions' :: ShowOrParseArgs -> [OptionField TestFlags]
1907+
testOptions' showOrParseArgs =
1908+
[ optionVerbosity testVerbosity (\v flags -> flags { testVerbosity = v })
1909+
, optionDistPref
1910+
testDistPref (\d flags -> flags { testDistPref = d })
1911+
showOrParseArgs
1912+
, option [] ["log"]
1913+
("Log all test suite results to file (name template can use "
1914+
++ "$pkgid, $compiler, $os, $arch, $test-suite, $result)")
1915+
testHumanLog (\v flags -> flags { testHumanLog = v })
1916+
(reqArg' "TEMPLATE"
1917+
(toFlag . toPathTemplate)
1918+
(flagToList . fmap fromPathTemplate))
1919+
, option [] ["machine-log"]
1920+
("Produce a machine-readable log file (name template can use "
1921+
++ "$pkgid, $compiler, $os, $arch, $result)")
1922+
testMachineLog (\v flags -> flags { testMachineLog = v })
1923+
(reqArg' "TEMPLATE"
1924+
(toFlag . toPathTemplate)
1925+
(flagToList . fmap fromPathTemplate))
1926+
, option [] ["show-details"]
1927+
("'always': always show results of individual test cases. "
1928+
++ "'never': never show results of individual test cases. "
1929+
++ "'failures': show results of failing test cases. "
1930+
++ "'streaming': show results of test cases in real time."
1931+
++ "'direct': send results of test cases in real time; no log file.")
1932+
testShowDetails (\v flags -> flags { testShowDetails = v })
1933+
(reqArg "FILTER"
1934+
(parsecToReadE (\_ -> "--show-details flag expects one of "
1935+
++ intercalate ", "
1936+
(map prettyShow knownTestShowDetails))
1937+
(fmap toFlag parsec))
1938+
(flagToList . fmap prettyShow))
1939+
, option [] ["keep-tix-files"]
1940+
"keep .tix files for HPC between test runs"
1941+
testKeepTix (\v flags -> flags { testKeepTix = v})
1942+
trueArg
1943+
, option [] ["test-options"]
1944+
("give extra options to test executables "
1945+
++ "(name templates can use $pkgid, $compiler, "
1946+
++ "$os, $arch, $test-suite)")
1947+
testOptions (\v flags -> flags { testOptions = v })
1948+
(reqArg' "TEMPLATES" (map toPathTemplate . splitArgs)
1949+
(const []))
1950+
, option [] ["test-option"]
1951+
("give extra option to test executables "
1952+
++ "(no need to quote options containing spaces, "
1953+
++ "name template can use $pkgid, $compiler, "
1954+
++ "$os, $arch, $test-suite)")
1955+
testOptions (\v flags -> flags { testOptions = v })
1956+
(reqArg' "TEMPLATE" (\x -> [toPathTemplate x])
1957+
(map fromPathTemplate))
1958+
]
1959+
19551960
emptyTestFlags :: TestFlags
19561961
emptyTestFlags = mempty
19571962

cabal-install/Distribution/Client/CmdBench.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Distribution.Client.Setup
2020
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
2121
import qualified Distribution.Client.Setup as Client
2222
import Distribution.Simple.Setup
23-
( HaddockFlags, fromFlagOrDefault )
23+
( HaddockFlags, TestFlags, fromFlagOrDefault )
2424
import Distribution.Simple.Command
2525
( CommandUI(..), usageAlternatives )
2626
import Distribution.Text
@@ -33,7 +33,7 @@ import Distribution.Simple.Utils
3333
import Control.Monad (when)
3434

3535

36-
benchCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
36+
benchCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags)
3737
benchCommand = Client.installCommand {
3838
commandName = "new-bench",
3939
commandSynopsis = "Run benchmarks",
@@ -73,9 +73,9 @@ benchCommand = Client.installCommand {
7373
-- For more details on how this works, see the module
7474
-- "Distribution.Client.ProjectOrchestration"
7575
--
76-
benchAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
76+
benchAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags)
7777
-> [String] -> GlobalFlags -> IO ()
78-
benchAction (configFlags, configExFlags, installFlags, haddockFlags)
78+
benchAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
7979
targetStrings globalFlags = do
8080

8181
baseCtx <- establishProjectBaseContext verbosity cliConfig
@@ -117,7 +117,7 @@ benchAction (configFlags, configExFlags, installFlags, haddockFlags)
117117
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
118118
cliConfig = commandLineFlagsToProjectConfig
119119
globalFlags configFlags configExFlags
120-
installFlags haddockFlags
120+
installFlags haddockFlags testFlags
121121

122122
-- | This defines what a 'TargetSelector' means for the @bench@ command.
123123
-- It selects the 'AvailableTarget's that the 'TargetSelector' refers to,

cabal-install/Distribution/Client/CmdBuild.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import Distribution.Client.Setup
2020
, liftOptions, yesNoOpt )
2121
import qualified Distribution.Client.Setup as Client
2222
import Distribution.Simple.Setup
23-
( HaddockFlags, Flag(..), toFlag, fromFlag, fromFlagOrDefault )
23+
( HaddockFlags, TestFlags
24+
, Flag(..), toFlag, fromFlag, fromFlagOrDefault )
2425
import Distribution.Simple.Command
2526
( CommandUI(..), usageAlternatives, option )
2627
import Distribution.Verbosity
@@ -31,7 +32,7 @@ import Distribution.Simple.Utils
3132
import qualified Data.Map as Map
3233

3334

34-
buildCommand :: CommandUI (BuildFlags, (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags))
35+
buildCommand :: CommandUI (BuildFlags, (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags))
3536
buildCommand = CommandUI {
3637
commandName = "new-build",
3738
commandSynopsis = "Compile targets within the project.",
@@ -95,10 +96,10 @@ defaultBuildFlags = BuildFlags
9596
-- For more details on how this works, see the module
9697
-- "Distribution.Client.ProjectOrchestration"
9798
--
98-
buildAction :: (BuildFlags, (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags))
99+
buildAction :: (BuildFlags, (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags))
99100
-> [String] -> GlobalFlags -> IO ()
100101
buildAction (buildFlags,
101-
(configFlags, configExFlags, installFlags, haddockFlags))
102+
(configFlags, configExFlags, installFlags, haddockFlags, testFlags))
102103
targetStrings globalFlags = do
103104
-- TODO: This flags defaults business is ugly
104105
let onlyConfigure = fromFlag (buildOnlyConfigure defaultBuildFlags
@@ -147,7 +148,7 @@ buildAction (buildFlags,
147148
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
148149
cliConfig = commandLineFlagsToProjectConfig
149150
globalFlags configFlags configExFlags
150-
installFlags haddockFlags
151+
installFlags haddockFlags testFlags
151152

152153
-- | This defines what a 'TargetSelector' means for the @bench@ command.
153154
-- It selects the 'AvailableTarget's that the 'TargetSelector' refers to,

cabal-install/Distribution/Client/CmdConfigure.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import Distribution.Client.ProjectConfig
1616
import Distribution.Client.Setup
1717
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
1818
import Distribution.Simple.Setup
19-
( HaddockFlags, fromFlagOrDefault )
19+
( HaddockFlags, TestFlags, fromFlagOrDefault )
2020
import Distribution.Verbosity
2121
( normal )
2222

@@ -27,7 +27,7 @@ import Distribution.Simple.Utils
2727
import qualified Distribution.Client.Setup as Client
2828

2929
configureCommand :: CommandUI (ConfigFlags, ConfigExFlags
30-
,InstallFlags, HaddockFlags)
30+
,InstallFlags, HaddockFlags, TestFlags)
3131
configureCommand = Client.installCommand {
3232
commandName = "new-configure",
3333
commandSynopsis = "Add extra project configuration",
@@ -78,9 +78,9 @@ configureCommand = Client.installCommand {
7878
-- For more details on how this works, see the module
7979
-- "Distribution.Client.ProjectOrchestration"
8080
--
81-
configureAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
81+
configureAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags)
8282
-> [String] -> GlobalFlags -> IO ()
83-
configureAction (configFlags, configExFlags, installFlags, haddockFlags)
83+
configureAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
8484
_extraArgs globalFlags = do
8585
--TODO: deal with _extraArgs, since flags with wrong syntax end up there
8686

@@ -121,5 +121,5 @@ configureAction (configFlags, configExFlags, installFlags, haddockFlags)
121121
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
122122
cliConfig = commandLineFlagsToProjectConfig
123123
globalFlags configFlags configExFlags
124-
installFlags haddockFlags
124+
installFlags haddockFlags testFlags
125125

cabal-install/Distribution/Client/CmdExec.hs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ import Distribution.Simple.GHC
7474
, GhcImplInfo(supportsPkgEnvFiles) )
7575
import Distribution.Simple.Setup
7676
( HaddockFlags
77+
, TestFlags
7778
, fromFlagOrDefault
7879
)
7980
import Distribution.Simple.Utils
@@ -94,7 +95,7 @@ import Data.Set (Set)
9495
import qualified Data.Set as S
9596
import qualified Data.Map as M
9697

97-
execCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
98+
execCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags)
9899
execCommand = CommandUI
99100
{ commandName = "new-exec"
100101
, commandSynopsis = "Give a command access to the store."
@@ -119,9 +120,9 @@ execCommand = CommandUI
119120
, commandDefaultFlags = commandDefaultFlags Client.installCommand
120121
}
121122

122-
execAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
123+
execAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags)
123124
-> [String] -> GlobalFlags -> IO ()
124-
execAction (configFlags, configExFlags, installFlags, haddockFlags)
125+
execAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
125126
extraArgs globalFlags = do
126127

127128
baseCtx <- establishProjectBaseContext verbosity cliConfig
@@ -193,7 +194,7 @@ execAction (configFlags, configExFlags, installFlags, haddockFlags)
193194
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
194195
cliConfig = commandLineFlagsToProjectConfig
195196
globalFlags configFlags configExFlags
196-
installFlags haddockFlags
197+
installFlags haddockFlags testFlags
197198
withOverrides env args program = program
198199
{ programOverrideEnv = programOverrideEnv program ++ env
199200
, programDefaultArgs = programDefaultArgs program ++ args}

cabal-install/Distribution/Client/CmdFreeze.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import Distribution.PackageDescription
3333
import Distribution.Client.Setup
3434
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
3535
import Distribution.Simple.Setup
36-
( HaddockFlags, fromFlagOrDefault )
36+
( HaddockFlags, TestFlags, fromFlagOrDefault )
3737
import Distribution.Simple.Utils
3838
( die', notice, wrapText )
3939
import Distribution.Verbosity
@@ -49,7 +49,7 @@ import Distribution.Simple.Command
4949
import qualified Distribution.Client.Setup as Client
5050

5151

52-
freezeCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
52+
freezeCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags)
5353
freezeCommand = Client.installCommand {
5454
commandName = "new-freeze",
5555
commandSynopsis = "Freeze dependencies.",
@@ -99,9 +99,9 @@ freezeCommand = Client.installCommand {
9999
-- For more details on how this works, see the module
100100
-- "Distribution.Client.ProjectOrchestration"
101101
--
102-
freezeAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
102+
freezeAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags)
103103
-> [String] -> GlobalFlags -> IO ()
104-
freezeAction (configFlags, configExFlags, installFlags, haddockFlags)
104+
freezeAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
105105
extraArgs globalFlags = do
106106

107107
unless (null extraArgs) $
@@ -130,7 +130,7 @@ freezeAction (configFlags, configExFlags, installFlags, haddockFlags)
130130
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
131131
cliConfig = commandLineFlagsToProjectConfig
132132
globalFlags configFlags configExFlags
133-
installFlags haddockFlags
133+
installFlags haddockFlags testFlags
134134

135135

136136

cabal-install/Distribution/Client/CmdHaddock.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Distribution.Client.Setup
2020
( GlobalFlags, ConfigFlags(..), ConfigExFlags, InstallFlags )
2121
import qualified Distribution.Client.Setup as Client
2222
import Distribution.Simple.Setup
23-
( HaddockFlags(..), fromFlagOrDefault )
23+
( HaddockFlags(..), TestFlags, fromFlagOrDefault )
2424
import Distribution.Simple.Command
2525
( CommandUI(..), usageAlternatives )
2626
import Distribution.Verbosity
@@ -32,7 +32,7 @@ import Control.Monad (when)
3232

3333

3434
haddockCommand :: CommandUI (ConfigFlags, ConfigExFlags, InstallFlags
35-
,HaddockFlags)
35+
,HaddockFlags, TestFlags)
3636
haddockCommand = Client.installCommand {
3737
commandName = "new-haddock",
3838
commandSynopsis = "Build Haddock documentation",
@@ -69,9 +69,9 @@ haddockCommand = Client.installCommand {
6969
-- For more details on how this works, see the module
7070
-- "Distribution.Client.ProjectOrchestration"
7171
--
72-
haddockAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags)
72+
haddockAction :: (ConfigFlags, ConfigExFlags, InstallFlags, HaddockFlags, TestFlags)
7373
-> [String] -> GlobalFlags -> IO ()
74-
haddockAction (configFlags, configExFlags, installFlags, haddockFlags)
74+
haddockAction (configFlags, configExFlags, installFlags, haddockFlags, testFlags)
7575
targetStrings globalFlags = do
7676

7777
baseCtx <- establishProjectBaseContext verbosity cliConfig
@@ -111,7 +111,7 @@ haddockAction (configFlags, configExFlags, installFlags, haddockFlags)
111111
verbosity = fromFlagOrDefault normal (configVerbosity configFlags)
112112
cliConfig = commandLineFlagsToProjectConfig
113113
globalFlags configFlags configExFlags
114-
installFlags haddockFlags
114+
installFlags haddockFlags testFlags
115115

116116
-- | This defines what a 'TargetSelector' means for the @haddock@ command.
117117
-- It selects the 'AvailableTarget's that the 'TargetSelector' refers to,

0 commit comments

Comments
 (0)