lib: doctests: file pattern arguments, more informative output
Limiting to just the file(s) you're interested can make doctest start much quicker. With a big caveat: you can limit the starting files, but it will also test all other local files those import.
This commit is contained in:
parent
df430e5eb0
commit
46d6971da7
@ -1,5 +1,20 @@
|
|||||||
|
{-
|
||||||
|
Runs hledger doctests.
|
||||||
|
Usage examples: in hledger source dir,
|
||||||
|
make ghci-doctest, :main [--verbose] [--slow] [CIFILEPATHSUBSTRINGS]
|
||||||
|
or:
|
||||||
|
stack test hledger-lib:test:doctests [--test-arguments '[--verbose] [--slow] [CIFILEPATHSUBSTRINGS]']
|
||||||
|
|
||||||
|
Arguments are case-insensitive file path substrings.
|
||||||
|
--verbose shows files being searched for doctests and progress while running.
|
||||||
|
--slow reloads ghci between each test (https://github.com/sol/doctest#a-note-on-performance).
|
||||||
|
|
||||||
|
-}
|
||||||
|
|
||||||
{-# LANGUAGE PackageImports #-}
|
{-# LANGUAGE PackageImports #-}
|
||||||
|
|
||||||
|
import Control.Monad
|
||||||
|
import Data.Char
|
||||||
import Data.List
|
import Data.List
|
||||||
import System.Environment
|
import System.Environment
|
||||||
import "Glob" System.FilePath.Glob
|
import "Glob" System.FilePath.Glob
|
||||||
@ -7,14 +22,35 @@ import Test.DocTest
|
|||||||
|
|
||||||
main = do
|
main = do
|
||||||
args <- getArgs
|
args <- getArgs
|
||||||
fs1 <- glob "Hledger/**/*.hs"
|
let
|
||||||
fs2 <- glob "Text/**/*.hs"
|
verbose = "--verbose" `elem` args
|
||||||
--fs3 <- glob "other/ledger-parse/**/*.hs"
|
slow = "--slow" `elem` args
|
||||||
let fs = filter (not . isInfixOf "/.") $ ["Hledger.hs"] ++ fs1 ++ fs2
|
pats = filter (not . ("-" `isPrefixOf`)) args
|
||||||
doctest $
|
|
||||||
-- show verbose progress output
|
-- find source files
|
||||||
(if "--verbose" `elem` args then ("--verbose" :) else id) $
|
sourcefiles1 <- glob "Hledger/**/*.hs"
|
||||||
-- don't reload environment per test (opposite of doctest's --fast,
|
sourcefiles2 <- glob "Text/**/*.hs"
|
||||||
-- https://github.com/sol/doctest#a-note-on-performance)
|
let sourcefiles = filter (not . isInfixOf "/.") $ ["Hledger.hs"] ++ sourcefiles1 ++ sourcefiles2
|
||||||
(if "--slow" `elem` args then id else ("--fast" :)) $
|
|
||||||
fs
|
-- filter by patterns (case insensitive infix substring match)
|
||||||
|
let
|
||||||
|
fs | null pats = sourcefiles
|
||||||
|
| otherwise = [f | f <- sourcefiles, let f' = map toLower f, any (`isInfixOf` f') pats']
|
||||||
|
where pats' = map (map toLower) pats
|
||||||
|
fslen = length fs
|
||||||
|
|
||||||
|
if (null fs)
|
||||||
|
then do
|
||||||
|
putStrLn $ "No file paths found matching: " ++ unwords pats
|
||||||
|
|
||||||
|
else do
|
||||||
|
putStrLn $
|
||||||
|
"Loading and searching for doctests in "
|
||||||
|
++ show fslen
|
||||||
|
++ if fslen > 1 then " files, plus any files they import:" else " file, plus any files it imports:"
|
||||||
|
when verbose $ putStrLn $ unwords fs
|
||||||
|
|
||||||
|
doctest $
|
||||||
|
(if verbose then ("--verbose" :) else id) $
|
||||||
|
(if slow then id else ("--fast" :)) $
|
||||||
|
fs
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user