Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --tasty-arg to validate.sh #10425

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cabal-testsuite/cabal-testsuite.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ executable cabal-tests
-- dependencies specific to exe:cabal-tests
, clock ^>= 0.7.2 || ^>=0.8
, directory
, tasty
, containers

build-tool-depends: cabal-testsuite:setup
default-extensions: TypeOperators
Expand Down
44 changes: 39 additions & 5 deletions cabal-testsuite/main/cabal-tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@
import Control.Monad
import GHC.Conc (numCapabilities)
import Data.List
import Data.Proxy (Proxy(Proxy))
import qualified Data.Sequence as Seq (fromList)
import Text.Printf
import qualified Test.Tasty.Options as Tasty
( OptionSet
, OptionDescription (Option)
, lookupOption
)
import qualified Test.Tasty.Runners as Tasty
( optionParser
, TestPattern
, testPatternMatches
)
import qualified System.Clock as Clock
import System.IO
import System.FilePath
Expand Down Expand Up @@ -72,7 +84,8 @@
mainArgQuiet :: Bool,
mainArgDistDir :: Maybe FilePath,
mainArgCabalSpec :: Maybe CabalLibSpec,
mainCommonArgs :: CommonArgs
mainCommonArgs :: CommonArgs,
mainTastyArgs :: Tasty.OptionSet
}

data CabalLibSpec = BootCabalLib | InTreeCabalLib FilePath FilePath | SpecificCabalLib String FilePath
Expand Down Expand Up @@ -117,6 +130,17 @@
<> metavar "DIR"))
<*> optional cabalLibSpecParser
<*> commonArgParser
<*> tastyArgParser

tastyArgParser :: Parser Tasty.OptionSet
tastyArgParser =
let (warnings, parser) =
Tasty.optionParser
[ Tasty.Option (Proxy @Tasty.TestPattern)
]
in if null warnings
then parser
else error $ unlines ("Failed to create parser for Tasty CLI options:" : warnings)

-- Unpack and build a specific released version of Cabal and Cabal-syntax libraries
buildCabalLibsProject :: String -> Verbosity -> Maybe FilePath -> FilePath -> IO [FilePath]
Expand Down Expand Up @@ -184,6 +208,7 @@
-- Parse arguments. N.B. 'helper' adds the option `--help`.
args <- execParser $ info (mainArgParser <**> helper) mempty
let verbosity = if mainArgVerbose args then verbose else normal
testPattern = Tasty.lookupOption @Tasty.TestPattern (mainTastyArgs args)

pkg_dbs <-
-- Not path to cabal-install so we're not going to run cabal-install tests so we
Expand Down Expand Up @@ -264,7 +289,7 @@
-- NB: getDirectoryContentsRecursive is lazy IO, but it
-- doesn't handle directories disappearing gracefully. Fix
-- this!
(single_tests, multi_tests) <- evaluate (partitionTests test_scripts)
(single_tests, multi_tests) <- evaluate (partitionTests testPattern test_scripts)
let all_tests = multi_tests ++ single_tests
margin = maximum (map length all_tests) + 2
hPutStrLn stderr $ "tests to run: " ++ show (length all_tests)
Expand Down Expand Up @@ -381,10 +406,19 @@
findTests :: IO [FilePath]
findTests = getDirectoryContentsRecursive "."

partitionTests :: [FilePath] -> ([FilePath], [FilePath])
partitionTests = go [] []
-- | Partition a list of paths into a tuple of test paths and multi-test paths.
--
-- Non-test paths and test paths that don't match the given `Tasty.TestPattern` are dropped.
partitionTests :: Tasty.TestPattern -> [FilePath] -> ([FilePath], [FilePath])
partitionTests pattern paths =

Check failure on line 413 in cabal-testsuite/main/cabal-tests.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: on input `pattern' ▫︎ Found: " -- Non-test paths and test paths that don't match the given `Tasty.TestPattern` are dropped.\n partitionTests :: Tasty.TestPattern -> [FilePath] -> ([FilePath], [FilePath])\n> partitionTests pattern paths =\n go [] [] paths\n where\n"
go [] [] paths
where
go ts ms [] = (ts, ms)
-- Filter a list, keeping only paths that match the @pattern@.
keepPatternMatches = filter (Tasty.testPatternMatches pattern . toTastyPath)

toTastyPath path = Seq.fromList $ splitDirectories path

go ts ms [] = (keepPatternMatches ts, keepPatternMatches ms)
go ts ms (f:fs) =
-- NB: Keep this synchronized with isTestFile
case takeExtensions f of
Expand Down
15 changes: 12 additions & 3 deletions cabal-validate/src/Cli.hs
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,11 @@

tastyArgs' =
"--hide-successes"
: case rawTastyPattern opts of
Just tastyPattern -> ["--pattern", tastyPattern]
Nothing -> []
: maybe
[]
(\pattern -> ["--pattern", pattern])

Check failure on line 239 in cabal-validate/src/Cli.hs

View workflow job for this annotation

GitHub Actions / hlint

Error: Parse error: on input `pattern' ▫︎ Found: " : maybe\n []\n> (\\pattern -> [\"--pattern\", pattern])\n (rawTastyPattern opts)\n ++ rawTastyArgs opts\n"
(rawTastyPattern opts)
++ rawTastyArgs opts

when (rawListSteps opts) $ do
-- TODO: This should probably list _all_ available steps, not just the selected ones!
Expand Down Expand Up @@ -279,6 +281,7 @@
, rawCabal :: FilePath
, rawExtraCompilers :: [FilePath]
, rawTastyPattern :: Maybe String
, rawTastyArgs :: [String]
, rawDoctest :: Bool
, rawSteps :: [Step]
, rawListSteps :: Bool
Expand Down Expand Up @@ -343,6 +346,12 @@
<> help "Pattern to filter tests by"
<> value Nothing
)
<*> many
( strOption
( long "tasty-arg"
<> help "Extra arguments to pass to Tasty test suites"
)
)
<*> boolOption
False
"doctest"
Expand Down
Loading