From f46c4a52a9bc4c3e785c0c568bcd7a09e835b1bc Mon Sep 17 00:00:00 2001 From: Eduardo Trujillo <ed@chromabits.com> Date: Sat, 26 Dec 2020 17:44:11 -0800 Subject: [PATCH] test(Parsers): Add initial parses tests --- test/Doctest.hs => Doctest.hs | 0 hie.yaml | 16 +++++++++++++ package.yaml | 11 +++++++-- shift.cabal | 44 ++++++++++++++++++++++++++++++++-- src/Shift/Types.hs | 2 +- test/Spec.hs | 1 + test/Test/Shift/ParsersSpec.hs | 17 +++++++++++++ 7 files changed, 86 insertions(+), 5 deletions(-) rename test/Doctest.hs => Doctest.hs (100%) create mode 100644 hie.yaml create mode 100644 test/Spec.hs create mode 100644 test/Test/Shift/ParsersSpec.hs diff --git a/test/Doctest.hs b/Doctest.hs similarity index 100% rename from test/Doctest.hs rename to Doctest.hs diff --git a/hie.yaml b/hie.yaml new file mode 100644 index 0000000..537a09a --- /dev/null +++ b/hie.yaml @@ -0,0 +1,16 @@ +cradle: + stack: + - path: "./src" + component: "shift:lib" + + - path: "./app" + component: "shift:exe" + + - path: "./test/Spec.hs" + component: "shift:test:spec" + + - path: "./test/Test" + component: "shift:test:spec" + + - path: "./Doctest.hs" + component: "shift:test:doctest" diff --git a/package.yaml b/package.yaml index 12ec06e..547285c 100644 --- a/package.yaml +++ b/package.yaml @@ -68,10 +68,17 @@ executables: - shift tests: - doctest: - main: Doctest.hs + spec: + main: Spec.hs source-dirs: - test + dependencies: + - shift + - hspec + - hspec-discover + - hspec-megaparsec + doctest: + main: Doctest.hs dependencies: - shift - doctest diff --git a/shift.cabal b/shift.cabal index cf00da2..80a0383 100644 --- a/shift.cabal +++ b/shift.cabal @@ -19,7 +19,8 @@ license-file: LICENSE build-type: Simple extra-source-files: README.md - test/Doctest.hs + test/Spec.hs + test/Test/Shift/ParsersSpec.hs library exposed-modules: @@ -106,6 +107,43 @@ test-suite doctest main-is: Doctest.hs other-modules: Paths_shift + ghc-options: -Wall + build-depends: + aeson + , base >=4.7 && <5 + , bytestring + , cmark-gfm + , containers + , data-default + , doctest + , exceptions + , github + , hgit + , http-client + , http-client-tls + , io-memoize + , lens + , megaparsec + , mtl + , optparse-applicative + , process + , scotty + , semigroups + , shift + , string-conversions + , text + , transformers + , unordered-containers + , vector + , versions + default-language: Haskell2010 + +test-suite spec + type: exitcode-stdio-1.0 + main-is: Spec.hs + other-modules: + Test.Shift.ParsersSpec + Paths_shift hs-source-dirs: test ghc-options: -Wall @@ -116,10 +154,12 @@ test-suite doctest , cmark-gfm , containers , data-default - , doctest , exceptions , github , hgit + , hspec + , hspec-discover + , hspec-megaparsec , http-client , http-client-tls , io-memoize diff --git a/src/Shift/Types.hs b/src/Shift/Types.hs index 021d620..76a701b 100644 --- a/src/Shift/Types.hs +++ b/src/Shift/Types.hs @@ -88,7 +88,7 @@ data CommitType | CTRefactor | CTTest | CTChore - deriving (Show) + deriving (Show, Eq) data BreakingChange = BreakingChange { _bcSubject :: Text, diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..52ef578 --- /dev/null +++ b/test/Spec.hs @@ -0,0 +1 @@ +{-# OPTIONS_GHC -F -pgmF hspec-discover #-} \ No newline at end of file diff --git a/test/Test/Shift/ParsersSpec.hs b/test/Test/Shift/ParsersSpec.hs new file mode 100644 index 0000000..c2e8ef9 --- /dev/null +++ b/test/Test/Shift/ParsersSpec.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE OverloadedStrings #-} + +module Test.Shift.ParsersSpec where + +import Shift.Parsers (commitType) +import Shift.Types (CommitType (CTFeature)) +import Test.Hspec (Spec, describe, it) +import Test.Hspec.Megaparsec (shouldFailOn, shouldParse) +import Text.Megaparsec (parse) + +spec :: Spec +spec = do + describe "commitType" $ do + it "parses a commit type" $ do + parse commitType "" "feat" `shouldParse` CTFeature + it "should fail if the commit type is unknown" $ do + parse commitType "" `shouldFailOn` "omg" -- GitLab