doctest 0.18 → 0.18.1
raw patch · 12 files changed
+328/−185 lines, 12 filesdep +exceptionsdep ~ghcnew-uploaderPVP ok
version bump matches the API change (PVP)
Dependencies added: exceptions
Dependency ranges changed: ghc
API changes (from Hackage documentation)
Files
- CHANGES +0/−144
- CHANGES.markdown +147/−0
- doctest.cabal +23/−8
- src/Extract.hs +22/−3
- src/GhcUtil.hs +14/−0
- src/Location.hs +12/−1
- src/Options.hs +72/−23
- src/Run.hs +5/−0
- test/ExtractSpec.hs +8/−1
- test/LocationSpec.hs +8/−0
- test/MainSpec.hs +12/−4
- test/extract/th/Bar.hs +5/−1
− CHANGES
@@ -1,144 +0,0 @@-Changes in 0.18- - Don't use unqualified references to `stderr` or `stdout` which may collide with definitions in user code. (#201)- - Remove support for cabal-install sandboxes. They have been obsoleted in practice by Nix-style builds in cabal-install (i.e., the `v2-*` commands) and stack.--Changes in 0.17- - #266:- - doctest now annotates its internal marker string as a `String`, to prevent misbehaviour in `OverloadedStrings` environments. This has a theoretical chance of breakage; if you're affected, please open an issue.- - `evalEcho` no longer preserves `it`.--Changes in 0.16.3- - Add a cursor to highlight the differing portion between the- expected and actual output. (#249)- - GHC 8.10 compatibility. (#247, #257)--Changes in 0.16.2- - Add doctest's necessary-for-operation options to GHC's command- line at the end, so that they over-ride anything provided by the- user. (#233)- - Allow GHC 8.8.--Changes in 0.16.1- - Fix loading plugins in doctests. (#224)- - Require QuickCheck 2.13.1 or newer.- - Remove dependency on `with-location`--Changes in 0.16.0.1- - Bump bounds to allow GHC 8.6. (#210)--Changes in 0.16.0- - Output format has changed to (hopefully) be more machine consumable. (#200)--Changes in 0.15.0- - Add `--verbose` for printing each test as it is run--Changes in 0.14.1- - Add test assets to source tarball (see #189)--Changes in 0.14.0- - GHC 8.4 compatibility.--Changes in 0.13.0- - Add `--preserve-it` for allowing the `it` variable to be preserved between examples--Changes in 0.12.0- - Preserve the 'it' variable between examples--Changes in 0.11.4- - Add `--fast`, which disables running `:reload` between example groups--Changes in 0.11.3- - Add `--info`- - Add `--no-magic`--Changes in 0.11.2- - Make `...` match zero lines--Changes in 0.11.1- - Fix an issue with Unicode output on Windows (see #149)--Changes in 0.11.0- - Support for GHC 8.0.1-rc2--Changes in 0.10.1- - Automatically expand directories into contained Haskell source files (thanks @snoyberg)- - Add cabal_macros.h and autogen dir by default (thanks @snoyberg)--Changes in 0.10.0- - Support HASKELL_PACKAGE_SANDBOXES (thanks @snoyberg)--Changes in 0.9.13- - Add ellipsis as wildcard--Changes in 0.9.12- - Add support for GHC 7.10--Changes in 0.9.11- - Defaults ambiguous type variables to Integer (#74)--Changes in 0.9.10- - Add support for the upcoming GHC 7.8 release--Changes in 0.9.9- - Add support for multi-line statements--Changes in 0.9.8- - Support for GHC HEAD (7.7)--Changes in 0.9.7- - Ignore trailing whitespace when matching example output--Changes in 0.9.6- - Fail gracefully if GHCi is not supported (#46)--Changes in 0.9.5- - Fix a GHC panic with GHC 7.6.1 (#41)--Changes in 0.9.4- - Respect HASKELL_PACKAGE_SANDBOX (#39)- - Print path to ghc on --version--Changes in 0.9.3- - Properly handle additional object files (#38)--Changes in 0.9.2- - Add support for QuickCheck properties--Changes in 0.9.1- - Fix an issue with GHC 7.6.1 and type families--Changes in 0.9.0- - Add support for setup code (see README).- - There is no distinction between example/interaction anymore. Each- expression is counted as an example in the summary.--Changes in 0.8.0- - Doctest now directly accepts arbitrary GHC options, prefixing GHC options- with --optghc is no longer necessary--Changes in 0.7.0- - Print source location for failing tests- - Output less clutter on failing examples- - Expose Doctest's functionality through a very simplistic API, which can be- used for cabal integration--Changes in 0.6.1- - Fix a parser bug with CR+LF line endings--Changes in 0.6.0- - Support for ghc-7.4- - Doctest now comes with it's own parser and does not depend on Haddock- anymore--Changes in 0.5.2- - Proper handling of singular/plural when printing stats- - Improve handling of invalid command line options--Changes in 0.5.1- - Adapted for ghc-7.2--Changes in 0.5.0- - Print number of interactions to stderr before running tests- - Exit with exitFailure on failed tests- - Improve documentation- - Give a useful error message if ghc is not executable
+ CHANGES.markdown view
@@ -0,0 +1,147 @@+Changes in 0.19+ - GHC 9.0 compatibility. (#275)++Changes in 0.18+ - Don't use unqualified references to `stderr` or `stdout` which may collide with definitions in user code. (#201)+ - Remove support for cabal-install sandboxes. They have been obsoleted in practice by Nix-style builds in cabal-install (i.e., the `v2-*` commands) and stack.++Changes in 0.17+ - #266:+ - doctest now annotates its internal marker string as a `String`, to prevent misbehaviour in `OverloadedStrings` environments. This has a theoretical chance of breakage; if you're affected, please open an issue.+ - `evalEcho` no longer preserves `it`.++Changes in 0.16.3+ - Add a cursor to highlight the differing portion between the+ expected and actual output. (#249)+ - GHC 8.10 compatibility. (#247, #257)++Changes in 0.16.2+ - Add doctest's necessary-for-operation options to GHC's command+ line at the end, so that they over-ride anything provided by the+ user. (#233)+ - Allow GHC 8.8.++Changes in 0.16.1+ - Fix loading plugins in doctests. (#224)+ - Require QuickCheck 2.13.1 or newer.+ - Remove dependency on `with-location`++Changes in 0.16.0.1+ - Bump bounds to allow GHC 8.6. (#210)++Changes in 0.16.0+ - Output format has changed to (hopefully) be more machine consumable. (#200)++Changes in 0.15.0+ - Add `--verbose` for printing each test as it is run++Changes in 0.14.1+ - Add test assets to source tarball (see #189)++Changes in 0.14.0+ - GHC 8.4 compatibility.++Changes in 0.13.0+ - Add `--preserve-it` for allowing the `it` variable to be preserved between examples++Changes in 0.12.0+ - Preserve the 'it' variable between examples++Changes in 0.11.4+ - Add `--fast`, which disables running `:reload` between example groups++Changes in 0.11.3+ - Add `--info`+ - Add `--no-magic`++Changes in 0.11.2+ - Make `...` match zero lines++Changes in 0.11.1+ - Fix an issue with Unicode output on Windows (see #149)++Changes in 0.11.0+ - Support for GHC 8.0.1-rc2++Changes in 0.10.1+ - Automatically expand directories into contained Haskell source files (thanks @snoyberg)+ - Add cabal_macros.h and autogen dir by default (thanks @snoyberg)++Changes in 0.10.0+ - Support HASKELL_PACKAGE_SANDBOXES (thanks @snoyberg)++Changes in 0.9.13+ - Add ellipsis as wildcard++Changes in 0.9.12+ - Add support for GHC 7.10++Changes in 0.9.11+ - Defaults ambiguous type variables to Integer (#74)++Changes in 0.9.10+ - Add support for the upcoming GHC 7.8 release++Changes in 0.9.9+ - Add support for multi-line statements++Changes in 0.9.8+ - Support for GHC HEAD (7.7)++Changes in 0.9.7+ - Ignore trailing whitespace when matching example output++Changes in 0.9.6+ - Fail gracefully if GHCi is not supported (#46)++Changes in 0.9.5+ - Fix a GHC panic with GHC 7.6.1 (#41)++Changes in 0.9.4+ - Respect HASKELL_PACKAGE_SANDBOX (#39)+ - Print path to ghc on --version++Changes in 0.9.3+ - Properly handle additional object files (#38)++Changes in 0.9.2+ - Add support for QuickCheck properties++Changes in 0.9.1+ - Fix an issue with GHC 7.6.1 and type families++Changes in 0.9.0+ - Add support for setup code (see README).+ - There is no distinction between example/interaction anymore. Each+ expression is counted as an example in the summary.++Changes in 0.8.0+ - Doctest now directly accepts arbitrary GHC options, prefixing GHC options+ with --optghc is no longer necessary++Changes in 0.7.0+ - Print source location for failing tests+ - Output less clutter on failing examples+ - Expose Doctest's functionality through a very simplistic API, which can be+ used for cabal integration++Changes in 0.6.1+ - Fix a parser bug with CR+LF line endings++Changes in 0.6.0+ - Support for ghc-7.4+ - Doctest now comes with it's own parser and does not depend on Haddock+ anymore++Changes in 0.5.2+ - Proper handling of singular/plural when printing stats+ - Improve handling of invalid command line options++Changes in 0.5.1+ - Adapted for ghc-7.2++Changes in 0.5.0+ - Print number of interactions to stderr before running tests+ - Exit with exitFailure on failed tests+ - Improve documentation+ - Give a useful error message if ghc is not executable
doctest.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.34.3. -- -- see: https://github.com/sol/hpack ----- hash: a5f986d148ee2304fff5f9d670fcb819b4c821e8f1c9f43497020870a53475ef+-- hash: a7c307d4c3548326994e6fb1f8f2e96fd825cb9ba3cf2ed3cc6ea352a2554436 name: doctest-version: 0.18+version: 0.18.1 synopsis: Test interactive Haskell examples description: The doctest program checks examples in source code comments. It is modeled after doctest for Python (<https://docs.python.org/3/library/doctest.html>).@@ -22,6 +22,17 @@ author: Simon Hengel <sol@typeful.net> maintainer: quasicomputational <quasicomputational@gmail.com> build-type: Simple+tested-with:+ GHC == 7.6.3+ , GHC == 7.8.4+ , GHC == 7.10.3+ , GHC == 8.0.2+ , GHC == 8.2.2+ , GHC == 8.4.4+ , GHC == 8.6.5+ , GHC == 8.8.4+ , GHC == 8.10.4+ , GHC == 9.0.1 extra-source-files: example/example.cabal example/src/Example.hs@@ -100,7 +111,7 @@ test/integration/trailing-whitespace/Foo.hs test/integration/with-cbits/Bar.hs test/integration/with-cbits/foo.c- CHANGES+ CHANGES.markdown README.markdown source-repository head@@ -135,8 +146,9 @@ , code-page >=0.1 , deepseq , directory+ , exceptions , filepath- , ghc >=7.0 && <8.11+ , ghc >=7.0 && <9.1 , ghc-paths >=0.1.0.9 , process , syb >=0.3@@ -157,8 +169,9 @@ , deepseq , directory , doctest+ , exceptions , filepath- , ghc >=7.0 && <8.11+ , ghc >=7.0 && <9.1 , ghc-paths >=0.1.0.9 , process , syb >=0.3@@ -178,8 +191,9 @@ , deepseq , directory , doctest+ , exceptions , filepath- , ghc >=7.0 && <8.11+ , ghc >=7.0 && <9.1 , ghc-paths >=0.1.0.9 , process , syb >=0.3@@ -234,8 +248,9 @@ , code-page >=0.1 , deepseq , directory+ , exceptions , filepath- , ghc >=7.0 && <8.11+ , ghc >=7.0 && <9.1 , ghc-paths >=0.1.0.9 , hspec >=2.3.0 , hspec-core >=2.3.0
src/Extract.hs view
@@ -19,12 +19,25 @@ #if __GLASGOW_HASKELL__ < 707 import GHC hiding (flags, Module, Located) import MonadUtils (liftIO, MonadIO)-#else+#elif __GLASGOW_HASKELL__ < 900 import GHC hiding (Module, Located) import DynFlags import MonadUtils (liftIO)+#else+import GHC hiding (Module, Located)+import GHC.Driver.Session+import GHC.Utils.Monad (liftIO) #endif++#if __GLASGOW_HASKELL__ < 900+import Digraph (flattenSCCs) import Exception (ExceptionMonad)+#else+import GHC.Data.Graph.Directed (flattenSCCs)+import GHC.Utils.Exception (ExceptionMonad)+import Control.Monad.Catch (generalBracket)+#endif+ import System.Directory import System.FilePath @@ -37,8 +50,6 @@ import FastString (unpackFS) #endif -import Digraph (flattenSCCs)- import System.Posix.Internals (c_getpid) import GhcUtil (withGhc)@@ -48,8 +59,12 @@ import PackageDBs (getPackageDBArgs) #if __GLASGOW_HASKELL__ >= 806+#if __GLASGOW_HASKELL__ < 900 import DynamicLoading (initializePlugins)+#else+import GHC.Runtime.Loader (initializePlugins) #endif+#endif -- | A wrapper around `SomeException`, to allow for a custom `Show` instance. newtype ExtractError = ExtractError SomeException@@ -159,7 +174,11 @@ -- | A variant of 'gbracket' where the return value from the first computation -- is not required. gbracket_ :: ExceptionMonad m => m a -> m b -> m c -> m c+#if __GLASGOW_HASKELL__ < 900 gbracket_ before_ after thing = gbracket before_ (const after) (const thing)+#else+ gbracket_ before_ after thing = fst <$> generalBracket before_ (\ _ _ -> after) (const thing)+#endif setOutputDir f d = d { objectDir = Just f
src/GhcUtil.hs view
@@ -8,11 +8,25 @@ import DynFlags (dopt_set) #else import GHC+#if __GLASGOW_HASKELL__ < 900 import DynFlags (gopt_set)+#else+import GHC.Driver.Session (gopt_set) #endif+#endif++#if __GLASGOW_HASKELL__ < 900 import Panic (throwGhcException)+#else+import GHC.Utils.Panic (throwGhcException)+#endif +#if __GLASGOW_HASKELL__ < 900 import MonadUtils (liftIO)+#else+import GHC.Utils.Monad (liftIO)+#endif+ import System.Exit (exitFailure) #if __GLASGOW_HASKELL__ < 702
src/Location.hs view
@@ -2,9 +2,16 @@ module Location where import Control.DeepSeq (deepseq, NFData(rnf))++#if __GLASGOW_HASKELL__ < 900 import SrcLoc hiding (Located) import qualified SrcLoc as GHC import FastString (unpackFS)+#else+import GHC.Types.SrcLoc hiding (Located)+import qualified GHC.Types.SrcLoc as GHC+import GHC.Data.FastString (unpackFS)+#endif #if __GLASGOW_HASKELL__ < 702 import Outputable (showPpr)@@ -60,8 +67,12 @@ | otherwise = (UnhelpfulLocation . showPpr) start where start = srcSpanStart loc-#else+#elif __GLASGOW_HASKELL__ < 900 toLocation loc = case loc of UnhelpfulSpan str -> UnhelpfulLocation (unpackFS str) RealSrcSpan sp -> Location (unpackFS . srcSpanFile $ sp) (srcSpanStartLine sp)+#else+toLocation loc = case loc of+ UnhelpfulSpan str -> UnhelpfulLocation (unpackFS $ unhelpfulSpanFS str)+ RealSrcSpan sp _ -> Location (unpackFS . srcSpanFile $ sp) (srcSpanStartLine sp) #endif
src/Options.hs view
@@ -18,12 +18,22 @@ import Prelude () import Prelude.Compat +import Control.Monad.Trans.RWS (RWS, execRWS)+import qualified Control.Monad.Trans.RWS as RWS++import Control.Monad (when) import Data.List.Compat-import Data.Maybe+import Data.Monoid (Endo (Endo)) import qualified Paths_doctest import Data.Version (showVersion)++#if __GLASGOW_HASKELL__ < 900 import Config as GHC+#else+import GHC.Settings.Config as GHC+#endif+ import Interpreter (ghc) usage :: String@@ -89,40 +99,79 @@ defaultVerbose :: Bool defaultVerbose = False +defaultRun :: Run+defaultRun = Run {+ runWarnings = []+, runOptions = []+, runMagicMode = defaultMagic+, runFastMode = defaultFastMode+, runPreserveIt = defaultPreserveIt+, runVerbose = defaultVerbose+}++modifyWarnings :: ([String] -> [String]) -> Run -> Run+modifyWarnings f run = run { runWarnings = f (runWarnings run) }++setOptions :: [String] -> Run -> Run+setOptions opts run = run { runOptions = opts }++setMagicMode :: Bool -> Run -> Run+setMagicMode magic run = run { runMagicMode = magic }++setFastMode :: Bool -> Run -> Run+setFastMode fast run = run { runFastMode = fast }++setPreserveIt :: Bool -> Run -> Run+setPreserveIt preserveIt run = run { runPreserveIt = preserveIt }++setVerbose :: Bool -> Run -> Run+setVerbose verbose run = run { runVerbose = verbose }+ parseOptions :: [String] -> Result Run parseOptions args | "--help" `elem` args = Output usage | "--info" `elem` args = Output info | "--version" `elem` args = Output versionInfo- | otherwise = case fmap (fmap (fmap stripOptGhc))- . fmap (fmap stripVerbose)- . fmap stripPreserveIt- . stripFast- <$> stripNoMagic args of- (magicMode, (fastMode, (preserveIt, (verbose, (warning, xs))))) ->- Result (Run (maybeToList warning) xs magicMode fastMode preserveIt verbose)+ | otherwise = case execRWS parse () args of+ (xs, Endo setter) ->+ Result (setOptions xs $ setter defaultRun)+ where+ parse :: RWS () (Endo Run) [String] ()+ parse = do+ stripNoMagic+ stripFast+ stripPreserveIt+ stripVerbose+ stripOptGhc -stripNoMagic :: [String] -> (Bool, [String])-stripNoMagic = stripFlag (not defaultMagic) "--no-magic"+stripNoMagic :: RWS () (Endo Run) [String] ()+stripNoMagic = stripFlag (setMagicMode False) "--no-magic" -stripFast :: [String] -> (Bool, [String])-stripFast = stripFlag (not defaultFastMode) "--fast"+stripFast :: RWS () (Endo Run) [String] ()+stripFast = stripFlag (setFastMode True) "--fast" -stripPreserveIt :: [String] -> (Bool, [String])-stripPreserveIt = stripFlag (not defaultPreserveIt) "--preserve-it"+stripPreserveIt :: RWS () (Endo Run) [String] ()+stripPreserveIt = stripFlag (setPreserveIt True) "--preserve-it" -stripVerbose :: [String] -> (Bool, [String])-stripVerbose = stripFlag (not defaultVerbose) "--verbose"+stripVerbose :: RWS () (Endo Run) [String] ()+stripVerbose = stripFlag (setVerbose True) "--verbose" -stripFlag :: Bool -> String -> [String] -> (Bool, [String])-stripFlag enableIt flag args = ((flag `elem` args) == enableIt, filter (/= flag) args)+stripFlag :: (Run -> Run) -> String -> RWS () (Endo Run) [String] ()+stripFlag setter flag = do+ args <- RWS.get+ when (flag `elem` args) $+ RWS.tell (Endo setter)+ RWS.put (filter (/= flag) args) -stripOptGhc :: [String] -> (Maybe Warning, [String])-stripOptGhc = go+stripOptGhc :: RWS () (Endo Run) [String] ()+stripOptGhc = do+ issueWarning <- RWS.state go+ when issueWarning $+ RWS.tell $ Endo $ modifyWarnings (++ [warning]) where go args = case args of- [] -> (Nothing, [])- "--optghc" : opt : rest -> (Just warning, opt : snd (go rest))- opt : rest -> maybe (fmap (opt :)) (\x (_, xs) -> (Just warning, x : xs)) (stripPrefix "--optghc=" opt) (go rest)+ [] -> (False, [])+ "--optghc" : opt : rest -> (True, opt : snd (go rest))+ opt : rest -> maybe (fmap (opt :)) (\x (_, xs) -> (True, x : xs)) (stripPrefix "--optghc=" opt) (go rest) warning = "WARNING: --optghc is deprecated, doctest now accepts arbitrary GHC options\ndirectly."
src/Run.hs view
@@ -20,7 +20,12 @@ import System.IO.CodePage (withCP65001) import qualified Control.Exception as E++#if __GLASGOW_HASKELL__ < 900 import Panic+#else+import GHC.Utils.Panic+#endif import PackageDBs import Parse
test/ExtractSpec.hs view
@@ -1,11 +1,18 @@-{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE CPP #-} {-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE FlexibleContexts #-}+ module ExtractSpec (main, spec) where import Test.Hspec import Test.HUnit ++#if __GLASGOW_HASKELL__ < 900 import Panic (GhcException (..))+#else+import GHC.Utils.Panic (GhcException (..))+#endif import Extract import Location
test/LocationSpec.hs view
@@ -1,10 +1,18 @@+{-# LANGUAGE CPP #-}+ module LocationSpec (main, spec) where import Test.Hspec import Location++#if __GLASGOW_HASKELL__ < 900 import SrcLoc import FastString (fsLit)+#else+import GHC.Types.SrcLoc+import GHC.Data.FastString (fsLit)+#endif main :: IO () main = hspec spec
test/MainSpec.hs view
@@ -106,9 +106,18 @@ doctest "setup-skip-on-failure" ["Foo.hs"] (cases 3) {sTried = 1, sFailures = 1} - it "works with additional object files" $ do- doctest "with-cbits" ["Bar.hs", "../../../dist/build/spec/spec-tmp/test/integration/with-cbits/foo.o"]- (cases 1)+ -- Andreas, 2021-02-27, see issue #294.+ -- This test case contains a hard-wired path that does not work+ -- with v2-cabal.+ -- I tested it under v2-cabal with a very non-portable path.+ -- Deactivating the test case until a systematic solution is found...+ --+ -- it "works with additional object files" $ do+ -- -- -- Path for v1-cabal:+ -- -- doctest "with-cbits" ["Bar.hs", "../../../dist/build/spec/spec-tmp/test/integration/with-cbits/foo.o"]+ -- -- -- Path for v2-cabal with ghc-9.0.1+ -- -- doctest "with-cbits" ["Bar.hs", "../../../dist-newstyle/build/x86_64-osx/ghc-9.0.1/doctest-0.19/t/spec/build/spec/spec-tmp/Test/integration/with-cbits/foo.o"]+ -- (cases 1) it "ignores trailing whitespace when matching test output" $ do doctest "trailing-whitespace" ["Foo.hs"]@@ -175,4 +184,3 @@ it "doesn't get confused by doctests using System.IO imports" $ do doctest "system-io-imported" ["A.hs"] (cases 1)-
test/extract/th/Bar.hs view
@@ -1,4 +1,8 @@ {-# LANGUAGE TemplateHaskell #-}+ module Bar where -bar = [|23|]+import Language.Haskell.TH.Lib (ExpQ)++bar :: ExpQ+bar = [| 23 |]