@@ -23,7 +23,19 @@ import Control.Exception
23
23
import Control.Monad
24
24
import GHC.Conc (numCapabilities )
25
25
import Data.List
26
+ import Data.Proxy (Proxy (Proxy ))
27
+ import qualified Data.Sequence as Seq (fromList )
26
28
import Text.Printf
29
+ import qualified Test.Tasty.Options as Tasty
30
+ ( OptionSet
31
+ , OptionDescription (Option )
32
+ , lookupOption
33
+ )
34
+ import qualified Test.Tasty.Runners as Tasty
35
+ ( optionParser
36
+ , TestPattern
37
+ , testPatternMatches
38
+ )
27
39
import qualified System.Clock as Clock
28
40
import System.IO
29
41
import System.FilePath
@@ -72,7 +84,8 @@ data MainArgs = MainArgs {
72
84
mainArgQuiet :: Bool ,
73
85
mainArgDistDir :: Maybe FilePath ,
74
86
mainArgCabalSpec :: Maybe CabalLibSpec ,
75
- mainCommonArgs :: CommonArgs
87
+ mainCommonArgs :: CommonArgs ,
88
+ mainTastyArgs :: Tasty. OptionSet
76
89
}
77
90
78
91
data CabalLibSpec = BootCabalLib | InTreeCabalLib FilePath FilePath | SpecificCabalLib String FilePath
@@ -117,6 +130,17 @@ mainArgParser = MainArgs
117
130
<> metavar " DIR" ))
118
131
<*> optional cabalLibSpecParser
119
132
<*> commonArgParser
133
+ <*> tastyArgParser
134
+
135
+ tastyArgParser :: Parser Tasty. OptionSet
136
+ tastyArgParser =
137
+ let (warnings, parser) =
138
+ Tasty. optionParser
139
+ [ Tasty. Option (Proxy @ Tasty. TestPattern )
140
+ ]
141
+ in if null warnings
142
+ then parser
143
+ else error $ unlines (" Failed to create parser for Tasty CLI options:" : warnings)
120
144
121
145
-- Unpack and build a specific released version of Cabal and Cabal-syntax libraries
122
146
buildCabalLibsProject :: String -> Verbosity -> Maybe FilePath -> FilePath -> IO [FilePath ]
@@ -184,6 +208,7 @@ main = do
184
208
-- Parse arguments. N.B. 'helper' adds the option `--help`.
185
209
args <- execParser $ info (mainArgParser <**> helper) mempty
186
210
let verbosity = if mainArgVerbose args then verbose else normal
211
+ testPattern = Tasty. lookupOption @ Tasty. TestPattern (mainTastyArgs args)
187
212
188
213
pkg_dbs <-
189
214
-- Not path to cabal-install so we're not going to run cabal-install tests so we
@@ -264,7 +289,7 @@ main = do
264
289
-- NB: getDirectoryContentsRecursive is lazy IO, but it
265
290
-- doesn't handle directories disappearing gracefully. Fix
266
291
-- this!
267
- (single_tests, multi_tests) <- evaluate (partitionTests test_scripts)
292
+ (single_tests, multi_tests) <- evaluate (partitionTests testPattern test_scripts)
268
293
let all_tests = multi_tests ++ single_tests
269
294
margin = maximum (map length all_tests) + 2
270
295
hPutStrLn stderr $ " tests to run: " ++ show (length all_tests)
@@ -381,10 +406,19 @@ main = do
381
406
findTests :: IO [FilePath ]
382
407
findTests = getDirectoryContentsRecursive " ."
383
408
384
- partitionTests :: [FilePath ] -> ([FilePath ], [FilePath ])
385
- partitionTests = go [] []
409
+ -- | Partition a list of paths into a tuple of test paths and multi-test paths.
410
+ --
411
+ -- Non-test paths and test paths that don't match the given `Tasty.TestPattern` are dropped.
412
+ partitionTests :: Tasty. TestPattern -> [FilePath ] -> ([FilePath ], [FilePath ])
413
+ partitionTests testPattern paths =
414
+ go [] [] paths
386
415
where
387
- go ts ms [] = (ts, ms)
416
+ -- Filter a list, keeping only paths that match the @pattern@.
417
+ keepPatternMatches = filter (Tasty. testPatternMatches testPattern . toTastyPath)
418
+
419
+ toTastyPath path = Seq. fromList $ splitDirectories path
420
+
421
+ go ts ms [] = (keepPatternMatches ts, keepPatternMatches ms)
388
422
go ts ms (f: fs) =
389
423
-- NB: Keep this synchronized with isTestFile
390
424
case takeExtensions f of
0 commit comments