Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve the failure messages when tests fail. #298

Merged
merged 1 commit into from
Jun 30, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions test/Utils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import qualified Control.Exception as Exception
import Prelude hiding (FilePath)
import System.Directory (removePathForcibly)
import qualified System.Process as Process
import Test.Hspec (shouldBe)
import Test.Hspec (HasCallStack, shouldBe, shouldSatisfy)
import Turtle (ExitCode (..), FilePath, Text, cd, empty, encodeString,
procStrictWithErr, pwd, readTextFile)

Expand All @@ -35,33 +35,33 @@ runFor us cmd args = do
Concurrent.threadDelay us
Process.terminateProcess p

shouldBeSuccess :: (ExitCode, Text, Text) -> IO ()
shouldBeSuccess (code, _stdout, _stderr) = do
shouldBeSuccess :: HasCallStack => (ExitCode, Text, Text) -> IO ()
shouldBeSuccess result@(_code, _stdout, _stderr) = do
-- print $ "STDOUT: " <> _stdout
-- print $ "STDERR: " <> _stderr
code `shouldBe` ExitSuccess
result `shouldSatisfy` (\(code, _, _) -> code == ExitSuccess)

shouldBeSuccessOutput :: FilePath -> (ExitCode, Text, Text) -> IO ()
shouldBeSuccessOutput expected (code, out, _) = do
shouldBeSuccessOutput :: HasCallStack => FilePath -> (ExitCode, Text, Text) -> IO ()
shouldBeSuccessOutput expected result = do
expectedContent <- readFixture expected
(code, out) `shouldBe` (ExitSuccess, expectedContent)
result `shouldSatisfy` (\(code, stdout, _stderr) -> code == ExitSuccess && stdout == expectedContent)

shouldBeFailure :: (ExitCode, Text, Text) -> IO ()
shouldBeFailure (code, _stdout, _stderr) = do
shouldBeFailure :: HasCallStack => (ExitCode, Text, Text) -> IO ()
shouldBeFailure result@(_code, _stdout, _stderr) = do
-- print $ "STDOUT: " <> _stdout
-- print $ "STDERR: " <> _stderr
code `shouldBe` ExitFailure 1
result `shouldSatisfy` (\(code, _, _) -> code == ExitFailure 1)

shouldBeFailureOutput :: FilePath -> (ExitCode, Text, Text) -> IO ()
shouldBeFailureOutput expected (code, _, out) = do
shouldBeFailureOutput :: HasCallStack => FilePath -> (ExitCode, Text, Text) -> IO ()
shouldBeFailureOutput expected result = do
expectedContent <- readFixture expected
(code, out) `shouldBe` (ExitFailure 1, expectedContent)
result `shouldSatisfy` (\(code, _stdout, stderr) -> code == ExitFailure 1 && stderr == expectedContent)

readFixture :: FilePath -> IO Text
readFixture path =
readTextFile $ "../fixtures/" <> path

checkFixture :: FilePath -> IO ()
checkFixture :: HasCallStack => FilePath -> IO ()
checkFixture path = do
actual <- readTextFile path
expected <- readFixture path
Expand Down