@@ -8,17 +8,15 @@ import Data.Foldable (traverse_)
88import qualified Data.List.NonEmpty as N
99import Data.Monoid
1010import qualified System.Timeout as TO
11−import Test.Tasty (TestTree, defaultMain, testGroup)
12−import qualified Test.Tasty.HUnit as HU
13−import Test.Tasty.QuickCheck (testProperty)
11+import Test.Hspec
12+import Test.QuickCheck (property)
1413
1514import qualified Data.JsonSchema.Draft4 as D4
1615import Data.JsonSchema.Fetch (ReferencedSchemas(..))
1716import qualified Data.JsonSchema.Types as JT
18−import Local.Failure (correctPaths)
19−import Local.Validation (fetchFromFilesystem,
20− generalValidation)
21−import Local.Reference (referenceTests)
17+import qualified Local.Failure
18+import qualified Local.Validation
19+import qualified Local.Reference
2220import Shared
2321
2422-- Examples
@@ -45,47 +43,32 @@ main = do
4543 supplementDir
4644 (\a -> not (isHTTPTest a || skipOptional a))
4745
48− defaultMain . testGroup "Tests not requiring an HTTP server" $
49− [ testGroup
50− "Check that examples compile and don't throw errors"
51− exampleTests
52− , testGroup
53− "QuickCheck tests"
54− quickCheckTests
55− , testGroup
56− "Report the path to invalid data correctly"
57− correctPaths
58− , testGroup
59− "Test the Reference module"
60− referenceTests
61− , testGroup
62− "Test the referencesViaFilesystem function"
63− fetchFromFilesystem
64− , testGroup
65− "Supplementary validation tests written in Haskell"
66− generalValidation
67− , testGroup
68− "Supplementary tests written in JSON (using the record based schema)"
69− (toTest (fmap timeout . validate) <$> supplementTs)
70− , testGroup
71− "Supplementary tests written in JSON (using the 'Value' based schema)"
72− (toTest (fmap timeout . validateExample) <$> supplementTs)
73− , testGroup
74− "Language agnostic local tests (using the record based schema)"
75− (toTest validate <$> ts)
76− , testGroup
77− "Language agnostic local tests (using the 'Value' based schema)"
78− (toTest validateExample <$> ts)
79− ]
46+ hspec $ do
47+ describe "Examples" exampleTests
48+ describe "QuickCheck" quickCheckTests
49+ describe "Failure" Local.Failure.spec
50+ describe "Data.Validator.Reference" Local.Reference.spec
51+ describe "Supplementary validation tests written in Haskell"
52+ Local.Validation.spec
53+
54+ describe "Supplementary tests written in JSON (using the record based schema)"
55+ (traverse_ (toTest (fmap timeout . validate)) supplementTs)
56+ describe "Supplementary tests written in JSON (using the 'Value' based schema)"
57+ (traverse_ (toTest (fmap timeout . validateExample)) supplementTs)
58+
59+ describe "Language agnostic tests (using the record based schema)"
60+ (traverse_ (toTest validate) ts)
61+ describe "Language agnostic tests (using the 'Value' based schema)"
62+ (traverse_ (toTest validateExample) ts)
8063 where
81− timeout :: HU.Assertion -> HU.Assertion
64+ timeout :: Expectation -> Expectation
8265 timeout f = do
8366 res <- TO.timeout 3000000 f
8467 case res of
85− Nothing -> HU.assertFailure "timeout expired"
68+ Nothing -> expectationFailure "timeout expired"
8669 Just a -> pure a
8770
88− validate :: D4.Schema -> SchemaTestCase -> HU.Assertion
71+ validate :: D4.Schema -> SchemaTestCase -> Expectation
8972 validate s sc = do
9073 res <- D4.fetchHTTPAndValidate (D4.SchemaWithURI s Nothing) (_scData sc)
9174 let failures = case res of
@@ -96,7 +79,7 @@ main = do
9679 traverse_ (checkPointer (_scData sc)) failures
9780 assertResult sc failures
9881
99− validateExample :: JT.Schema -> SchemaTestCase -> HU.Assertion
82+ validateExample :: JT.Schema -> SchemaTestCase -> Expectation
10083 validateExample s sc = do
10184 res <- AlternateSchema.referencesViaHTTP (D4.SchemaWithURI s Nothing)
10285 case res of
@@ -108,15 +91,15 @@ main = do
10891 traverse_ (checkPointer (_scData sc)) failures
10992 assertResult sc failures
11093
111−quickCheckTests :: [TestTree]
94+quickCheckTests :: Spec
11295quickCheckTests =
113− [testProperty "Invert schemas through JSON without change" invertSchema]
96+ it "schemas invert through JSON without change" $ do
97+ property invertSchema
11498 where
11599 invertSchema :: D4.Schema -> Bool
116100 invertSchema a = Just a == decode (encode a)
117101
118−exampleTests :: [TestTree]
119−exampleTests =
120− [ HU.testCase "Full example" Full.example
121− , HU.testCase "Simple example" Simple.example
122− ]
102+exampleTests :: Spec
103+exampleTests = do
104+ it "Full.example compiles successfully" Full.example
105+ it "Simple.example compiles successfully" Simple.example