on master help sign in
Tests moved to hspec
commit689a4a44fba2473856fca0907cb30ba54be93f14 authorMichael Snoyman <michael@snoyman.com> dateWed 28 Dec 2011, 13:27 (15 years ago) parentb1694ae
3 files changed+27−36
Text/Libyaml.hs+2 runtests.hs → test/main.hs+19−20 yaml.cabal+6−16
Text/Libyaml.hs+2
@@ -9,6 +9,8 @@
99{-# LANGUAGE RankNTypes #-}
1010{-# LANGUAGE CPP #-}
1111
12+-- | Low-level, streaming YAML interface. For a higher-level interface, see
13+-- "Data.Yaml".
1214module Text.Libyaml
1315 ( -- * The event stream
1416 Event (..)
runtests.hs → test/main.hsrenamed+19−20
@@ -1,38 +1,37 @@
11{-# LANGUAGE CPP #-}
22{-# LANGUAGE PackageImports #-}
33{-# LANGUAGE ScopedTypeVariables #-}
4−import Test.Framework (defaultMain)
54
65import Text.Libyaml
76import qualified Data.ByteString.Char8 as B8
87
9−import Test.Framework.Providers.HUnit
108import Test.HUnit hiding (Test, path)
119
1210import qualified Data.Conduit as C
1311import qualified Data.Conduit.List as CL
14−import Data.List (foldl')
1512
1613import System.Directory
1714import Control.Monad
1815import Control.Exception (try, SomeException)
16+import Test.Hspec.Monadic
17+import Test.Hspec.HUnit ()
1918
2019main :: IO ()
21−main = defaultMain
22− [ testCase "count scalars with anchor" caseCountScalarsWithAnchor
23− , testCase "count sequences with anchor" caseCountSequencesWithAnchor
24− , testCase "count mappings with anchor" caseCountMappingsWithAnchor
25− , testCase "count aliases" caseCountAliases
26− , testCase "count scalars" caseCountScalars
27− , testCase "largest string" caseLargestString
28− , testCase "encode/decode" caseEncodeDecode
29− , testCase "encode/decode file" caseEncodeDecodeFile
30− , testCase "interleaved encode/decode" caseInterleave
31− , testCase "decode invalid document (without segfault)" caseDecodeInvalidDocument
32− ]
33−
34−counter :: (Event -> Bool) -> Int -> C.Sink Event IO Int
35−counter pred' acc =
20+main = hspecX $ do
21+ describe "streaming" $ do
22+ it "count scalars with anchor" caseCountScalarsWithAnchor
23+ it "count sequences with anchor" caseCountSequencesWithAnchor
24+ it "count mappings with anchor" caseCountMappingsWithAnchor
25+ it "count aliases" caseCountAliases
26+ it "count scalars" caseCountScalars
27+ it "largest string" caseLargestString
28+ it "encode/decode" caseEncodeDecode
29+ it "encode/decode file" caseEncodeDecodeFile
30+ it "interleaved encode/decode" caseInterleave
31+ it "decode invalid document (without segfault)" caseDecodeInvalidDocument
32+
33+counter :: (Event -> Bool) -> C.Sink Event IO Int
34+counter pred' =
3635 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
3736
3837caseHelper :: String
@@ -40,7 +39,7 @@ caseHelper :: String
4039 -> Int
4140 -> Assertion
4241caseHelper yamlString pred' expRes = do
43− res <- C.runResourceT $ decode (B8.pack yamlString) C.$$ counter pred' 0
42+ res <- C.runResourceT $ decode (B8.pack yamlString) C.$$ counter pred'
4443 res @?= expRes
4544
4645caseCountScalarsWithAnchor :: Assertion
@@ -152,7 +151,7 @@ caseDecodeInvalidDocument :: Assertion
152151caseDecodeInvalidDocument = do
153152 x <- try $ C.runResourceT $ decode yamlBS C.$$ CL.sinkNull
154153 case x of
155− Left (e :: SomeException) -> return ()
154+ Left (_ :: SomeException) -> return ()
156155 Right y -> do
157156 putStrLn $ "bad return value: " ++ show y
158157 assertFailure "expected parsing exception, but got no errors"
yaml.cabal+6−16
@@ -12,7 +12,7 @@ description: Provides support for parsing and emitting Yaml documents.
1212 don't need to worry about any non-Haskell dependencies.
1313category: Web
1414stability: unstable
15−cabal-version: >= 1.2
15+cabal-version: >= 1.8
1616build-type: Simple
1717homepage: http://github.com/snoyberg/yaml/
1818extra-source-files: c/helper.h,
@@ -24,18 +24,7 @@ flag system-libyaml
2424 description: Use the system-wide libyaml instead of the bundled copy
2525 default: False
2626
27−flag nolib
28− description: Skip building the library
29− default: False
30−flag buildtests
31− description: Build the executable to run unit tests
32− default: False
33−
3427library
35− if flag(nolib)
36− Buildable: False
37− else
38− Buildable: True
3928 build-depends: base >= 4 && < 5
4029 , transformers >= 0.1 && < 0.3
4130 , bytestring >= 0.9.1.4 && < 0.10
@@ -57,18 +46,19 @@ library
5746 libyaml/writer.c
5847 include-dirs: libyaml
5948
60−test-suite runtests
49+test-suite test
6150 type: exitcode-stdio-1.0
62− main-is: runtests.hs
51+ hs-source-dirs: test
52+ main-is: main.hs
6353 cpp-options: -DTEST
64− build-depends: test-framework
65− , test-framework-hunit
54+ build-depends: hspec
6655 , HUnit
6756 , directory
6857 , base >= 4 && < 5
6958 , transformers >= 0.1 && < 0.3
7059 , bytestring >= 0.9.1.4 && < 0.10
7160 , conduit
61+ , yaml
7262 ghc-options: -Wall
7363 c-sources: c/helper.c
7464 include-dirs: c