From 47bcdb045bf98a629de193b6739a03c265bb1948 Mon Sep 17 00:00:00 2001 From: Lennart Spitzner Date: Fri, 12 May 2023 12:01:31 +0000 Subject: [PATCH] Amend output of golden-tests to avoid confusion --- brittany.cabal | 2 ++ source/test-suite/Main.hs | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/brittany.cabal b/brittany.cabal index 6afadea..1643adf 100644 --- a/brittany.cabal +++ b/brittany.cabal @@ -170,6 +170,8 @@ test-suite brittany-test-suite build-depends: , hspec >= 2.8.3 && < 2.10 + , HUnit >= 1.6.2 && < 1.7 + , ansi-terminal >= 0.11.4 && < 0.12 , parsec ^>= 3.1.14 , these ^>= 1.1 hs-source-dirs: source/test-suite diff --git a/source/test-suite/Main.hs b/source/test-suite/Main.hs index 7720ee6..051fa17 100644 --- a/source/test-suite/Main.hs +++ b/source/test-suite/Main.hs @@ -15,6 +15,7 @@ import Language.Haskell.Brittany.Internal import Language.Haskell.Brittany.Internal.Config.Config import Language.Haskell.Brittany.Internal.Config.Types import Language.Haskell.Brittany.Internal.Prelude +import Test.HUnit (assertEqual) import qualified System.Directory import System.FilePath (()) import System.Timeout (timeout) @@ -22,6 +23,7 @@ import Test.Hspec import qualified Text.Parsec as Parsec import Text.Parsec.Text (Parser) import qualified Data.List.Extra +import qualified System.Console.ANSI as ANSI hush :: Either a b -> Maybe b hush = either (const Nothing) Just @@ -282,9 +284,15 @@ roundTripEqual c t = `shouldReturn` Right (PPTextWrapper t) goldenTest :: Config -> Text -> Text -> Expectation -goldenTest c input expected = - fmap (fmap PPTextWrapper) (parsePrintModuleTests c "TestFakeFileName.hs" input) - `shouldReturn` Right (PPTextWrapper expected) +goldenTest c input expected = do + result <- parsePrintModuleTests c "TestFakeFileName.hs" input + assertEqual + ( ANSI.setSGRCode [ANSI.SetColor ANSI.Foreground ANSI.Dull ANSI.Red] + ++ "golden input: see test source!" + ++ ANSI.setSGRCode [ANSI.Reset] + ) + (Right (PPTextWrapper expected)) + (fmap PPTextWrapper result) newtype PPTextWrapper = PPTextWrapper Text deriving Eq