Stack を使って Haskell したい!! を参考にHSpecを書いてみました。.cabalファイルのbuild-dependsにhspecを追加して、コンソールから、stack testを実行したら、依存関係で、HUnit、QuickCheckもダウンロードしてビルドされているようです。
プロジェクトの.cabalにhspec追加
1 2 3 4 5 6 7 8 9 |
test-suite hw-test type: exitcode-stdio-1.0 hs-source-dirs: test main-is: Spec.hs build-depends: base , hspec , hw ghc-options: -threaded -rtsopts -with-rtsopts=-N default-language: Haskell2010 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
hw> stack test hspec-discover-2.2.4: download setenv-0.1.1.3: download HUnit-1.3.1.2: download setenv-0.1.1.3: configure tf-random-0.5: download setenv-0.1.1.3: build hspec-discover-2.2.4: configure setenv-0.1.1.3: copy/register hspec-discover-2.2.4: build HUnit-1.3.1.2: configure HUnit-1.3.1.2: build tf-random-0.5: configure tf-random-0.5: build hspec-discover-2.2.4: copy/register HUnit-1.3.1.2: copy/register tf-random-0.5: copy/register hspec-expectations-0.7.2: download hspec-expectations-0.7.2: configure QuickCheck-2.8.2: download hspec-expectations-0.7.2: build QuickCheck-2.8.2: configure hspec-expectations-0.7.2: copy/register QuickCheck-2.8.2: build QuickCheck-2.8.2: copy/register quickcheck-io-0.1.4: download quickcheck-io-0.1.4: configure quickcheck-io-0.1.4: build quickcheck-io-0.1.4: copy/register hspec-core-2.2.4: download hspec-core-2.2.4: configure hspec-core-2.2.4: build hspec-core-2.2.4: copy/register hspec-2.2.4: download hspec-2.2.4: configure hspec-2.2.4: build hspec-2.2.4: copy/register hw-0.1.0.0: configure (lib + exe + test) Configuring hw-0.1.0.0... |
Lib.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
module Lib ( someFunc ,add1 ) where import Data.List add1 :: Int -> Int -> Int add1 x y = x + y + 1 someFunc :: IO () someFunc = do print $ sort [5,3,4,2] putStrLn "aaa" putStrLn "someFunc!!" |
LibSpec.hs
1 2 3 4 5 6 7 8 9 10 11 12 13 |
module LibSpec where import Test.Hspec import Lib spec :: Spec spec = do describe "test add1" $ do it "aaaa" $ add1 5 6 `shouldBe` 12 describe "test add1" $ do it "aaaa" $ do add1 5 7 `shouldBe` 13 |
Spec.hs
1 2 3 4 5 |
{-# OPTIONS_GHC -F -pgmF hspec-discover #-} {- main :: IO () main = putStrLn "Test suite not yet implemented" -} |