2 using System.Collections;
6 using System.Xml.XPath;
11 namespace MonoTests.oasis_xslt {
12 public class SuiteBuilder {
13 #region test list fields
14 IDictionary expectedExceptions = new Hashtable ();
15 ArrayList skipTargets = new ArrayList ();
16 ArrayList knownFailures = new ArrayList ();
17 ArrayList fixmeList = new ArrayList ();
21 SuiteBuilder (TestSuite suite)
28 string exceptionsFilename = Path.Combine (EnvOptions.OutputDir, "res-exceptions.lst");
30 Helpers.ReadStrings (skipTargets, "ignore.lst");
31 Helpers.ReadStrings (knownFailures, "knownFailures.lst");
32 Helpers.ReadStrings (fixmeList, "fixme.lst");
33 ArrayList exceptionsArray = new ArrayList();
34 Helpers.ReadStrings (exceptionsArray, exceptionsFilename);
35 foreach (string s in exceptionsArray) {
36 string [] halves = s.Split ('\t');
37 expectedExceptions [halves[0]] = halves[1];
43 // if (Environment.GetEnvironmentVariables().Contains("START_DEBUG"))
44 // System.Diagnostics.Debugger.Launch ();
46 XmlDocument whole = new XmlDocument ();
47 whole.Load (@"testsuite/TESTS/catalog-fixed.xml");
49 foreach (XmlElement testCase in whole.SelectNodes ("test-suite/test-catalog/test-case")) {
50 string testid = testCase.GetAttribute ("id");
52 if (skipTargets.Contains (testid))
55 CatalogTestCase ctc = new CatalogTestCase(EnvOptions.OutputDir, testCase);
59 SingleTestTransform stt = new SingleTestTransform (ctc);
61 string expectedException = (string) expectedExceptions[testid];
62 bool isKnownFailure = knownFailures.Contains (testid) || fixmeList.Contains (testid);
64 _suite.Add (new TestFromCatalog (testid, stt, expectedException,
65 EnvOptions.InverseResults, isKnownFailure));
70 public static TestSuite Suite {
72 TestSuite suite = new TestSuite ("MonoTests.oasis_xslt.SuiteBuilder");
73 SuiteBuilder builder = new SuiteBuilder (suite);
80 class TestFromCatalog: NUnit.Core.TestCase {
83 string _expectedException;
84 SingleTestTransform _transform;
86 public TestFromCatalog (string testid, SingleTestTransform transform,
87 string expectedException, bool inverseResult, bool isKnownFailure)
91 _expectedException = expectedException;
92 _transform = transform;
93 _inverseResult = inverseResult;
95 ArrayList arr = new ArrayList ();
97 arr.Add ("KnownFailures");
98 this.IsExplicit = true;
105 string CompareResult (string actual, string expected)
107 //TODO: add xml comparison
108 if (actual == expected)
111 #if !FAILURE_DETAILED_MESSAGE
114 return "Different.\nActual*****\n"+actual+"\nReference*****\n"+expected;
118 string CompareException (Exception actual, string testid)
120 if (_expectedException == null)
121 return "Unexpected exception: " + actual.ToString ();
123 string actualType = actual.GetType ().ToString ();
124 if (actualType != _expectedException)
125 return "Different exception thrown.\nActual*****\n"+actualType+
126 "\nReference*****\n"+_expectedException;
131 void ReportResult (string failureMessage, string stackTrace, TestCaseResult res)
133 if (_inverseResult) {
134 if (failureMessage != null)
137 res.Failure ("The following test was FIXED: "+_testid, null);
140 if (failureMessage != null)
141 res.Failure (failureMessage, stackTrace);
147 public override void Run (TestCaseResult res)
149 _transform.RunTest ();
151 string failureMessage;
152 string stackTrace = null;
153 if (_transform.Succeeded) {
155 using (StreamReader sr = new StreamReader (_transform.TestCase.OutFile))
156 failureMessage = CompareResult (_transform.Result, sr.ReadToEnd ());
159 //if there is no reference result because of expectedException, we
160 //are OK, otherwise, rethrow
161 if (_expectedException!=null)
162 failureMessage = null;
164 Console.WriteLine ("ERROR: No reference result, and no expected exception.");
170 failureMessage = CompareException (_transform.Exception, _testid);
171 stackTrace = _transform.Exception.StackTrace;
174 ReportResult (failureMessage, stackTrace, res);