diff --git a/ChangeLog.md b/ChangeLog.md index 6f26a1a..e8634be 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,9 @@ +## 0.3.3 + +- Change 'ediffGolden' so that parse errors in expected file don't cause the hard failure. + This way you may `--accept` new results even when expected files are broken, e.g. due merge conflict markers. + For now the change is a bit a hack to avoid breaking change in type-signature of `ediffGolden/1`. + ## 0.3.2 - Add 'ediffGolden1', a variant of 'ediffGolden' with an additional argument. diff --git a/src/Data/TreeDiff/Golden.hs b/src/Data/TreeDiff/Golden.hs index 5670965..8e1f292 100644 --- a/src/Data/TreeDiff/Golden.hs +++ b/src/Data/TreeDiff/Golden.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE ScopedTypeVariables #-} -- | "Golden tests" using 'ediff' comparison. module Data.TreeDiff.Golden ( ediffGolden, @@ -50,7 +51,7 @@ ediffGolden impl testName fp x = ediffGolden1 impl' testName fp (\() -> x) where -- @since 0.3.2 -- ediffGolden1 - :: (Eq a, ToExpr a) + :: forall a arg testName testTree. (Eq a, ToExpr a) => (testName -> IO Expr -> (arg -> IO Expr) -> (Expr -> Expr -> IO (Maybe String)) -> (Expr -> IO ()) -> testTree) -- ^ 'goldenTest' -> testName -- ^ test name -> FilePath -- ^ path to "golden file" @@ -58,12 +59,17 @@ ediffGolden1 -> testTree ediffGolden1 impl testName fp x = impl testName expect actual cmp wrt where + actual :: arg -> IO Expr actual arg = fmap toExpr (x arg) + + expect :: IO Expr expect = do contents <- BS.readFile fp case parse (exprParser <* eof) fp $ TE.decodeUtf8 contents of - Left err -> print err >> fail "parse error" + Left err -> return $ App "ParseError" [toExpr fp, toExpr (show err)] Right r -> return r + + cmp :: Expr -> Expr -> IO (Maybe [Char]) cmp a b | a == b = return Nothing | otherwise = return $ Just $ diff --git a/tree-diff.cabal b/tree-diff.cabal index d1dc439..16edfef 100644 --- a/tree-diff.cabal +++ b/tree-diff.cabal @@ -1,6 +1,6 @@ cabal-version: 2.2 name: tree-diff -version: 0.3.2 +version: 0.3.3 synopsis: Diffing of (expression) trees. category: Data, Testing description: