From f7aa1fadd1b37685e0d73da58b6a626cf89f2778 Mon Sep 17 00:00:00 2001 From: Simon Michael Date: Fri, 16 May 2025 10:46:50 -1000 Subject: [PATCH] fix:test: fix and improve pass-through of arguments to tasty [#2386] --- hledger/Hledger/Cli/Commands.hs | 12 ++++++++---- hledger/Hledger/Cli/Commands/Test.md | 15 ++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/hledger/Hledger/Cli/Commands.hs b/hledger/Hledger/Cli/Commands.hs index 4da675294..2ab6a2d0b 100644 --- a/hledger/Hledger/Cli/Commands.hs +++ b/hledger/Hledger/Cli/Commands.hs @@ -474,9 +474,9 @@ testmode = hledgerCommandMode [] ([], Just $ argsFlag "[-- TASTYOPTS]") --- | The test command, which runs the hledger and hledger-lib --- packages' unit tests. This command also accepts tasty test runner --- options, written after a -- (double hyphen). +-- | The test command, which runs the hledger and hledger-lib packages' unit tests. +-- Arguments following a -- argument will be passed to the tasty test runner, +-- and any arguments before -- will be passed as test-selecting -p patterns. -- -- Unlike most hledger commands, this one does not read the user's journal. -- A 'Journal' argument remains in the type signature, but it should @@ -484,7 +484,11 @@ testmode = hledgerCommandMode -- testcmd :: CliOpts -> Journal -> IO () testcmd opts _undefined = do - withArgs (listofstringopt "args" $ rawopts_ opts) $ + let + args = listofstringopt "args" $ rawopts_ opts + (hledgerargs, tastyargs0) = break (== "--") args + tastyargs = dbg1 "tastyargs" $ ["-p " <> a | a <- hledgerargs] ++ drop 1 tastyargs0 + withArgs tastyargs $ Test.Tasty.defaultMain $ testGroup "hledger" [ tests_Hledger ,tests_Hledger_Cli diff --git a/hledger/Hledger/Cli/Commands/Test.md b/hledger/Hledger/Cli/Commands/Test.md index a04890551..ec5f89e27 100644 --- a/hledger/Hledger/Cli/Commands/Test.md +++ b/hledger/Hledger/Cli/Commands/Test.md @@ -16,11 +16,12 @@ sanity-check the installed hledger executable on your platform. All tests are expected to pass - if you ever see a failure, please report as a bug! -This command also accepts tasty test runner options, written after a --- (double hyphen). Eg to run only the tests in Hledger.Data.Amount, -with ANSI colour codes disabled: -```cli -$ hledger test -- -pData.Amount --color=never +Any arguments before a `--` argument will be passed to the `tasty` test runner as test-selecting -p patterns, +and any arguments after `--` will be passed to tasty unchanged. + +Examples: +``` +$ hledger test # run all unit tests +$ hledger test balance # run tests with "balance" in their name +$ hledger test -- -h # show tasty's options ``` -For help on these, see https://github.com/feuerbach/tasty#options -(`-- --help` currently doesn't show them).