packages feed

hspec-golden 0.1.0.1 → 0.1.0.2

raw patch · 6 files changed

+52/−28 lines, 6 filesPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

API changes (from Hackage documentation)

+ Test.Hspec.Golden: [failFirstTime] :: Golden str -> Bool
- Test.Hspec.Golden: Golden :: str -> (str -> String) -> (FilePath -> str -> IO ()) -> (FilePath -> IO str) -> String -> FilePath -> Golden str
+ Test.Hspec.Golden: Golden :: str -> (str -> String) -> (FilePath -> str -> IO ()) -> (FilePath -> IO str) -> String -> FilePath -> Bool -> Golden str

Files

ChangeLog.md view
@@ -1,5 +1,10 @@ # Changelog for hspec-golden +## 0.1.0.2+#### Add+* CLI updates tests recursively #19+* Allow first execution to fail #16+ ## 0.1.0.1 #### Add * CLI changed to work with optparse-applicative.
LICENSE view
@@ -1,4 +1,4 @@-Copyright Stack Builders (c) 2019+Copyright Stack Builders (c) 2019-2020  All rights reserved. 
README.md view
@@ -44,7 +44,8 @@     writeToFile = T.writeFile,     readFromFile = T.readFile,     testName = name,-    directory = ".myGoldenTestDir"+    directory = ".myGoldenTestDir",+    failFirstTime = False   }  describe "myTextFunc" $
app/Main.hs view
@@ -5,8 +5,8 @@ import           Paths_hspec_golden    (version) import           Options.Applicative import           Data.Monoid ((<>))-import           System.Directory      (doesFileExist, listDirectory,-                                        renameFile)+import           System.Directory      (doesDirectoryExist, doesFileExist,+                                        listDirectory, renameFile) import qualified Test.Hspec.Golden     as G  defaultDirGoldenTest :: FilePath@@ -41,14 +41,22 @@ updateGolden :: FilePath -> IO () updateGolden dir = do   putStrLn "Replacing golden with actual..."-  goldenTests <- listDirectory dir-  forM_ goldenTests (mvActualToGolden dir)+  go dir   putStrLn "Finish..."+ where+  go dir = do+    entries <- listDirectory dir+    forM_ entries $ \entry -> do+      let entryInDir = dir ++ "/" ++ entry+      isDir <- doesDirectoryExist entryInDir+      when isDir $ do+        mvActualToGolden entryInDir+        go entryInDir -mvActualToGolden :: FilePath -> FilePath -> IO ()-mvActualToGolden goldenDir testName =-  let actualFilePath = goldenDir ++ "/" ++ testName ++ "/" ++ "actual"-      goldenFilePath = goldenDir ++ "/" ++ testName ++ "/" ++ "golden"+mvActualToGolden :: FilePath -> IO ()+mvActualToGolden testPath =+  let actualFilePath = testPath ++ "/actual"+      goldenFilePath = testPath ++ "/golden"    in do      actualFileExist <- doesFileExist actualFilePath      when actualFileExist (do
hspec-golden.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.31.2.+-- This file has been generated from package.yaml by hpack version 0.33.1. -- -- see: https://github.com/sol/hpack ----- hash: 47827519449632063e1d3d47aaedfb8a42618dfbcf2406caefab51c360611a22+-- hash: a35e55cff149f915e3e5a385717c03730159ae8ac6ccee1967031d55df1f9f99  name:           hspec-golden-version:        0.1.0.1+version:        0.1.0.2 synopsis:       Golden tests for hspec description:    Please see the README on GitHub at <https://github.com/stackbuilders/hspec-golden#README> category:       Testing@@ -15,7 +15,7 @@ bug-reports:    https://github.com/stackbuilders/hspec-golden/issues author:         Stack Builders maintainer:     cmotoche@stackbuilders.com-copyright:      2019 Stack Builders Inc+copyright:      2019-2020 Stack Builders Inc license:        MIT license-file:   LICENSE build-type:     Simple
src/Test/Hspec/Golden.hs view
@@ -1,7 +1,7 @@ {-| Module      : Test.Hspec.Golden Description : Golden tests for Hspec-Copyright   : Stack Builders (c), 2019+Copyright   : Stack Builders (c), 2019-2020 License     : MIT Maintainer  : cmotoche@stackbuilders.com Stability   : experimental@@ -44,7 +44,8 @@ --     writeToFile = T.writeFile, --     readFromFile = T.readFile, --     testName = name,---     directory = ".specific-golden-dir"+--     directory = ".specific-golden-dir",+--     failFirstTime = False --   } -- -- describe "myTextFunc" $@@ -54,12 +55,13 @@  data Golden str =   Golden {-    output       :: str, -- ^ Output-    encodePretty :: str -> String, -- ^ Makes the comparison pretty when the test fails-    writeToFile  :: FilePath -> str -> IO (), -- ^ How to write into the golden file the file-    readFromFile :: FilePath -> IO str, -- ^ How to read the file,-    testName     :: String, -- ^ Test name (make sure it's unique otherwise it could be override)-    directory    :: FilePath -- ^ Directory where you write your tests+    output        :: str, -- ^ Output+    encodePretty  :: str -> String, -- ^ Makes the comparison pretty when the test fails+    writeToFile   :: FilePath -> str -> IO (), -- ^ How to write into the golden file the file+    readFromFile  :: FilePath -> IO str, -- ^ How to read the file,+    testName      :: String, -- ^ Test name (make sure it's unique otherwise it could be override)+    directory     :: FilePath, -- ^ Directory where you write your tests+    failFirstTime :: Bool -- ^ Whether to record a failure the first time this test is run   }  instance Eq str => Example (Golden str) where@@ -78,8 +80,11 @@ -- | Transform a GoldenResult into a Result from Hspec  fromGoldenResult :: GoldenResult -> Result-fromGoldenResult FirstExecution  = Result "First time execution. Golden file created." Success-fromGoldenResult SameOutput      = Result "Golden and Actual output hasn't changed" Success+fromGoldenResult SameOutput             = Result "Golden and Actual output hasn't changed" Success+fromGoldenResult FirstExecutionSucceed  = Result "First time execution. Golden file created." Success+fromGoldenResult FirstExecutionFail =+  Result "First time execution. Golden file created."+         (Failure Nothing (Reason "failFirstTime is set to True")) fromGoldenResult (MissmatchOutput expected actual) =   Result "Files golden and actual not match"          (Failure Nothing (ExpectedButGot Nothing expected actual))@@ -101,7 +106,8 @@     testName = name,     writeToFile = writeFile,     readFromFile = readFile,-    directory = ".golden"+    directory = ".golden",+    failFirstTime = False   }  -- | Possible results from a golden test execution@@ -109,7 +115,8 @@ data GoldenResult =    MissmatchOutput String String    | SameOutput-   | FirstExecution+   | FirstExecutionSucceed+   | FirstExecutionFail  -- | Runs a Golden test. @@ -127,8 +134,11 @@      writeToFile actualFilePath output       if not goldenFileExist-       then writeToFile goldenFilePath output-            >> return FirstExecution+       then do+           writeToFile goldenFilePath output+           return $ if failFirstTime+               then FirstExecutionFail+               else FirstExecutionSucceed        else do           contentGolden <- readFromFile goldenFilePath