From 052b9138ef0fae4256f419a0033b94edd4296de3 Mon Sep 17 00:00:00 2001 From: rbasso Date: Mon, 12 Sep 2016 17:39:54 +0900 Subject: [PATCH] series: Rewrite tests to use hspec with fail-fast. --- exercises/series/package.yaml | 2 +- exercises/series/test/Tests.hs | 51 +++++++++++++++++----------------- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/exercises/series/package.yaml b/exercises/series/package.yaml index 060a02777..869a18227 100644 --- a/exercises/series/package.yaml +++ b/exercises/series/package.yaml @@ -16,4 +16,4 @@ tests: source-dirs: test dependencies: - series - - HUnit + - hspec diff --git a/exercises/series/test/Tests.hs b/exercises/series/test/Tests.hs index e6397cefe..055bd6de5 100644 --- a/exercises/series/test/Tests.hs +++ b/exercises/series/test/Tests.hs @@ -1,30 +1,29 @@ -import Test.HUnit (Assertion, (@=?), runTestTT, Test(..), Counts(..)) -import System.Exit (ExitCode(..), exitWith) -import Series (slices) +{-# OPTIONS_GHC -fno-warn-type-defaults #-} -exitProperly :: IO Counts -> IO () -exitProperly m = do - counts <- m - exitWith $ if failures counts /= 0 || errors counts /= 0 then ExitFailure 1 else ExitSuccess +import Test.Hspec (Spec, describe, it, shouldBe) +import Test.Hspec.Runner (configFastFail, defaultConfig, hspecWith) -testCase :: String -> Assertion -> Test -testCase label assertion = TestLabel label (TestCase assertion) +import Series (slices) main :: IO () -main = exitProperly $ runTestTT $ TestList - [ TestList seriesTests ] - -seriesTests :: [Test] -seriesTests = - [ testCase "slices of one" $ do - [] @=? slices 1 "" - [[0],[1],[2],[3],[4]] @=? slices 1 "01234" - , testCase "slices of two" $ do - [] @=? slices 2 "" - [[0,1]] @=? slices 2 "01" - [[0,1],[1,2],[2,3],[3,4]] @=? slices 2 "01234" - , testCase "slices of three" $ do - [] @=? slices 3 "ab" - [[0,1,2]] @=? slices 3 "012" - [[0,1,2],[1,2,3]] @=? slices 3 "0123" - ] +main = hspecWith defaultConfig {configFastFail = True} specs + +specs :: Spec +specs = describe "series" $ do + + -- As of 2016-09-12, there was no reference file + -- for the test cases in `exercism/x-common`. + + it "slices of one" $ do + slices 1 "" `shouldBe` [] + slices 1 "01234" `shouldBe` [[0], [1], [2], [3], [4]] + + it "slices of two" $ do + slices 2 "" `shouldBe` [] + slices 2 "01" `shouldBe` [[0,1]] + slices 2 "01234" `shouldBe` [[0,1], [1,2], [2,3], [3,4]] + + it "slices of three" $ do + slices 3 "ab" `shouldBe` [] + slices 3 "012" `shouldBe` [[0,1,2]] + slices 3 "0123" `shouldBe` [[0,1,2], [1,2,3]]