Debian Codegraph @

mcs/class/Commons.Xml.Relaxng/Test/standalone_tests/anglia-test-runner.cs

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