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

Adds --no-magic flag #156

Closed
wants to merge 1 commit into from
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
3 changes: 2 additions & 1 deletion src/Help.hs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import Interpreter (ghc)
usage :: String
usage = unlines [
"Usage:"
, " doctest [ GHC OPTION | MODULE ]..."
, " doctest [ --no-magic | GHC OPTION | MODULE ]..."
, " doctest --help"
, " doctest --version"
, ""
, "Options:"
, " --help display this help and exit"
, " --version output version information and exit"
, " --no-magic no directory expansion, and no argument discovery."
]

printVersion :: IO ()
Expand Down
19 changes: 17 additions & 2 deletions src/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ doctest args0
| "--help" `elem` args0 = putStr usage
| "--version" `elem` args0 = printVersion
| otherwise = do
args <- concat <$> mapM expandDirs args0
let (noMagic, args1) = stripNoMagic args0
args <- concat <$> mapM expandDirs args1
i <- Interpreter.interpreterSupported
unless i $ do
hPutStrLn stderr "WARNING: GHC does not support --interactive, skipping tests"
Expand All @@ -62,7 +63,7 @@ doctest args0
let addPackageConf = (packageDBArgs ++)
addDistArgs <- getAddDistArgs

r <- doctest_ (addDistArgs $ addPackageConf args_) `E.catch` \e -> do
r <- doctest_ (if noMagic then args1 else (addDistArgs $ addPackageConf args_)) `E.catch` \e -> do
case fromException e of
Just (UsageError err) -> do
hPutStrLn stderr ("doctest: " ++ err)
Expand Down Expand Up @@ -139,6 +140,20 @@ stripOptGhc = go
"--optghc" : opt : rest -> (True, opt : snd (go rest))
opt : rest -> maybe (fmap (opt :)) (\x (_, xs) -> (True, x :xs)) (stripPrefix "--optghc=" opt) (go rest)

-- |
-- Strip --no-magic from the options. Running doctest with --no-magic neither
-- expands directories nor tries to be smart about locating the package db.
--
-- A boolean is returned with the stipped arguments. It is True if striping
-- occurred.
stripNoMagic :: [String] -> (Bool, [String])
stripNoMagic = go
where
go args = case args of
[] -> (False, [])
"--no-magic" : opt : rest -> (True, opt : snd (go rest))
opt : rest -> (opt :) <$> (go rest)

doctest_ :: [String] -> IO Summary
doctest_ args = do

Expand Down