* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / Commons.Xml.Relaxng / Test / standalone_tests / anglia-test-runner.cs
1 using System;\r
2 using System.IO;\r
3 using System.Xml;\r
4 using Commons.Xml.Relaxng;\r
5 using Commons.Xml.Relaxng.Rnc;\r
6 \r
7 public class Driver\r
8 {\r
9         public static void Main (string [] args)\r
10         {\r
11                 bool outAll = false;\r
12                 bool details = false;\r
13                 bool stopOnError = false;\r
14                 string filter = null;\r
15                 foreach (string arg in args) {\r
16                         switch (arg) {\r
17                         case "--outall":\r
18                                 outAll = true; break;\r
19                         case "--details":\r
20                                 details = true; break;\r
21                         case "--stoponerror":\r
22                                 stopOnError = true; break;\r
23                         default:\r
24                                 filter = arg; break;\r
25                         }\r
26                 }\r
27 \r
28                 try {\r
29                         XmlDocument doc = new XmlDocument ();\r
30                         doc.Load ("test/RNCTest.xml");\r
31                         int success = 0;\r
32                         int failure = 0;\r
33                         foreach (XmlElement el in doc.SelectNodes ("/RNCTestCases/TestCase")) {\r
34                                 string id = el.GetAttribute ("id");\r
35                                 if (filter != null && id.IndexOf (filter) < 0)\r
36                                         continue;\r
37                                 if (outAll)\r
38                                         Console.WriteLine ("testing " + id);\r
39                                 bool isValid = el.GetAttribute ("legal") == "true";\r
40                                 RncParser p = new RncParser (new NameTable ());\r
41                                 try {\r
42                                         string s = new StreamReader ("test" + Path.DirectorySeparatorChar + el.GetAttribute ("path")).ReadToEnd ();\r
43                                         p.Parse (new StringReader (s));\r
44                                         if (isValid) {\r
45                                                 success++;\r
46 //                                              Console.Error.WriteLine ("valid " + id);\r
47                                         } else {\r
48                                                 failure++;\r
49                                                 Console.Error.WriteLine ("INCORRECTLY VALID   " + id);\r
50                                         }\r
51                                 } catch (Exception ex) {\r
52                                         if (isValid) {\r
53                                                 if (stopOnError)\r
54                                                         throw;\r
55                                                 failure++;\r
56                                                 Console.Error.WriteLine ("INCORRECTLY INVALID " + id + " --> " + (details ? ex.ToString () : ex.Message));\r
57                                         } else {\r
58                                                 success++;\r
59 //                                              Console.Error.WriteLine ("invalid " + id);\r
60                                         }\r
61                                 }\r
62                         }\r
63                         Console.Error.WriteLine ("Total success: " + success);\r
64                         Console.Error.WriteLine ("Total failure: " + failure);\r
65                 } catch (Exception ex) {\r
66                         Console.Error.WriteLine ("Unexpected Exception: " + ex);\r
67                 }\r
68         }\r
69 }\r