Skip to content

Commit

Permalink
Merge pull request #96 from haskellari/soft-parse-error
Browse files Browse the repository at this point in the history
Make ediffGolden fail gracefully on parse error
  • Loading branch information
phadej authored Nov 30, 2024
2 parents 3bc46be + 1b31b5d commit f25aa77
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
10 changes: 8 additions & 2 deletions src/Data/TreeDiff/Golden.hs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{-# LANGUAGE ScopedTypeVariables #-}
-- | "Golden tests" using 'ediff' comparison.
module Data.TreeDiff.Golden (
ediffGolden,
Expand Down Expand Up @@ -50,20 +51,25 @@ 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"
-> (arg -> IO a) -- ^ result value
-> 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 $
Expand Down
2 changes: 1 addition & 1 deletion tree-diff.cabal
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit f25aa77

Please sign in to comment.