git.iko.soy/typeable/hjsonschema
on master help sign in
Use Tasty when testing for the examples' validity.
commit00b0734a9d6c5fcaec109c538970e003798fd359 authorIan Grant Jeffries <ian@housejeffries.com> dateFri 25 Mar 2016, 00:42 (11 years ago) parent706d67e
5 files changed+19−16
examples/CustomSchema.hs+1−1 examples/Main.hs+10−10 examples/PrettyShowFailure.hs+5−4 examples/Standard.hs+1−1 hjsonschema.cabal+2
examples/CustomSchema.hs+1−1
@@ -58,7 +58,7 @@ example :: IO ()
5858example =
5959 case validate schema badData of
6060 [] -> error "We validated bad data."
61− [FR.Failure OddLength _ _] -> putStrLn "Success."
61+ [FR.Failure OddLength _ _] -> return () -- Success.
6262 _ -> error "We got a different failure than expected."
6363 where
6464 schema :: Schema
examples/Main.hs+10−10
@@ -1,19 +1,19 @@
11
22module Main where
33
4+import Test.Tasty (TestTree, defaultMain, testGroup)
5+import qualified Test.Tasty.HUnit as HU
6+
47import qualified CustomSchema as C
58import qualified PrettyShowFailure as P
69import qualified Standard as S
710
811main :: IO ()
9−main = do
10− putStrLn "# Standard Example"
11− S.example
12− putStrLn ""
13−
14− putStrLn "# PrettyShowFailure Example"
15− P.example
16− putStrLn ""
12+main = defaultMain (testGroup "Check Examples" exampleTests)
1713
18− putStrLn "# CustomSchema Example"
19− C.example
14+exampleTests :: [TestTree]
15+exampleTests =
16+ [ HU.testCase "Standard Example" S.example
17+ , HU.testCase "PrettyShowFailure Example" P.example
18+ , HU.testCase "CustomSchema Example" C.example
19+ ]
examples/PrettyShowFailure.hs+5−4
@@ -28,14 +28,15 @@ example =
2828 -- from the original data and the JSON Pointer.
2929 --
3030 -- If you want to display the invalid subset of the data here's how you
31− -- resolve the JSON Pointer ('D4._failureOffendingData') against the
32− -- original data.
31+ -- resolve the JSON Pointer (which has the field name
32+ -- 'D4._failureOffendingData') against the original data.
3333 --
3434 -- NOTE: You have to have hjsonpointer in your build-depends.
3535 case AP.resolve (D4._failureOffendingData failure) badData of
3636 Left _ -> error "Couldn't resolve pointer."
37− Right _ -> putStrLn "Success." -- We could feed the 'Right' value into
38− -- 'msg' if we wanted to display it.
37+ Right _ -> return () -- Success. We could feed the 'Right' value into
38+ -- the otherwise unused 'msg' if we wanted to
39+ -- display it.
3940
4041msg :: Value -> String
4142msg subsetOfData = unlines
examples/Standard.hs+1−1
@@ -38,7 +38,7 @@ example = do
3838
3939 case validate badData of
4040 [] -> error "We validated bad data."
41− [D4.Failure D4.UniqueItems _ _] -> putStrLn "Success."
41+ [D4.Failure D4.UniqueItems _ _] -> return () -- Success.
4242 _ -> error "We got a different failure than expected."
4343
4444 where
hjsonschema.cabal+2
@@ -116,6 +116,8 @@ test-suite example
116116 , base
117117 , hjsonpointer
118118 , hjsonschema
119+ , tasty
120+ , tasty-hunit
119121 , text
120122 , unordered-containers
121123 , vector