@@ -54,7 +54,8 @@ instance IsOption NodeOpt where
54 optionCLParser = fmap NodeOpt $ switch (long nodeArg <> help nodeHelp)
54 optionCLParser = fmap NodeOpt $ switch (long nodeArg <> help nodeHelp)
56ingredients :: [Ingredient]
56ingredients :: [Ingredient]
57+ingredients = defaultIngredients ++
57−ingredients = [rerunningTests [consoleTestReporter],
58+ [rerunningTests [consoleTestReporter],
58 includingOptions [Option (Proxy :: Proxy NodeOpt)] ]
59 includingOptions [Option (Proxy :: Proxy NodeOpt)] ]
60----------------------------------------------------------------------- [ Core ]
61----------------------------------------------------------------------- [ Core ]
@@ -63,28 +64,37 @@ ingredients = [rerunningTests [consoleTestReporter],
63-- A ripoff of goldenVsFile from Tasty.Golden
64-- A ripoff of goldenVsFile from Tasty.Golden
64test :: String -> String -> IO () -> TestTree
65test :: String -> String -> IO () -> TestTree
65test name path act =
66test name path act =
66− goldenTest name (BS.readFile ref) (act >> BS.readFile new) cmp upd
67+ goldenTest name (readFile ref) (act >> readFile new) cmp upd
68 ref = path </> "expected"
69 ref = path </> "expected"
69 new = path </> "output"
70 new = path </> "output"
70− cmp x y = return $ if x == y then Nothing
71+ cmp x y = return $ if normalize x == normalize y then Nothing
71 else Just $ printDiff (ref, x) (new, y)
72 else Just $ printDiff (ref, x) (new, y)
72− upd = BS.writeFile ref
73+ upd = writeFile ref
74+ -- just pretend that backslashes are slashes for comparison
75+ -- purposes to avoid path problems, so don't write any tests
76+ -- that depend on that distinction in other contexts.
77+ -- Also compare CRLF and LF as equal, fixes a weird corner case
78+ -- on Mac where basic010 and reg039 produces CRLF
80+ normalize ('\r':'\n':xs) = '\n' : normalize xs
81+ normalize ('\\':'\\':xs) = '/' : normalize xs
82+ normalize ('\\':xs) = '/' : normalize xs
83+ normalize (x : xs) = x : normalize xs
74-- Takes the filepath and content of `expected` and `output`
86-- Takes the filepath and content of `expected` and `output`
75-- and formats an error message stating their difference
87-- and formats an error message stating their difference
76−printDiff :: (String, BS.ByteString) -> (String, BS.ByteString) -> String
88+printDiff :: (String, String) -> (String, String) -> String
77printDiff (ref, x) (new, y) =
89printDiff (ref, x) (new, y) =
78− let refcnt = BSC.unpack x
79− newcnt = BSC.unpack y
80− printContent cnt =
90+ let printContent cnt =
81 if Data.List.null cnt
91 if Data.List.null cnt
82 then " is empty...\n"
92 then " is empty...\n"
83 else " is: \n" ++ unlines (fmap ((++) " ") (lines cnt))
93 else " is: \n" ++ unlines (fmap ((++) " ") (lines cnt))
85 "Test mismatch!\n" ++
95 "Test mismatch!\n" ++
86− "Golden file " ++ ref ++ printContent refcnt ++
96+ "Golden file " ++ ref ++ printContent x ++
87− "However, " ++ new ++ printContent newcnt
97+ "However, " ++ new ++ printContent y
89-- Should always output a 3-charater string from a postive Int
99-- Should always output a 3-charater string from a postive Int
90indexToString :: Int -> String
100indexToString :: Int -> String
@@ -112,9 +122,11 @@ mkGoldenTests testFamilies flags =
112runTest :: String -> Flags -> IO ()
122runTest :: String -> Flags -> IO ()
113runTest path flags = do
123runTest path flags = do
114 let run = (proc "bash" ("run" : flags)) {cwd = Just path,
124 let run = (proc "bash" ("run" : flags)) {cwd = Just path,
115− std_out = CreatePipe}
125+ std_out = CreatePipe,
126+ std_err = CreatePipe}
116− (_, output, _) <- readCreateProcessWithExitCode run ""
127+ (_, output, error_out) <- readCreateProcessWithExitCode run ""
117 writeFile (path </> "output") output
128 writeFile (path </> "output") output
129+ hPutStrLn stderr error_out
119main :: IO ()
131main :: IO ()
@@ -125,4 +137,3 @@ main = do
126 mkGoldenTests (testFamiliesForCodegen codegen)
138 mkGoldenTests (testFamiliesForCodegen codegen)
127 (flags ++ idrisFlags)
139 (flags ++ idrisFlags)