git.iko.soy/typeable/hjsonschema
on master help sign in
Build the examples as tests, not executables.

This way they're still type checked, but users won't run into issues with their system package managers if they have another program that already builds an executable named 'example'.

commit706d67e068f5568e5a73718947eaf41d342128d5 authorIan Grant Jeffries <ian@housejeffries.com> dateMon 7 Mar 2016, 17:31 (11 years ago) parent49fab05
2 files changed+20−9
examples/PrettyShowFailure.hs+18−8 hjsonschema.cabal+2−1
examples/PrettyShowFailure.hs+18−8
@@ -18,17 +18,27 @@ failure = D4.Failure
1818 , D4._failureOffendingData = AP.Pointer [AP.Token "0"]
1919 }
2020
21−subsetOfData :: Value
22−subsetOfData =
23− -- This is the only really interesting part of this example. To resolve the
24− -- pointer to the part of the data that triggered the validation failure we
25− -- have to have hjsonpointer in our build-depends and use 'AP.resolve'.
21+example :: IO ()
22+example =
23+ -- 'D4.Failure's contain the sequence of embedded validators that caused
24+ -- the invalidation, the contents of the final validator in that sequence,
25+ -- and a JSON Pointer to the subset of data that caused validation to fail.
26+ --
27+ -- They don't actually contain that subset of data, since it can be derived
28+ -- from the original data and the JSON Pointer.
29+ --
30+ -- 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.
33+ --
34+ -- NOTE: You have to have hjsonpointer in your build-depends.
2635 case AP.resolve (D4._failureOffendingData failure) badData of
2736 Left _ -> error "Couldn't resolve pointer."
28− Right v -> v
37+ Right _ -> putStrLn "Success." -- We could feed the 'Right' value into
38+ -- 'msg' if we wanted to display it.
2939
30−example :: IO ()
31−example = putStrLn . unlines $
40+msg :: Value -> String
41+msg subsetOfData = unlines
3242 [ "Invalid data. Here's the sequence of validators that caught it:"
3343 , ""
3444 , " " <> show (D4._failureValidatorsCalled failure)
hjsonschema.cabal+2−1
@@ -103,7 +103,8 @@ test-suite remote
103103 , wai-app-static
104104 , warp
105105
106−executable example
106+test-suite example
107+ type: exitcode-stdio-1.0
107108 hs-source-dirs: examples
108109 main-is: Main.hs
109110 other-modules: CustomSchema