doctest 0.11.3 → 0.11.4
raw patch · 4 files changed
+34/−24 lines, 4 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- doctest.cabal +1/−1
- src/Options.hs +17/−9
- src/Run.hs +6/−6
- src/Runner.hs +10/−8
doctest.cabal view
@@ -1,5 +1,5 @@ name: doctest-version: 0.11.3+version: 0.11.4 synopsis: Test interactive Haskell examples description: The doctest program checks examples in source code comments. It is modeled after doctest for Python
src/Options.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE CPP #-}+{-# LANGUAGE DeriveFunctor #-} module Options ( Result(..) , Run(..)@@ -24,12 +25,13 @@ usage :: String usage = unlines [ "Usage:"- , " doctest [ --no-magic | GHC OPTION | MODULE ]..."+ , " doctest [ --fast | --no-magic | GHC OPTION | MODULE ]..." , " doctest --help" , " doctest --version" , " doctest --info" , "" , "Options:"+ , " --fast disable :reload between example groups" , " --help display this help and exit" , " --version output version information and exit" , " --info output machine-readable version information and exit"@@ -55,8 +57,8 @@ , ("ghc", ghc) ]) ++ "\n]\n" -data Result = Output String | Result Run- deriving (Eq, Show)+data Result a = Output String | Result a+ deriving (Eq, Show, Functor) type Warning = String @@ -64,20 +66,26 @@ runWarnings :: [Warning] , runOptions :: [String] , runMagicMode :: Bool+, runFastMode :: Bool } deriving (Eq, Show) -parseOptions :: [String] -> Result+parseOptions :: [String] -> Result Run parseOptions args | "--help" `elem` args = Output usage | "--info" `elem` args = Output info | "--version" `elem` args = Output versionInfo- | otherwise = case stripOptGhc <$> stripNoMagic args of- (magicMode, (warning, xs)) -> Result (Run (maybeToList warning) xs magicMode)+ | otherwise = case fmap stripOptGhc . stripFast <$> stripNoMagic args of+ (magicMode, (fastMode, (warning, xs))) ->+ Result (Run (maybeToList warning) xs magicMode fastMode) stripNoMagic :: [String] -> (Bool, [String])-stripNoMagic args = (noMagic `notElem` args, filter (/= noMagic) args)- where- noMagic = "--no-magic"+stripNoMagic = stripFlag False "--no-magic"++stripFast :: [String] -> (Bool, [String])+stripFast = stripFlag True "--fast"++stripFlag :: Bool -> String -> [String] -> (Bool, [String])+stripFlag enableIt flag args = ((flag `elem` args) == enableIt, filter (/= flag) args) stripOptGhc :: [String] -> (Maybe Warning, [String]) stripOptGhc = go
src/Run.hs view
@@ -2,7 +2,7 @@ module Run ( doctest #ifdef TEST-, doctest_+, doctestWithFastMode , Summary , expandDirs #endif@@ -43,7 +43,7 @@ doctest :: [String] -> IO () doctest args0 = case parseOptions args0 of Output s -> putStr s- Result (Run warnings args_ magicMode) -> do+ Result (Run warnings args_ magicMode fastMode) -> do mapM_ (hPutStrLn stderr) warnings hFlush stderr @@ -60,7 +60,7 @@ addDistArgs <- getAddDistArgs return (addDistArgs $ packageDBArgs ++ expandedArgs) - r <- doctest_ args `E.catch` \e -> do+ r <- doctestWithFastMode fastMode args `E.catch` \e -> do case fromException e of Just (UsageError err) -> do hPutStrLn stderr ("doctest: " ++ err)@@ -123,11 +123,11 @@ isSuccess :: Summary -> Bool isSuccess s = sErrors s == 0 && sFailures s == 0 -doctest_ :: [String] -> IO Summary-doctest_ args = do+doctestWithFastMode :: Bool -> [String] -> IO Summary+doctestWithFastMode fastMode args = do -- get examples from Haddock comments modules <- getDocTests args Interpreter.withInterpreter args $ \repl -> withCP65001 $ do- runModules repl modules+ runModules fastMode repl modules
src/Runner.hs view
@@ -52,11 +52,11 @@ (Summary x1 x2 x3 x4) `mappend` (Summary y1 y2 y3 y4) = Summary (x1 + y1) (x2 + y2) (x3 + y3) (x4 + y4) -- | Run all examples from a list of modules.-runModules :: Interpreter -> [Module [Located DocTest]] -> IO Summary-runModules repl modules = do+runModules :: Bool -> Interpreter -> [Module [Located DocTest]] -> IO Summary+runModules fastMode repl modules = do isInteractive <- hIsTerminalDevice stderr ReportState _ _ s <- (`execStateT` ReportState 0 isInteractive mempty {sExamples = c}) $ do- forM_ modules $ runModule repl+ forM_ modules $ runModule fastMode repl -- report final summary gets (show . reportStateSummary) >>= report@@ -107,8 +107,8 @@ liftIO (hPutStr stderr str) -- | Run all examples from given module.-runModule :: Interpreter -> Module [Located DocTest] -> Report ()-runModule repl (Module module_ setup examples) = do+runModule :: Bool -> Interpreter -> Module [Located DocTest] -> Report ()+runModule fastMode repl (Module module_ setup examples) = do Summary _ _ e0 f0 <- gets reportStateSummary @@ -124,9 +124,11 @@ where reload :: IO () reload = do- -- NOTE: It is important to do the :reload first! There was some odd bug- -- with a previous version of GHC (7.4.1?).- void $ Interpreter.safeEval repl ":reload"+ unless fastMode $+ -- NOTE: It is important to do the :reload first! See+ -- https://ghc.haskell.org/trac/ghc/ticket/5904, which results in a+ -- panic on GHC 7.4.1 if you do the :reload second.+ void $ Interpreter.safeEval repl ":reload" void $ Interpreter.safeEval repl $ ":m *" ++ module_ setup_ :: IO ()