@@ -7,7 +7,6 @@ module Education.MakeMistakesToLearnHaskellSpec (main, spec) where
7
7
import qualified Education.MakeMistakesToLearnHaskell
8
8
import Education.MakeMistakesToLearnHaskell.Env
9
9
10
-
11
10
-- `main` is here so that this module can be run from GHCi on its own. It is
12
11
-- not needed for automatic spec discovery.
13
12
main :: IO ()
25
24
it " given an empty answer, show FAIL" $ do
26
25
void $ runMmlh [" show" , " --terminal" , " 1" ]
27
26
runMmlh [" verify" , " test/assets/common/empty.hs" ]
28
- >>= shouldExitWithHints [" HINT: This error indicates you haven't defined main function." ]
27
+ >>= shouldExitWithHints [" HINT: This error indicates that you haven't defined the main function." ]
29
28
30
29
it " given non-existing answer of exercise 2.5, show NOT VERIFIED" $ do
31
30
void $ runMmlh [" show" , " --terminal" , " 2.5" ]
44
43
45
44
it " given a not-compilable answer of exercise 4, show FAIL" $ do
46
45
let msgs =
47
- [" HINT: You seem to forget to write `do`. `do` must be put before listing `putStr`s and `getContents`." ]
46
+ [" HINT: You seem to have forgotten to write `do`. `do` must be put before listing `putStr`s and `getContents`." ]
48
47
void $ runMmlh [" show" , " --terminal" , " 4" ]
49
48
runMmlh [" verify" , " test/assets/4/no-do.hs" ]
50
49
>>= shouldExitWithHints msgs
@@ -58,30 +57,30 @@ runMmlh args = do
58
57
$ withEnv env
59
58
$ captureProcessResult Education.MakeMistakesToLearnHaskell. main
60
59
61
-
62
- includes :: ByteString'. ByteString -> ByteString'. ByteString -> Bool
63
- includes = ByteString'. isInfixOf
64
-
60
+ shouldContainBS :: ByteString'. ByteString -> ByteString'. ByteString -> Expectation
61
+ shouldContainBS a b = if ByteString'. isInfixOf b a
62
+ then pure ()
63
+ else expectationFailure $ unwords [ show a, " does not contain " , show b]
65
64
66
65
shouldExitWithHints :: [ByteString'. ByteString ] -> ProcessResult -> IO ()
67
66
shouldExitWithHints hintMsgs (ProcessResult out err code ex) = do
68
67
fmap show ex `shouldBe` Nothing
69
- err `shouldSatisfy ` ByteString'. null
70
- mapM_ (( out `shouldSatisfy` ) . includes ) hintMsgs
68
+ err `shouldBe ` ByteString'. empty
69
+ mapM_ (out `shouldContainBS` ) hintMsgs
71
70
code `shouldBe` ExitFailure 1
72
71
73
72
74
73
shouldVerifySuccess :: ProcessResult -> IO ()
75
74
shouldVerifySuccess (ProcessResult out err code ex) = do
76
75
fmap show ex `shouldBe` Nothing
77
- err `shouldSatisfy ` ByteString'. null
78
- out `shouldSatisfy` includes " SUCCESS"
76
+ err `shouldBe ` ByteString'. empty
77
+ out `shouldContainBS` " SUCCESS"
79
78
code `shouldBe` ExitSuccess
80
79
81
80
82
81
shouldPrintNotVerified :: ProcessResult -> IO ()
83
82
shouldPrintNotVerified (ProcessResult out err code ex) = do
84
83
fmap show ex `shouldBe` Nothing
85
- err `shouldSatisfy ` ByteString'. null
86
- out `shouldSatisfy` includes " NOT VERIFIED"
84
+ err `shouldBe ` ByteString'. empty
85
+ out `shouldContainBS` " NOT VERIFIED"
87
86
code `shouldBe` ExitSuccess
0 commit comments