doctest 0.18.2 → 0.19.0
raw patch · 9 files changed
+76/−25 lines, 9 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- CHANGES.markdown +3/−0
- README.markdown +26/−0
- doctest.cabal +4/−8
- src/Interpreter.hs +13/−2
- src/Options.hs +5/−4
- src/Property.hs +0/−1
- test/InterpreterSpec.hs +12/−2
- test/RunSpec.hs +13/−5
- test/doctests.hs +0/−3
CHANGES.markdown view
@@ -1,3 +1,6 @@+Changes in 0.19.0+ - Better support for `cabal v2-*`+ Changes in 0.18.2 - GHC 9.2 compatibility. (#305, thanks to Ryan Scott and Matthew Pickering)
README.markdown view
@@ -352,6 +352,32 @@ [language-pragma]: http://www.haskell.org/ghc/docs/latest/html/users_guide/pragmas.html#language-pragma +### Limitations++Due to [a GHC bug](https://gitlab.haskell.org/ghc/ghc/-/issues/20670), running+`:set -XTemplateHaskell` within `ghci` may unload any modules that were+specified on the command line.++To address this `doctest >= 0.19.0` does two things:++1. Doctest always enables `-XTemplateHaskell`. So it is safe to use Template+ Haskell in examples without enabling the extension explicitly.+1. Doctest filters out `-XTemplateHaskell` from single-line `:set`-statements.+ So it is still safe to include `:set -XTemplateHaskell` in examples for+ documentation purposes. It may just not work as intended in `ghci` due to+ that GHC bug.++Doctest does not filter out `-XTemplateHaskell` from multi-line+`:set`-statements. So if you e.g. use++```+>>> :{+:set -XTemplateHaskell+:}+```+then you are on your own.++ ### Cabal integration Doctest provides both, an executable and a library. The library exposes a
doctest.cabal view
@@ -1,13 +1,11 @@-cabal-version: 1.12+cabal-version: 2.0 -- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack------ hash: 3c86bef70634c1ec5f684a059a0805713b8f747ef2dcaecf351c5f773410e4d2 name: doctest-version: 0.18.2+version: 0.19.0 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>).@@ -140,7 +138,6 @@ Runner.Example Util Language.Haskell.GhciWrapper- Paths_doctest build-depends: base >=4.5 && <5 , base-compat >=0.7.0@@ -158,8 +155,6 @@ executable doctest main-is: Main.hs- other-modules:- Paths_doctest ghc-options: -Wall -threaded hs-source-dirs: driver@@ -231,7 +226,6 @@ Test.DocTest Util Language.Haskell.GhciWrapper- Paths_doctest type: exitcode-stdio-1.0 ghc-options: -Wall -threaded cpp-options: -DTEST@@ -241,6 +235,8 @@ ghci-wrapper/src c-sources: test/integration/with-cbits/foo.c+ build-tool-depends:+ hspec-discover:hspec-discover build-depends: HUnit , QuickCheck >=2.13.1
src/Interpreter.hs view
@@ -11,6 +11,7 @@ -- exported for testing , ghcInfo , haveInterpreterKey+, filterExpression ) where import System.Process@@ -55,6 +56,7 @@ let args = flags ++ [ "--interactive"+ , xTemplateHaskell #if __GLASGOW_HASKELL__ >= 802 , "-fdiagnostics-color=never" , "-fno-diagnostics-show-caret"@@ -62,6 +64,9 @@ ] bracket (new defaultConfig{configGhci = ghc} args) close action +xTemplateHaskell :: String+xTemplateHaskell = "-XTemplateHaskell"+ -- | Evaluate an expression; return a Left value on exceptions. -- -- An exception may e.g. be caused on unterminated multiline expressions.@@ -75,11 +80,17 @@ filterExpression e = case lines e of [] -> Right e- l -> if firstLine == ":{" && lastLine /= ":}" then fail_ else Right e+ l -> if firstLine == ":{" && lastLine /= ":}" then err else Right (filterXTemplateHaskell e) where firstLine = strip $ head l lastLine = strip $ last l- fail_ = Left "unterminated multiline command"+ err = Left "unterminated multi-line command" where strip :: String -> String strip = dropWhile isSpace . reverse . dropWhile isSpace . reverse++filterXTemplateHaskell :: String -> String+filterXTemplateHaskell input = case words input of+ [":set", setting] | setting == xTemplateHaskell -> ""+ ":set" : xs | xTemplateHaskell `elem` xs -> unwords $ ":set" : filter (/= xTemplateHaskell) xs+ _ -> input
src/Options.hs view
@@ -25,9 +25,6 @@ import Data.List.Compat (intercalate, stripPrefix) import Data.Monoid (Endo (Endo)) -import qualified Paths_doctest-import Data.Version (showVersion)- #if __GLASGOW_HASKELL__ < 900 import Config as GHC #else@@ -54,7 +51,11 @@ ] version :: String-version = showVersion Paths_doctest.version+#ifdef CURRENT_PACKAGE_VERSION+version = CURRENT_PACKAGE_VERSION+#else+version = "unknown"+#endif ghcVersion :: String ghcVersion = GHC.cProjectVersion
src/Property.hs view
@@ -30,7 +30,6 @@ _ <- Interpreter.safeEval repl "import Test.QuickCheck ((==>))" _ <- Interpreter.safeEval repl "import Test.QuickCheck.All (polyQuickCheck)" _ <- Interpreter.safeEval repl "import Language.Haskell.TH (mkName)"- _ <- Interpreter.safeEval repl ":set -XTemplateHaskell" r <- freeVariables repl expression >>= (Interpreter.safeEval repl . quickCheck expression) case r of
test/InterpreterSpec.hs view
@@ -5,7 +5,7 @@ import Test.Hspec -import Interpreter (interpreterSupported, haveInterpreterKey, ghcInfo, withInterpreter, safeEval)+import Interpreter (interpreterSupported, haveInterpreterKey, ghcInfo, withInterpreter, safeEval, filterExpression) main :: IO () main = hspec spec@@ -27,4 +27,14 @@ Interpreter.safeEval ghci "23 + 42" `shouldReturn` Right "65\n" it "returns Left on unterminated multiline command" $ withInterpreter [] $ \ghci -> do- Interpreter.safeEval ghci ":{\n23 + 42" `shouldReturn` Left "unterminated multiline command"+ Interpreter.safeEval ghci ":{\n23 + 42" `shouldReturn` Left "unterminated multi-line command"++ describe "filterExpression" $ do+ it "removes :set -XTemplateHaskell" $ do+ filterExpression ":set -XTemplateHaskell" `shouldBe` Right ""++ it "filters -XTemplateHaskell" $ do+ filterExpression ":set -XTemplateHaskell -XCPP" `shouldBe` Right ":set -XCPP"++ it "leaves :set-statement that do not set -XTemplateHaskell alone " $ do+ filterExpression ":set -XFoo -XBar" `shouldBe` Right ":set -XFoo -XBar"
test/RunSpec.hs view
@@ -29,6 +29,14 @@ main :: IO () main = hspec spec ++removeLoadedPackageEnvironment :: String -> String+#if __GLASGOW_HASKELL__ < 810+removeLoadedPackageEnvironment = unlines . filter (not . isPrefixOf "Loaded package environment from ") . lines+#else+removeLoadedPackageEnvironment = id+#endif+ spec :: Spec spec = do describe "doctest" $ do@@ -59,14 +67,14 @@ it "prints error message on invalid option" $ do (r, e) <- hCapture [stderr] . E.try $ doctest ["--foo", "test/integration/test-options/Foo.hs"] e `shouldBe` Left (ExitFailure 1)- r `shouldBe` unlines [+ removeLoadedPackageEnvironment r `shouldBe` unlines [ "doctest: unrecognized option `--foo'" , "Try `doctest --help' for more information." ] it "prints verbose description of a specification" $ do (r, ()) <- hCapture [stderr] $ doctest ["--verbose", "test/integration/testSimple/Fib.hs"]- r `shouldBe` unlines [+ removeLoadedPackageEnvironment r `shouldBe` unlines [ "### Started execution at test/integration/testSimple/Fib.hs:5." , "### example:" , "fib 10"@@ -78,7 +86,7 @@ it "prints verbose description of a property" $ do (r, ()) <- hCapture [stderr] $ doctest ["--verbose", "test/integration/property-bool/Foo.hs"]- r `shouldBe` unlines [+ removeLoadedPackageEnvironment r `shouldBe` unlines [ "### Started execution at test/integration/property-bool/Foo.hs:4." , "### property:" , "True"@@ -91,7 +99,7 @@ it "prints verbose error" $ do (r, e) <- hCapture [stderr] . E.try $ doctest ["--verbose", "test/integration/failing/Foo.hs"] e `shouldBe` Left (ExitFailure 1)- r `shouldBe` unlines [+ removeLoadedPackageEnvironment r `shouldBe` unlines [ "### Started execution at test/integration/failing/Foo.hs:5." , "### example:" , "23"@@ -125,7 +133,7 @@ #if __GLASGOW_HASKELL__ < 800 r `shouldBe` "\nFoo.hs:6:1:\n parse error (possibly incorrect indentation or mismatched brackets)\n" #else- r `shouldBe` "\nFoo.hs:6:1: error:\n parse error (possibly incorrect indentation or mismatched brackets)\n"+ removeLoadedPackageEnvironment r `shouldBe` "\nFoo.hs:6:1: error:\n parse error (possibly incorrect indentation or mismatched brackets)\n" #endif #endif
test/doctests.hs view
@@ -7,9 +7,6 @@ "-packageghc" , "-isrc" , "-ighci-wrapper/src"- , "-idist/build/autogen/"- , "-optP-include"- , "-optPdist/build/autogen/cabal_macros.h" , "src/Run.hs" , "src/PackageDBs.hs" ]