on master help sign in
Adopting hspec and hspec-discover as test-suite.
commit1f2b19ab87a0af745d230857ebf38489b3e6bf1d authorKazu Yamamoto <kazu@iij.ad.jp> dateWed 15 Aug 2012, 10:34 (14 years ago) parentbefd5ec
5 files changed+33−4
warp/Network/Wai/Handler/Warp/ReadInt.hs+4−1 warp/test/readInt.hs → warp/attic/readInt.hs warp/test/ReadIntSpec.hs+23 warp/test/Spec.hs+1 warp/warp.cabal+5−3
warp/Network/Wai/Handler/Warp/ReadInt.hs+4−1
@@ -3,7 +3,10 @@
33-- Copyright : Erik de Castro Lopo <erikd@mega-nerd.com>
44-- License : BSD3
55
6−module Network.Wai.Handler.Warp.ReadInt (readInt) where
6+module Network.Wai.Handler.Warp.ReadInt (
7+ readInt
8+ , readInt64
9+ ) where
710
811-- This function lives in its own file because the MagicHash pragma interacts
912-- 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
5151 if os(windows)
5252 Cpp-options: -DWINDOWS
5353
54−Test-Suite test
55− Main-Is: main.hs
56− Hs-Source-Dirs: test
54+Test-Suite spec
55+ Main-Is: Spec.hs
56+ Hs-Source-Dirs: test, .
5757 Type: exitcode-stdio-1.0
5858
5959 Ghc-Options: -Wall
6060 Build-Depends: base >= 4 && < 5
6161 , HUnit
62+ , QuickCheck
6263 , bytestring
6364 , conduit
65+ , ghc-prim
6466 , hspec
6567 , http-types
6668 , network