git.iko.soy/typeable/hjsonschema
on master help sign in
No need for examples to have their own test suite.
d69cd9eIan Grant Jeffries
examples/Main.hsdeleted−19
@@ -1,19 +0,0 @@
1−
2−module Main where
3−
4−import Test.Tasty (TestTree, defaultMain, testGroup)
5−import qualified Test.Tasty.HUnit as HU
6−
7−import qualified CustomSchema as C
8−import qualified PrettyShowFailure as P
9−import qualified Standard as S
10−
11−main :: IO ()
12−main = defaultMain (testGroup "Check Examples" exampleTests)
13−
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− ]
hjsonschema.cabal+6−18
@@ -61,11 +61,17 @@ library
61test-suite local
61test-suite local
62 type: exitcode-stdio-1.0
62 type: exitcode-stdio-1.0
63 hs-source-dirs: tests
63 hs-source-dirs: tests
64+ examples
64 main-is: Local.hs
65 main-is: Local.hs
65 other-modules: Local.Failure
66 other-modules: Local.Failure
66 , Local.Filesystem
67 , Local.Filesystem
67 , Local.Reference
68 , Local.Reference
68 , Shared
69 , Shared
70+ -- from ./examples:
71+ , CustomSchema
72+ , PrettyShowFailure
73+ , Standard
74+
69 default-language: Haskell2010
75 default-language: Haskell2010
70 ghc-options: -Wall -fno-warn-orphans
76 ghc-options: -Wall -fno-warn-orphans
71 default-extensions: OverloadedStrings
77 default-extensions: OverloadedStrings
@@ -108,24 +114,6 @@ test-suite remote
108 , wai-app-static
114 , wai-app-static
109 , warp
115 , warp
110
116
111−test-suite example
112− type: exitcode-stdio-1.0
113− hs-source-dirs: examples
114− main-is: Main.hs
115− other-modules: CustomSchema
116− , PrettyShowFailure
117− , Standard
118− default-language: Haskell2010
119− ghc-options: -Wall
120− build-depends: aeson
121− , base
122− , hjsonpointer
123− , hjsonschema
124− , tasty
125− , tasty-hunit
126− , text
127− , vector
128−
129source-repository head
117source-repository head
130 type: git
118 type: git
131 location: git://github.com/seagreen/hjsonschema.git
119 location: git://github.com/seagreen/hjsonschema.git
tests/Local.hs+22−4
@@ -7,9 +7,15 @@ import Data.Aeson
7import Data.List (isSuffixOf)
7import Data.List (isSuffixOf)
8import Data.Monoid
8import Data.Monoid
9import System.Directory (getDirectoryContents)
9import System.Directory (getDirectoryContents)
10−import Test.Tasty (defaultMain, testGroup)
10+import Test.Tasty (TestTree, defaultMain, testGroup)
11+import qualified Test.Tasty.HUnit as HU
11import Test.Tasty.QuickCheck (testProperty)
12import Test.Tasty.QuickCheck (testProperty)
12
13
14+-- Examples
15+import qualified CustomSchema as C
16+import qualified PrettyShowFailure as P
17+import qualified Standard as S
18+
13import Data.JsonSchema.Draft4
19import Data.JsonSchema.Draft4
14import Local.Failure (correctPaths)
20import Local.Failure (correctPaths)
15import Local.Filesystem (fetchFromFilesystem)
21import Local.Filesystem (fetchFromFilesystem)
@@ -24,11 +30,23 @@ main = do
24 filenames <- filter isLocal . filter (".json" `isSuffixOf`) <$> getDirectoryContents dir
30 filenames <- filter isLocal . filter (".json" `isSuffixOf`) <$> getDirectoryContents dir
25 ts <- readSchemaTests dir filenames
31 ts <- readSchemaTests dir filenames
26 defaultMain . testGroup "Tests not requiring an HTTP server" $
32 defaultMain . testGroup "Tests not requiring an HTTP server" $
27− testProperty "Invert schemas through JSON without change" invertSchema
33+ testGroup "Check that examples compile" exampleTests
34+ : testGroup "QuickCheck tests" quickCheckTests
28 : testGroup "Report the path to invalid data correctly" correctPaths
35 : testGroup "Report the path to invalid data correctly" correctPaths
29 : testGroup "Test the referencesViaFilesystem function" fetchFromFilesystem
36 : testGroup "Test the referencesViaFilesystem function" fetchFromFilesystem
30 : testGroup "Test the Reference module" referenceTests
37 : testGroup "Test the Reference module" referenceTests
31 : fmap toTest ts
38 : fmap toTest ts
32
39
40+quickCheckTests :: [TestTree]
41+quickCheckTests =
42+ [testProperty "Invert schemas through JSON without change" invertSchema]
43+ where
33−invertSchema :: Schema -> Bool
44+ invertSchema :: Schema -> Bool
34−invertSchema a = Just a == decode (encode a)
45+ invertSchema a = Just a == decode (encode a)
46+
47+exampleTests :: [TestTree]
48+exampleTests =
49+ [ HU.testCase "Standard Example" S.example
50+ , HU.testCase "PrettyShowFailure Example" P.example
51+ , HU.testCase "CustomSchema Example" C.example
52+ ]