on master help sign in
Adopting hspec and hspec-discover as test-suite.
1f2b19aKazu Yamamoto
warp/Network/Wai/Handler/Warp/ReadInt.hs+4−1
@@ -3,7 +3,10 @@
3-- Copyright : Erik de Castro Lopo <erikd@mega-nerd.com>
3-- Copyright : Erik de Castro Lopo <erikd@mega-nerd.com>
4-- License : BSD3
4-- License : BSD3
5
5
6−module Network.Wai.Handler.Warp.ReadInt (readInt) where
6+module Network.Wai.Handler.Warp.ReadInt (
7+ readInt
8+ , readInt64
9+ ) where
7
10
8-- This function lives in its own file because the MagicHash pragma interacts
11-- This function lives in its own file because the MagicHash pragma interacts
9-- poorly with the CPP pragma.
12-- poorly with the CPP pragma.
warp/test/readInt.hs → warp/attic/readInt.hsrenamed

The content is the same.

warp/test/ReadIntSpec.hsnew file+23
@@ -0,0 +1,23 @@
1+module ReadIntSpec where
2+
3+import Data.ByteString (ByteString)
4+import Test.Hspec
5+import Network.Wai.Handler.Warp.ReadInt
6+import qualified Data.ByteString.Char8 as B
7+import qualified Test.QuickCheck as QC
8+
9+spec :: Spec
10+spec = describe "readInt64" $ do
11+ it "converts ByteString to Int" $ QC.property (prop_read_show_idempotent readInt64)
12+
13+-- A QuickCheck property. Test that for a number >= 0, converting it to
14+-- a string using show and then reading the value back with the function
15+-- under test returns the original value.
16+-- The functions under test only work on Natural numbers (the Conent-Length
17+-- field in a HTTP header is always >= 0) so we check the absolute value of
18+-- the value that QuickCheck generates for us.
19+prop_read_show_idempotent :: (Integral a, Show a) => (ByteString -> a) -> a -> Bool
20+prop_read_show_idempotent freader x = px == freader (toByteString px)
21+ where
22+ px = abs x
23+ toByteString = B.pack . show
warp/test/Spec.hsnew file+1
@@ -0,0 +1 @@
1+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
warp/warp.cabal+5−3
@@ -51,16 +51,18 @@ Library
51 if os(windows)
51 if os(windows)
52 Cpp-options: -DWINDOWS
52 Cpp-options: -DWINDOWS
53
53
54−Test-Suite test
54+Test-Suite spec
55− Main-Is: main.hs
55+ Main-Is: Spec.hs
56− Hs-Source-Dirs: test
56+ Hs-Source-Dirs: test, .
57 Type: exitcode-stdio-1.0
57 Type: exitcode-stdio-1.0
58
58
59 Ghc-Options: -Wall
59 Ghc-Options: -Wall
60 Build-Depends: base >= 4 && < 5
60 Build-Depends: base >= 4 && < 5
61 , HUnit
61 , HUnit
62+ , QuickCheck
62 , bytestring
63 , bytestring
63 , conduit
64 , conduit
65+ , ghc-prim
64 , hspec
66 , hspec
65 , http-types
67 , http-types
66 , network
68 , network