From 6e851d63f0e086e58d846818335df57fb872c295 Mon Sep 17 00:00:00 2001 From: George Thomas Date: Tue, 9 Dec 2025 16:47:12 +0000 Subject: [PATCH] Show diff for golden test failures --- haskell/Main.hs | 2 +- haskell/Pre.hs | 4 ++++ haskell/Puzzles/Day4.hs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/haskell/Main.hs b/haskell/Main.hs index 39af2f4..4aaf91c 100644 --- a/haskell/Main.hs +++ b/haskell/Main.hs @@ -43,7 +43,7 @@ main = withResource (parseFile $ "../inputs/" <> t <> "/" <> pt) mempty \input -> testGroup pt $ ( zip (map show [1 :: Int ..]) parts <&> \(n, pp) -> - goldenVsString n ("../outputs/" <> t <> "/" <> pt <> "/" <> n) $ + goldenVsStringDiff n diffCommand ("../outputs/" <> t <> "/" <> pt <> "/" <> n) $ TL.encodeUtf8 . pp <$> input ) <> [testGroup "extra" $ extraTests isRealData ("../outputs/" <> t <> "/" <> pt <> "/extra/") input] diff --git a/haskell/Pre.hs b/haskell/Pre.hs index 89157ed..d472881 100644 --- a/haskell/Pre.hs +++ b/haskell/Pre.hs @@ -41,6 +41,7 @@ module Pre ( allUnorderedPairs, adjacentPairs, sortPair, + diffCommand, ) where @@ -122,3 +123,6 @@ adjacentPairs = \case sortPair :: (Ord a) => (a, a) -> (a, a) sortPair (a, b) = if a <= b then (a, b) else (b, a) + +diffCommand :: FilePath -> FilePath -> [String] +diffCommand a b = ["diff", "--color=always", a, b] diff --git a/haskell/Puzzles/Day4.hs b/haskell/Puzzles/Day4.hs index 74411dc..1be6346 100644 --- a/haskell/Puzzles/Day4.hs +++ b/haskell/Puzzles/Day4.hs @@ -31,7 +31,7 @@ puzzle = let frames = Seq.fromList . takeUntil noneAccessible . fmap snd . generateFrames . mkGrid <$> input nFrames = if isRealData then 58 else 9 in ( [0 .. nFrames] <&> \n -> - goldenVsString (show n) (path <> "frames/" <> show n) $ + goldenVsStringDiff (show n) diffCommand (path <> "frames/" <> show n) $ TL.encodeUtf8 . maybe "frame list too short!" drawGrid . Seq.lookup n <$> frames ) <> [ testCase "end" do