packages feed

tasty-golden 2.2.0.2 → 2.2.1

raw patch · 5 files changed

+112/−18 lines, 5 filesdep +deepseqdep ~optparse-applicativedep ~tasty

Dependencies added: deepseq

Dependency ranges changed: optparse-applicative, tasty

Files

+ CHANGELOG.md view
@@ -0,0 +1,42 @@+Changes+=======++Version 2.2.1+-------------++* Fix a bug where the result of the comparison function would reference yet+  unread data from a semiclosed file and the file gets closed, leading to a+  runtime exception+* Export `writeBinaryFile`+* Improve the docs+* Update to work with `tasty-0.8`++Version 2.2.0.2+---------------++Update to work with `tasty-0.7`++Version 2.2.0.1+---------------++Update to work with `tasty-0.5`++Version 2.2+-----------++Migrate to ingredients++Version 2.1+-----------++Add `goldenVsStringDiff`++Version 2.0.1+-------------++Update to work with `tasty-0.2`++Version 2.0+-----------++Initial release of `tasty-golden` (derived from `test-framework-golden-1.1.x`)
Test/Tasty/Golden.hs view
@@ -1,12 +1,53 @@ {- | This module provides a simplified interface. If you want more, see "Test.Tasty.Golden.Advanced".++Note about filenames. They are looked up in the usual way, thus relative+names are relative to the processes current working directory.+It is common to run tests from the package's root directory (via @cabal+test@ or @cabal install --enable-tests@), so if your test files are under+the @tests\/@ subdirectory, your relative file names should start with+@tests\/@ (even if your @test.hs@ is itself under @tests\/@, too).++Note about line endings. The best way to avoid headaches with line endings+(when running tests both on UNIX and Windows) is to treat your golden files+as binary, even when they are actually textual.++This means:++* When writing output files from Haskell code, open them in binary mode+(see 'openBinaryFile', 'withBinaryFile' and 'hSetBinaryMode'). This will+disable automatic @\\n -> \\r\\n@ conversion on Windows. For convenience, this+module exports 'writeBinaryFile' which is just like `writeFile` but opens+the file in binary mode. When using 'ByteString's note that+"Data.ByteString" and "Data.ByteString.Lazy" use binary mode for+@writeFile@, while "Data.ByteString.Char8" and "Data.ByteString.Lazy.Char8"+use text mode.++* Tell your VCS not to do any newline conversion for golden files. For+ git check in a @.gitattributes@ file with the following contents (assuming+ your golden files have @.golden@ extension):++>*.golden	-text++On its side, tasty-golden reads and writes files in binary mode, too.++Why not let Haskell/git do automatic conversion on Windows? Well, for+instance, @tar@ will not do the conversion for you when unpacking a release+tarball, so when you run @cabal install your-package --enable-tests@, the+tests will be broken.++As a last resort, you can strip all @\\r@s from both arguments in your+comparison function when necessary. But most of the time treating the files+as binary does the job. -}+ module Test.Tasty.Golden   ( goldenVsFile   , goldenVsString   , goldenVsFileDiff   , goldenVsStringDiff+  , writeBinaryFile   )   where @@ -21,6 +62,7 @@ import System.FilePath import Control.Exception import Control.Monad+import Control.DeepSeq  -- trick to avoid an explicit dependency on transformers import Control.Monad.Error (liftIO)@@ -94,7 +136,7 @@     (_, Just sout, _, pid) <- createProcess (proc (head cmd) (tail cmd)) { std_out = CreatePipe }     -- strictly read the whole output, so that the process can terminate     out <- hGetContents sout-    evaluate $ length out+    evaluate . rnf $ out      r <- waitForProcess pid     return $ case r of@@ -137,7 +179,7 @@     (_, Just sout, _, pid) <- createProcess (proc (head cmd) (tail cmd)) { std_out = CreatePipe }     -- strictly read the whole output, so that the process can terminate     out <- hGetContents sout-    _ <- evaluate $ length out+    evaluate . rnf $ out      r <- waitForProcess pid     return $ case r of@@ -145,3 +187,7 @@       _ -> Just (printf "Test output was different from '%s'. Output of %s:\n%s" ref (show cmd) out)    upd = LB.writeFile ref++-- | Like 'writeFile', but uses binary mode+writeBinaryFile :: FilePath -> String -> IO ()+writeBinaryFile f txt = withBinaryFile f WriteMode (\hdl -> hPutStr hdl txt)
Test/Tasty/Golden/Internal.hs view
@@ -2,14 +2,14 @@     MultiParamTypeClasses, GeneralizedNewtypeDeriving #-} module Test.Tasty.Golden.Internal where -import Data.Typeable (Typeable) import Control.Applicative import Control.Monad.Cont-import Test.Tasty.Providers-import Data.ByteString.Lazy as LB+import Control.DeepSeq import Control.Exception+import Data.Typeable (Typeable)+import Data.ByteString.Lazy as LB import System.IO-import Data.Maybe+import Test.Tasty.Providers  -- | See 'goldenTest' for explanation of the fields data Golden =@@ -46,19 +46,21 @@ vgRun (ValueGetter a) = runContT a evaluate  instance IsTest Golden where-  run opts golden _ = runGolden golden+  run _ golden _ = runGolden golden   testOptions = return []  runGolden :: Golden -> IO Result runGolden (Golden getGolden getTested cmp _) = do-  result <- vgRun $ do+  vgRun $ do     new <- getTested     ref <- getGolden-    liftIO $ cmp ref new+    result <- liftIO $ cmp ref new -  return $     case result of-      Just reason ->-        Result False reason+      Just reason -> do+        -- Make sure that the result is fully evaluated and doesn't depend+        -- on yet un-read lazy input+        liftIO $ evaluate . rnf $ reason+        return $ testFailed reason       Nothing ->-        Result True ""+        return $ testPassed ""
Test/Tasty/Golden/Manage.hs view
@@ -18,14 +18,13 @@ import Test.Tasty.Runners import Test.Tasty.Options import Test.Tasty.Golden.Internal-import Data.Maybe import Data.Typeable import Data.Tagged import Data.Proxy+import Data.Maybe import Control.Monad.Cont import Text.Printf import Options.Applicative-import System.Exit  -- | Like @defaultMain@ from the main tasty package, but also includes the -- golden test management capabilities.
tasty-golden.cabal view
@@ -1,5 +1,5 @@ name:                tasty-golden-version:             2.2.0.2+version:             2.2.1 synopsis:            Golden tests support for tasty description:   This package provides support for «golden testing».@@ -18,6 +18,7 @@ category:            Testing build-type:          Simple cabal-version:       >=1.8+extra-source-files:  CHANGELOG.md  Source-repository head   type:     git@@ -29,13 +30,17 @@                        Test.Tasty.Golden.Manage   other-modules:                        Test.Tasty.Golden.Internal++  ghc-options: -Wall+   build-depends:     base ==4.*,-    tasty >= 0.7,+    tasty >= 0.8,     bytestring,     process,     mtl,     optparse-applicative,     filepath,     temporary >= 1.1,-    tagged+    tagged,+    deepseq