git.iko.soy/typeable/xsd-parser
on master help sign in
Integrate W3C XML Schema 1.1 test suite (#8)
7e79343Yuras
.gitmodulesnew file+3
@@ -0,0 +1,3 @@
1+[submodule "xsdtests"]
2+ path = xsdtests
3+ url = git@github.com:w3c/xsdtests.git
README.mdnew file+10
@@ -0,0 +1,10 @@
1+
2+# xsd-parser
3+
4+Library for parsing XML schema files.
5+
6+# W3C XML Schema 1.1 test suite
7+
8+The test suite is designed mostly to test validation, but at least we
9+can check whether we are able to parse all the xsd files from the
10+test suite. See results [here](xsts.md).
xsd-parser.cabal+12
@@ -62,3 +62,15 @@ test-suite spec
62 , xsd-parser
62 , xsd-parser
63 default-language: Haskell2010
63 default-language: Haskell2010
64 ghc-options: -Wall
64 ghc-options: -Wall
65+
66+test-suite xsts
67+ type: exitcode-stdio-1.0
68+ hs-source-dirs: xsts-test
69+ main-is: Main.hs
70+ build-depends: base
71+ , text
72+ , filepath
73+ , xml-conduit
74+ , xsd-parser
75+ default-language: Haskell2010
76+ ghc-options: -Wall
xsdtestsnew file+1

Submodule changed.

xsts-test/Main.hsnew file+163
@@ -0,0 +1,163 @@
1+{-# LANGUAGE OverloadedStrings #-}
2+
3+module Main
4+( main
5+)
6+where
7+
8+import Data.Text (Text)
9+import qualified Data.Text as Text
10+import Data.IORef
11+import Control.Monad
12+import Control.Exception
13+import System.FilePath
14+import System.IO.Unsafe (unsafePerformIO)
15+import qualified System.IO as IO
16+import Text.XML
17+import Text.XML.Cursor
18+
19+import qualified Xsd
20+
21+data Stat = Stat
22+ { statTestSet :: Text
23+ , statTotal :: Int
24+ , statSucceeded :: Int
25+ }
26+ deriving (Show)
27+
28+{-# NOINLINE errRef #-}
29+errRef :: IORef Int
30+errRef = unsafePerformIO (newIORef 0)
31+
32+{-# NOINLINE okRef #-}
33+okRef :: IORef Int
34+okRef = unsafePerformIO (newIORef 0)
35+
36+{-# NOINLINE statsRef #-}
37+statsRef :: IORef [Stat]
38+statsRef = unsafePerformIO (newIORef [])
39+
40+dumpResults :: [Stat] -> IO ()
41+dumpResults stats = IO.withFile "xsts.md" IO.WriteMode $ \h -> do
42+ IO.hPutStrLn h "This table is generated automatically by `xsts` test."
43+ IO.hPutStrLn h "It contains number of xsd files successfully parsed."
44+ IO.hPutStrLn h "Note that we don't currently attempt to validate xml files"
45+ IO.hPutStrLn h "against the schemata."
46+ IO.hPutStrLn h ""
47+ IO.hPutStrLn h "Test set | Total tests | Passed tests"
48+ IO.hPutStrLn h "--- | --- | ---"
49+ forM_ stats $ \s -> do
50+ IO.hPutStrLn h $ mconcat
51+ [ Text.unpack (statTestSet s), " | "
52+ , show (statTotal s), " | "
53+ , show (statSucceeded s)
54+ ]
55+
56+expectedFailures :: Int
57+expectedFailures = 5316
58+
59+main :: IO ()
60+main = do
61+ let path = "./xsdtests/suite.xml"
62+ doc <- Text.XML.readFile def path
63+ runSuite path (fromDocument doc)
64+ oks <- readIORef okRef
65+ readIORef statsRef >>= dumpResults
66+ putStrLn $ "Succeeded: " ++ show oks
67+ errs <- readIORef errRef
68+ putStrLn $ "Failed: " ++ show errs
69+ unless (errs == expectedFailures) $
70+ fail $ "There were " ++ show errs ++ " errors, expected "
71+ ++ show expectedFailures
72+
73+runSuite :: FilePath -> Cursor -> IO ()
74+runSuite path c = mapM_ (runTestSetRef dir) (c $/ laxElement "testSetRef")
75+ where
76+ dir = takeDirectory path
77+
78+runTestSetRef :: FilePath -> Cursor -> IO ()
79+runTestSetRef dir c = do
80+ ref <- theAttribute c "href"
81+ let path = normalise (dir </> Text.unpack ref)
82+ runTestSet path
83+
84+runTestSet :: FilePath -> IO ()
85+runTestSet path = do
86+ doc <- Text.XML.readFile def path
87+ let c = fromDocument doc
88+ name <- theAttribute c "name"
89+ putStrLn ("----- Test set " <> Text.unpack name)
90+ results <- mapM (runTestGroup dir) (c $/ laxElement "testGroup")
91+ let
92+ stat = Stat
93+ { statTestSet = name
94+ , statTotal = (sum . map fst) results
95+ , statSucceeded = (sum . map snd) results
96+ }
97+ modifyIORef' statsRef (stat :)
98+ where
99+ dir = takeDirectory path
100+
101+runTestGroup :: FilePath -> Cursor -> IO (Int, Int)
102+runTestGroup dir c = do
103+ name <- theAttribute c "name"
104+ results <- mapM (runSchemaTest dir name) (aChild c "schemaTest")
105+ case join results of
106+ Nothing -> return (0, 0)
107+ Just True -> return (1, 1)
108+ Just False -> return (1, 0)
109+
110+runSchemaTest :: FilePath -> Text -> Cursor -> IO (Maybe Bool)
111+runSchemaTest dir groupName c = do
112+ path <- do
113+ c' <- theChild c "schemaDocument"
114+ theAttribute c' "href"
115+ mvalid <- do
116+ c' <- theChild c "expected"
117+ valid <- theAttribute c' "validity"
118+ case valid of
119+ "valid" -> return (Just True)
120+ "invalid" -> return (Just False)
121+ _ -> return Nothing
122+ case mvalid of
123+ Nothing -> return Nothing -- indetermined
124+ Just valid -> do
125+ res <- try (Xsd.getSchema (dir </> Text.unpack path))
126+ case (res, valid) of
127+ (Left _, False) -> do
128+ modifyIORef' okRef succ
129+ return (Just True)
130+ (Right _, True) -> do
131+ modifyIORef' okRef succ
132+ return (Just True)
133+ (Right _, False) -> do
134+ modifyIORef' errRef succ
135+ putStrLn $ "invalid xsd passed: " <> Text.unpack groupName
136+ <> " (" <> dir </> Text.unpack path <> ")"
137+ return (Just False)
138+ (Left err, True) -> do
139+ modifyIORef' errRef succ
140+ putStrLn $ "valid xsd didn't pass: " <> Text.unpack groupName
141+ <> " (" <> dir </> Text.unpack path <> ")"
142+ <> ": " <> show (err :: SomeException)
143+ return (Just False)
144+
145+anAttribute :: Cursor -> Text -> Maybe Text
146+anAttribute c name = case c $| laxAttribute name of
147+ (a:_) -> Just a
148+ _ -> Nothing
149+
150+theAttribute :: Cursor -> Text -> IO Text
151+theAttribute c name = maybe err return (anAttribute c name)
152+ where
153+ err = fail $ "no attribute " <> Text.unpack name
154+
155+aChild :: Cursor -> Text -> Maybe Cursor
156+aChild c name = case c $/ laxElement name of
157+ (a:_) -> Just a
158+ _ -> Nothing
159+
160+theChild :: Cursor -> Text -> IO Cursor
161+theChild c name = case aChild c name of
162+ Just a -> return a
163+ _ -> fail $ "no element " <> Text.unpack name
xsts.mdnew file+100
@@ -0,0 +1,100 @@
1+This table is generated automatically by `xsts` test.
2+It contains number of xsd files successfully parsed.
3+Note that we don't currently attempt to validate xml files
4+against the schemata.
5+
6+Test set | Total tests | Passed tests
7+--- | --- | ---
8+yearMonthDuration | 25 | 9
9+XSImportReference | 1 | 1
10+XPathDefaultNSonKeyKeyRefUnique | 13 | 11
11+XML11Support | 11 | 11
12+wildcard | 17 | 9
13+VC | 6 | 5
14+unsignedIntegers | 8 | 8
15+UnitsLength | 8 | 7
16+union | 19 | 6
17+CTA | 6 | 4
18+TypeAlternativeTests | 23 | 8
19+time | 1 | 1
20+TargetNS | 2 | 0
21+substitutionGroup | 5 | 2
22+rf-whiteSpace | 2 | 2
23+RestrictionOfComplexTypes | 13 | 11
24+RegularExpression | 8 | 8
25+PopenContent | 24 | 15
26+list | 2 | 1
27+IdentityConstraint | 12 | 7
28+ID_IDREF | 77 | 44
29+gMonth | 1 | 0
30+gDay | 1 | 1
31+gMonthDay | 1 | 1
32+gYear | 1 | 1
33+gYearMonth | 1 | 1
34+float | 2 | 2
35+explicitTimezone | 18 | 6
36+EDCWildcard | 2 | 2
37+double | 2 | 2
38+DefaultFixed | 5 | 2
39+defaultAttributesApply | 17 | 14
40+dayTimeDuration | 24 | 8
41+dateTimeStamp | 28 | 7
42+date | 1 | 1
43+CyclicDependencies_Redefine_Include_Import_Override | 5 | 1
44+constraintsOnAttribute | 16 | 12
45+ConditionalInclusion | 3 | 1
46+assertion | 51 | 40
47+Assert | 35 | 24
48+anyAttribute | 9 | 7
49+allGroup | 9 | 8
50+IRI | 1 | 0
51+substitution-groups | 6 | 0
52+Zone | 9 | 5
53+Zone | 20 | 16
54+XmlVersions | 13 | 13
55+Wild | 84 | 52
56+VC | 24 | 9
57+TargetNS | 4 | 0
58+Subsgroup | 6 | 3
59+Simple | 58 | 31
60+Override | 30 | 20
61+Open | 51 | 25
62+Missing | 6 | 4
63+Id | 32 | 7
64+CTA | 44 | 13
65+Complex | 25 | 7
66+Assert | 34 | 2
67+All | 62 | 33
68+BoeingXSDTestCases | 6 | 0
69+MS-Wildcards2006-07-15 | 315 | 195
70+MS-SimpleType2006-07-15 | 333 | 146
71+MS-Schema2006-07-15 | 124 | 56
72+MS-Regex2006-07-15 | 2590 | 1988
73+MS-Particles2006-07-15 | 855 | 398
74+MS-Notations2006-07-15 | 116 | 42
75+MS-ModelGroups2006-07-15 | 391 | 190
76+MS-IdentityConstraint2006-07-15 | 844 | 229
77+MS-Group2006-07-15 | 218 | 73
78+MS-Errata102006-07-15 | 19 | 8
79+MS-Element2006-07-15 | 355 | 138
80+MS-DataTypes2006-07-15 | 2247 | 1078
81+MS-ComplexType2006-07-15 | 550 | 262
82+MS-Attribute2006-07-15 | 279 | 138
83+MS-AttributeGroup2006-07-15 | 114 | 67
84+MS-Annotations2006-07-15 | 80 | 51
85+MS-Additional2006-07-15 | 253 | 134
86+Wildcard | 26 | 22
87+Schema | 6 | 0
88+SType | 138 | 123
89+Notation | 13 | 8
90+MGroupDef | 19 | 10
91+MGroup | 40 | 30
92+IdConstrDefs | 27 | 21
93+ElemDecl | 227 | 86
94+CType | 31 | 15
95+AttrUse | 4 | 1
96+AttrDecl | 83 | 71
97+AGroupDef | 13 | 7
98+suntest | 52 | 19
99+NIST2004-01-14 | 3953 | 3873
100+introspection | 1 | 0