Skip to content

Commit 92a7e1d

Browse files
authored
Merge pull request #969 from haskell/JSONTestSuite-cleanup
JSONTestSuite cleanup
2 parents 57596db + fd29544 commit 92a7e1d

File tree

652 files changed

+99
-63704
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

652 files changed

+99
-63704
lines changed

aeson.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ test-suite aeson-tests
166166
ErrorMessages
167167
Functions
168168
Instances
169+
JSONTestSuite
169170
Options
170171
Properties
171172
PropertyGeneric

tests/JSONTestSuite.hs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
module JSONTestSuite (tests) where
2+
3+
import Test.Tasty (TestTree, testGroup)
4+
import Data.Either.Compat (isLeft, isRight)
5+
import Test.Tasty.HUnit ( testCase, assertBool )
6+
import System.Directory (getDirectoryContents)
7+
import System.FilePath ((</>), takeExtension, takeFileName)
8+
import Data.List (sort)
9+
import Control.Monad (forM)
10+
11+
import qualified Data.ByteString.Lazy as L
12+
import qualified Data.HashSet as HashSet
13+
14+
import Data.Aeson
15+
16+
jsonTestSuiteTest :: FilePath -> TestTree
17+
jsonTestSuiteTest path = testCase fileName $ do
18+
payload <- L.readFile path
19+
let result = eitherDecode payload :: Either String Value
20+
assertBool (show result) $ case take 2 fileName of
21+
"n_" -> isLeft result
22+
"y_" -> isRight result
23+
"i_" | fileName `HashSet.member` ignore_accepted -> isRight result
24+
| otherwise -> isLeft result
25+
_ | fileName `HashSet.member` transform_rejected -> isLeft result
26+
| otherwise -> isRight result -- test_transform tests have inconsistent names
27+
where
28+
fileName = takeFileName path
29+
30+
-- Build a collection of tests based on the current contents of the
31+
-- JSONTestSuite test directories.
32+
33+
tests :: IO TestTree
34+
tests = do
35+
let suitePath = "tests/JSONTestSuite"
36+
let suites = ["test_parsing", "test_transform"]
37+
testPaths <- fmap (sort . concat) . forM suites $ \suite -> do
38+
let dir = suitePath </> suite
39+
entries <- getDirectoryContents dir
40+
let ok name = takeExtension name == ".json"
41+
return . map (dir </>) . filter ok $ entries
42+
return $ testGroup "JSONTestSuite" $ map jsonTestSuiteTest testPaths
43+
44+
-- The set expected-to-be-failing JSONTestSuite tests.
45+
-- Not all of these failures are genuine bugs.
46+
-- Of those that are bugs, not all are worth fixing.
47+
48+
-- | The @i@ cases we can ignore. We don't.
49+
--
50+
-- @i_@ - parsers are free to accept or reject content
51+
--
52+
-- We specify which @i_@ case we accept, so we can catch changes even in unspecified behavior.
53+
-- (There is less case we accept)
54+
ignore_accepted :: HashSet.HashSet FilePath
55+
ignore_accepted = HashSet.fromList
56+
[ "i_number_double_huge_neg_exp.json"
57+
, "i_number_huge_exp.json"
58+
, "i_number_neg_int_huge_exp.json"
59+
, "i_number_pos_double_huge_exp.json"
60+
, "i_number_real_neg_overflow.json"
61+
, "i_number_real_pos_overflow.json"
62+
, "i_number_real_underflow.json"
63+
, "i_number_too_big_neg_int.json"
64+
, "i_number_too_big_pos_int.json"
65+
, "i_number_very_big_negative_int.json"
66+
, "i_structure_500_nested_arrays.json"
67+
]
68+
69+
-- | Transform folder contain weird structures and characters that parsers may understand differently.
70+
--
71+
-- We don't even try to understand some.
72+
transform_rejected :: HashSet.HashSet FilePath
73+
transform_rejected = HashSet.fromList
74+
[ "string_1_escaped_invalid_codepoint.json"
75+
, "string_1_invalid_codepoint.json"
76+
, "string_2_escaped_invalid_codepoints.json"
77+
, "string_2_invalid_codepoints.json"
78+
, "string_3_escaped_invalid_codepoints.json"
79+
, "string_3_invalid_codepoints.json"
80+
]

tests/JSONTestSuite/README.md

Lines changed: 0 additions & 50 deletions
This file was deleted.

0 commit comments

Comments
 (0)