7import qualified Data.List.NonEmpty as NE
8import qualified System.Timeout as TO
10import Test.QuickCheck (property)
12import qualified JSONSchema.Draft4 as D4
13import qualified JSONSchema.Types as JT
14import qualified Local.Failure
15import qualified Local.Validation
16import qualified Local.Reference
20import qualified AlternateSchema
21import qualified Simple
22import qualified TwoStep
25dir = "JSON-Schema-Test-Suite/tests/draft4"
27supplementDir :: FilePath
28supplementDir = "test/supplement"
33 -- Language agnostic tests
36 (\a -> not (isHTTPTest a || skipOptional a))
38 -- Custom supplements to the language agnostic tests
39 supplementTs <- readSchemaTests
41 (\a -> not (isHTTPTest a || skipOptional a))
44 describe "Examples" exampleTests
45 describe "QuickCheck" quickCheckTests
46 describe "Failure" Local.Failure.spec
47 describe "JSONSchema.Validator.Reference" Local.Reference.spec
48 describe "Supplementary validation tests written in Haskell"
51 describe "Supplementary tests written in JSON (using the record based schema)"
52 (traverse_ (toTest (fmap timeout . validate)) supplementTs)
53 describe "Supplementary tests written in JSON (using the 'Value' based schema)"
54 (traverse_ (toTest (fmap timeout . validateExample)) supplementTs)
56 describe "Language agnostic tests (using the record based schema)"
57 (traverse_ (toTest validate) ts)
58 describe "Language agnostic tests (using the 'Value' based schema)"
59 (traverse_ (toTest validateExample) ts)
61 timeout :: Expectation -> Expectation
63 res <- TO.timeout 3000000 f
65 Nothing -> expectationFailure "timeout expired"
68 validate :: D4.Schema -> SchemaTestCase -> Expectation
70 res <- D4.fetchHTTPAndValidate (D4.SchemaWithURI s Nothing) (_scData sc)
71 let failures = case res of
73 Left (D4.HVData a) -> NE.toList (D4._invalidFailures a)
74 other -> panic ("Local.validate error: "
76 assertResult sc failures
78 validateExample :: JT.Schema -> SchemaTestCase -> Expectation
79 validateExample s sc = do
80 res <- AlternateSchema.referencesViaHTTP (D4.SchemaWithURI s Nothing)
82 Left e -> panic ("Local.validateExample error: " <> show e)
84 let failures = AlternateSchema.validate
86 (D4.SchemaWithURI s Nothing)
88 assertResult sc failures
90quickCheckTests :: Spec
92 it "schemas invert through JSON without change" $ do
95 invertSchema :: D4.Schema -> Bool
96 invertSchema a = Just a == decode (encode a)
100 it "Simple.example compiles successfully" Simple.example
101 it "TwoStep.example compiles successfully" TwoStep.example
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list