2 using System.Collections.Generic;
\r
9 public class NUnitReport
\r
11 private static string input_dir = string.Empty;
\r
12 private static string output_file = string.Empty;
\r
14 static void Main (string[] args)
\r
16 if (args.Length != 2) {
\r
17 Console.WriteLine ("Expected Usage:");
\r
18 Console.WriteLine (" mono NUnitReport.exe input_directory output_file");
\r
22 // Get our input directory and our output file
\r
23 input_dir = args[0];
\r
24 output_file = args[1];
\r
26 // Start the output file
\r
27 StreamWriter sw = new StreamWriter (output_file);
\r
35 // Loop through the inputs, outputting the results to the output file
\r
36 foreach (string file in Directory.GetFiles (input_dir)) {
\r
39 Dictionary<string, FailedTest> failed_tests = new Dictionary<string,FailedTest> ();
\r
40 List<string> ignored_tests = new List<string> ();
\r
42 int tests_passed = PopulateFailureTable (file, failed_tests, ignored_tests);
\r
44 fail_total += failed_tests.Count;
\r
45 pass_total += tests_passed;
\r
46 run_total += failed_tests.Count + tests_passed;
\r
48 if (failed_tests.Count > 0) {
\r
49 sw.WriteLine (" <tr class='errorrow' onclick=\"toggle('el{0}')\" onmouseover='highlight(this)' onmouseout='unhighlight(this)'>", assembly);
\r
50 sw.WriteLine (@" <td><img src='Media/fail.png' /></td>");
\r
52 sw.WriteLine (@" <tr>");
\r
53 sw.WriteLine (@" <td><img src='Media/pass.png' /></td>");
\r
56 sw.WriteLine (@" <td>{0}</td>", Path.GetFileName (file));
\r
57 sw.WriteLine (@" <td>{0}</td>", failed_tests.Count);
\r
58 sw.WriteLine (@" <td>{0}</td>", tests_passed);
\r
59 sw.WriteLine (@" <td>{0}</td>", tests_passed + failed_tests.Count);
\r
60 sw.WriteLine (@" </tr>");
\r
62 if (failed_tests.Count == 0)
\r
65 sw.WriteLine (@" <tr id='el{0}' class='errorlist' style='display: none'>", assembly);
\r
66 sw.WriteLine (@" <td></td>");
\r
67 sw.WriteLine (@" <td colspan='4'>");
\r
68 sw.WriteLine (@" <table cellpadding='2' cellspacing='0' width='100%'>");
\r
72 foreach (FailedTest ft in failed_tests.Values) {
\r
73 sw.WriteLine (" <tr onclick=\"toggle('as{0}ed{1}')\" onmouseover='highlight(this)' onmouseout='unhighlight(this)'>", assembly, test_num);
\r
74 sw.WriteLine (@" <td style='width: 17px'><img src='Media/bullet.png' /></td>");
\r
75 sw.WriteLine (@" <td>{0}</td>", ft.Name);
\r
76 sw.WriteLine (@" </tr>");
\r
77 sw.WriteLine (@" <tr id='as{0}ed{1}' class='errordetail' style='display: none'>", assembly, test_num);
\r
78 sw.WriteLine (@" <td></td>");
\r
79 sw.WriteLine (@" <td>");
\r
80 sw.WriteLine (@"{0}", ft.Message.Trim ().Trim ('\n').Replace ("\n", "<br/>"));
\r
81 if (!string.IsNullOrEmpty (ft.StackTrace.Trim ()))
\r
82 sw.WriteLine (@"<br /><br /><strong>StackTrace:</strong><br />{0}", ft.StackTrace.Replace ("\n", "<br/>"));
\r
83 sw.WriteLine (@" </td>");
\r
84 sw.WriteLine (@" </tr>");
\r
89 sw.WriteLine (@" </table>");
\r
90 sw.WriteLine (@" </td>");
\r
91 sw.WriteLine (@" </tr>");
\r
95 WriteTotals (sw, fail_total, pass_total, run_total);
\r
97 // Finish up the output file
\r
103 public static int PopulateFailureTable (string filename, Dictionary<string, FailedTest> output, List<string> ignored)
\r
105 XmlDocument doc = new XmlDocument ();
\r
106 doc.Load (filename);
\r
108 return FindTestCases (doc.DocumentElement, output, ignored);
\r
111 public static int FindTestCases (XmlElement xe, Dictionary<string, FailedTest> output, List<string> ignored)
\r
113 if (xe.Name == "test-case") {
\r
114 OutputFailedTestCase (xe, output, ignored);
\r
120 foreach (XmlElement child in xe.ChildNodes)
\r
121 i += FindTestCases (child, output, ignored);
\r
126 public static void OutputFailedTestCase (XmlElement xe, Dictionary<string, FailedTest> output, List<string> ignored)
\r
128 if (xe.GetAttribute ("executed") == "False")
\r
129 ignored.Add (xe.GetAttribute ("name"));
\r
131 if (xe.GetAttribute ("success") == "True" || xe.GetAttribute ("executed") == "False")
\r
134 FailedTest ft = new FailedTest (xe.GetAttribute ("name"), xe["failure"]["message"].InnerText, xe["failure"]["stack-trace"].InnerText);
\r
135 output[ft.Name] = ft;
\r
138 public static void StartReport (StreamWriter sw)
\r
140 sw.WriteLine (@"<!DOCTYPE html PUBLIC ""-//W3C//DTD XHTML 1.0 Transitional//EN"" ""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"">");
\r
141 sw.WriteLine (@"<html xmlns=""http://www.w3.org/1999/xhtml""><head>");
\r
142 sw.WriteLine (@"<title>Mono: Class Libraries NUnit Test Results</title>");
\r
143 sw.WriteLine (@"<link rel=""stylesheet"" type=""text/css"" href=""Media/style.css"" />");
\r
144 sw.WriteLine (@"<script type=""text/ecmascript"" src=""Media/scripts.js""></script></head>");
\r
145 sw.WriteLine (@"<body>");
\r
146 sw.WriteLine (@" <div class='header'>");
\r
147 sw.WriteLine (@" <div class='headerimage'>");
\r
148 sw.WriteLine (@" <img src='Media/rupert.png' width='48' height='48' />");
\r
149 sw.WriteLine (@" </div>");
\r
150 sw.WriteLine (@" <div class='headertext'>Class Libraries NUnit Test Results</div>");
\r
151 sw.WriteLine (@" </div>");
\r
152 sw.WriteLine (@" <div class='legend'>");
\r
153 sw.WriteLine (@" Generated:<br />");
\r
154 sw.WriteLine (@" {0}<br /><br />", DateTime.Now.ToString ());
\r
155 sw.WriteLine (@" Click on failure row for more details.<br /><br />");
\r
156 sw.WriteLine (@" Icons courtesy of <a href='http://www.famfamfam.com/lab/icons/silk'>famfamfam</a>");
\r
157 sw.WriteLine (@" </div>");
\r
158 sw.WriteLine (@" <table cellpadding='2' cellspacing='0' class='maintable'>");
\r
159 sw.WriteLine (@" <tr class='tableheader'>");
\r
160 sw.WriteLine (@" <td style='width: 17px'></td>");
\r
161 sw.WriteLine (@" <td>Tested Assembly</td>");
\r
162 sw.WriteLine (@" <td>Failed</td>");
\r
163 sw.WriteLine (@" <td>Passed</td>");
\r
164 sw.WriteLine (@" <td>Run</td>");
\r
165 sw.WriteLine (@" </tr>");
\r
168 public static void WriteTotals (StreamWriter sw, int failed, int passed, int run)
\r
170 sw.WriteLine (@" <tr class='tabletotal'>");
\r
171 sw.WriteLine (@" <td style='width: 17px'></td>");
\r
172 sw.WriteLine (@" <td>Totals</td>");
\r
173 sw.WriteLine (@" <td>{0}</td>", failed);
\r
174 sw.WriteLine (@" <td>{0}</td>", passed);
\r
175 sw.WriteLine (@" <td>{0}</td>", run);
\r
176 sw.WriteLine (@" </tr>");
\r
179 public static void FinishReport (StreamWriter sw)
\r
181 sw.WriteLine (@" </table>");
\r
182 sw.WriteLine (@"</body>");
\r
183 sw.WriteLine (@"</html>");
\r