Skip to content

Commit

Permalink
Add unit tests target
Browse files Browse the repository at this point in the history
  • Loading branch information
Valeriy Popov committed Dec 10, 2017
1 parent fc886b5 commit 0e3bf33
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
16 changes: 16 additions & 0 deletions future-store.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ library
build-depends:
base >= 4.7 && < 5
exposed-modules:
Chapter2.SimpleFunctions
Lib
default-language: Haskell2010

Expand All @@ -53,3 +54,18 @@ test-suite future-store-test
base >= 4.7 && < 5
, future-store
default-language: Haskell2010

test-suite unit-tests
type: exitcode-stdio-1.0
main-is: Spec.hs
hs-source-dirs:
test/unit
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >= 4.7 && < 5
, future-store
, hspec
, hspec-discover
other-modules:
Chapter2.SimpleFunctionsSpec
default-language: Haskell2010
15 changes: 15 additions & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,18 @@ tests:
- -with-rtsopts=-N
dependencies:
- future-store

unit-tests:
main: Spec.hs
source-dirs: test/unit
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- future-store
- hspec
- hspec-discover



18 changes: 18 additions & 0 deletions src/Chapter2/SimpleFunctions.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Chapter2.SimpleFunctions (
firstOrEmpty,
(+++),
reverse2
) where

firstOrEmpty :: [String] -> String
firstOrEmpty lst = if not (null lst) then head lst else "empty"


lst1 +++ lst2 = if null lst1
then lst2
else (head lst1) : (tail lst1 +++ lst2)


reverse2 list = if null list
then []
else reverse2 (tail list) +++ [head list]
11 changes: 11 additions & 0 deletions test/unit/Chapter2/SimpleFunctionsSpec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Chapter2.SimpleFunctionsSpec where

import Test.Hspec
import Chapter2.SimpleFunctions

spec :: Spec
spec = do
describe "Prelude.head" $ do

it "reverse the string" $ do
reverse2 "hello" `shouldBe` "olleh"
1 change: 1 addition & 0 deletions test/unit/Spec.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{-# OPTIONS_GHC -F -pgmF hspec-discover #-}

0 comments on commit 0e3bf33

Please sign in to comment.