on master help sign in
Tests moved to hspec
689a4a4Michael Snoyman
Text/Libyaml.hs+2
@@ -9,6 +9,8 @@
9{-# LANGUAGE RankNTypes #-}
9{-# LANGUAGE RankNTypes #-}
10{-# LANGUAGE CPP #-}
10{-# LANGUAGE CPP #-}
11
11
12+-- | Low-level, streaming YAML interface. For a higher-level interface, see
13+-- "Data.Yaml".
12module Text.Libyaml
14module Text.Libyaml
13 ( -- * The event stream
15 ( -- * The event stream
14 Event (..)
16 Event (..)
runtests.hs → test/main.hsrenamed+19−20
@@ -1,38 +1,37 @@
1{-# LANGUAGE CPP #-}
1{-# LANGUAGE CPP #-}
2{-# LANGUAGE PackageImports #-}
2{-# LANGUAGE PackageImports #-}
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4−import Test.Framework (defaultMain)
5
4
6import Text.Libyaml
5import Text.Libyaml
7import qualified Data.ByteString.Char8 as B8
6import qualified Data.ByteString.Char8 as B8
8
7
9−import Test.Framework.Providers.HUnit
10import Test.HUnit hiding (Test, path)
8import Test.HUnit hiding (Test, path)
11
9
12import qualified Data.Conduit as C
10import qualified Data.Conduit as C
13import qualified Data.Conduit.List as CL
11import qualified Data.Conduit.List as CL
14−import Data.List (foldl')
15
12
16import System.Directory
13import System.Directory
17import Control.Monad
14import Control.Monad
18import Control.Exception (try, SomeException)
15import Control.Exception (try, SomeException)
16+import Test.Hspec.Monadic
17+import Test.Hspec.HUnit ()
19
18
20main :: IO ()
19main :: IO ()
21−main = defaultMain
20+main = hspecX $ do
21+ describe "streaming" $ do
22− [ testCase "count scalars with anchor" caseCountScalarsWithAnchor
22+ it "count scalars with anchor" caseCountScalarsWithAnchor
23− , testCase "count sequences with anchor" caseCountSequencesWithAnchor
23+ it "count sequences with anchor" caseCountSequencesWithAnchor
24− , testCase "count mappings with anchor" caseCountMappingsWithAnchor
24+ it "count mappings with anchor" caseCountMappingsWithAnchor
25− , testCase "count aliases" caseCountAliases
25+ it "count aliases" caseCountAliases
26− , testCase "count scalars" caseCountScalars
26+ it "count scalars" caseCountScalars
27− , testCase "largest string" caseLargestString
27+ it "largest string" caseLargestString
28− , testCase "encode/decode" caseEncodeDecode
28+ it "encode/decode" caseEncodeDecode
29− , testCase "encode/decode file" caseEncodeDecodeFile
29+ it "encode/decode file" caseEncodeDecodeFile
30− , testCase "interleaved encode/decode" caseInterleave
30+ it "interleaved encode/decode" caseInterleave
31− , testCase "decode invalid document (without segfault)" caseDecodeInvalidDocument
31+ it "decode invalid document (without segfault)" caseDecodeInvalidDocument
32− ]
32+
33−
34−counter :: (Event -> Bool) -> Int -> C.Sink Event IO Int
33+counter :: (Event -> Bool) -> C.Sink Event IO Int
35−counter pred' acc =
34+counter pred' =
36 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
35 CL.fold (\cnt e -> (if pred' e then 1 else 0) + cnt) 0
37
36
38caseHelper :: String
37caseHelper :: String
@@ -40,7 +39,7 @@ caseHelper :: String
40 -> Int
39 -> Int
41 -> Assertion
40 -> Assertion
42caseHelper yamlString pred' expRes = do
41caseHelper 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'
44 res @?= expRes
43 res @?= expRes
45
44
46caseCountScalarsWithAnchor :: Assertion
45caseCountScalarsWithAnchor :: Assertion
@@ -152,7 +151,7 @@ caseDecodeInvalidDocument :: Assertion
152caseDecodeInvalidDocument = do
151caseDecodeInvalidDocument = do
153 x <- try $ C.runResourceT $ decode yamlBS C.$$ CL.sinkNull
152 x <- try $ C.runResourceT $ decode yamlBS C.$$ CL.sinkNull
154 case x of
153 case x of
155− Left (e :: SomeException) -> return ()
154+ Left (_ :: SomeException) -> return ()
156 Right y -> do
155 Right y -> do
157 putStrLn $ "bad return value: " ++ show y
156 putStrLn $ "bad return value: " ++ show y
158 assertFailure "expected parsing exception, but got no errors"
157 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.
12 don't need to worry about any non-Haskell dependencies.
12 don't need to worry about any non-Haskell dependencies.
13category: Web
13category: Web
14stability: unstable
14stability: unstable
15−cabal-version: >= 1.2
15+cabal-version: >= 1.8
16build-type: Simple
16build-type: Simple
17homepage: http://github.com/snoyberg/yaml/
17homepage: http://github.com/snoyberg/yaml/
18extra-source-files: c/helper.h,
18extra-source-files: c/helper.h,
@@ -24,18 +24,7 @@ flag system-libyaml
24 description: Use the system-wide libyaml instead of the bundled copy
24 description: Use the system-wide libyaml instead of the bundled copy
25 default: False
25 default: False
26
26
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−
34library
27library
35− if flag(nolib)
36− Buildable: False
37− else
38− Buildable: True
39 build-depends: base >= 4 && < 5
28 build-depends: base >= 4 && < 5
40 , transformers >= 0.1 && < 0.3
29 , transformers >= 0.1 && < 0.3
41 , bytestring >= 0.9.1.4 && < 0.10
30 , bytestring >= 0.9.1.4 && < 0.10
@@ -57,18 +46,19 @@ library
57 libyaml/writer.c
46 libyaml/writer.c
58 include-dirs: libyaml
47 include-dirs: libyaml
59
48
60−test-suite runtests
49+test-suite test
61 type: exitcode-stdio-1.0
50 type: exitcode-stdio-1.0
51+ hs-source-dirs: test
62− main-is: runtests.hs
52+ main-is: main.hs
63 cpp-options: -DTEST
53 cpp-options: -DTEST
64− build-depends: test-framework
54+ build-depends: hspec
65− , test-framework-hunit
66 , HUnit
55 , HUnit
67 , directory
56 , directory
68 , base >= 4 && < 5
57 , base >= 4 && < 5
69 , transformers >= 0.1 && < 0.3
58 , transformers >= 0.1 && < 0.3
70 , bytestring >= 0.9.1.4 && < 0.10
59 , bytestring >= 0.9.1.4 && < 0.10
71 , conduit
60 , conduit
61+ , yaml
72 ghc-options: -Wall
62 ghc-options: -Wall
73 c-sources: c/helper.c
63 c-sources: c/helper.c
74 include-dirs: c
64 include-dirs: c