~ubuntu-branches/ubuntu/karmic/moon/karmic

« back to all changes in this revision

Viewing changes to test/harness/test-runner/ConsoleReport.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-14 12:01:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090214120108-06539vb25vhbd8bn
Tags: upstream-1.0
ImportĀ upstreamĀ versionĀ 1.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Permission is hereby granted, free of charge, to any person obtaining
 
2
// a copy of this software and associated documentation files (the
 
3
// "Software"), to deal in the Software without restriction, including
 
4
// without limitation the rights to use, copy, modify, merge, publish,
 
5
// distribute, sublicense, and/or sell copies of the Software, and to
 
6
// permit persons to whom the Software is furnished to do so, subject to
 
7
// the following conditions:
 
8
//
 
9
// The above copyright notice and this permission notice shall be
 
10
// included in all copies or substantial portions of the Software.
 
11
//
 
12
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
13
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
14
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
15
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
16
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
17
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
18
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
19
//
 
20
// Copyright (c) 2007-2008 Novell, Inc.
 
21
//
 
22
// Authors:
 
23
//      Jackson Harper (jackson@ximian.com)
 
24
//
 
25
 
 
26
 
 
27
using System;
 
28
using System.Collections;
 
29
 
 
30
namespace MoonlightTests {
 
31
 
 
32
        public class ConsoleReport : IReport {
 
33
 
 
34
                private TestRun run;
 
35
 
 
36
                public void BeginRun (TestRun run)
 
37
                {
 
38
                        this.run = run;
 
39
 
 
40
                        Console.WriteLine ("Running tests...");
 
41
                }
 
42
 
 
43
                public void Executing (Test test)
 
44
                {
 
45
                        
 
46
                }
 
47
 
 
48
                public void EndRun ()
 
49
                {
 
50
                        Console.WriteLine ("\n");
 
51
 
 
52
                        ReportIgnoredTests ();
 
53
                        ReportFailedTests ();
 
54
                        ReportPassedTests ();
 
55
                        
 
56
                        ReportSummary ();
 
57
                        //ReportAllTests ();
 
58
                }
 
59
 
 
60
                public void AddResult (Test test, TestResult result)
 
61
                {
 
62
                        string state = string.Empty;
 
63
                        ConsoleColor color;
 
64
                        
 
65
                        switch (result) {
 
66
                        case TestResult.Pass:
 
67
                                color = ConsoleColor.Green;
 
68
                                state = run.VerboseLevel != VerboseLevel.None ? "P" : ".";
 
69
                                break;
 
70
                        case TestResult.Ignore:
 
71
                                color = ConsoleColor.White;
 
72
                                state = "I";
 
73
                                break;
 
74
                        case TestResult.Fail:
 
75
                                color = ConsoleColor.Red;
 
76
                                state = "F";
 
77
                                break;
 
78
                        case TestResult.KnownFailure:
 
79
                                color = ConsoleColor.Blue;
 
80
                                state = "K";
 
81
                                break;
 
82
                        case TestResult.UnexpectedPass:
 
83
                                color = ConsoleColor.Cyan;
 
84
                                state = "U";
 
85
                                break;
 
86
                        default:
 
87
                                color = ConsoleColor.Green;
 
88
                                state = "?";
 
89
                                break;
 
90
                        }
 
91
 
 
92
                        if (!run.Runner.Driver.UseGdb)
 
93
                                Console.ForegroundColor = color;
 
94
                        
 
95
                        if (run.VerboseLevel != VerboseLevel.None)
 
96
                                Console.Write ("{0} ({1}):  ", test.InputFile, test.Id);
 
97
                        Console.Write (state);
 
98
                        if (run.VerboseLevel != VerboseLevel.None)
 
99
                                Console.WriteLine ();
 
100
                        
 
101
                        if (!run.Runner.Driver.UseGdb)
 
102
                                Console.ResetColor ();
 
103
                        
 
104
                }
 
105
 
 
106
                private void ReportAllTests ()
 
107
                {
 
108
                        Console.WriteLine ("========================= Test Summary =========================");
 
109
                        foreach (Test t in run.Tests)
 
110
                                AddResult (t, t.Result);
 
111
                        Console.WriteLine ("Tests run:  {0}  {1} Pass, {2} Ignored,  {3} Failures,  {4} Known Failures",
 
112
                                        run.ExecutedTests.Count, run.PassedTests.Count, run.IgnoredTests.Count, run.FailedTests.Count, run.KnownFailures.Count);
 
113
                        Console.WriteLine ("");
 
114
                }
 
115
                
 
116
                private void ReportIgnoredTests ()
 
117
                {
 
118
                        if (run.IgnoredTests.Count < 1)
 
119
                                return;
 
120
 
 
121
                        Console.WriteLine ("========================= Ignored Tests =========================");
 
122
                        foreach (Test t in run.IgnoredTests) {
 
123
                                Console.WriteLine ("Ignored:  {0} -- {1}", t.InputFile, t.IgnoreReason);
 
124
                        }
 
125
 
 
126
                        Console.WriteLine ("\n");
 
127
                }
 
128
 
 
129
                private void ReportFailedTests ()
 
130
                {
 
131
                        if (run.FailedTests.Count < 1)
 
132
                                return;
 
133
 
 
134
                        Console.WriteLine ("========================= Failed Tests ==========================");
 
135
                        foreach (Test t in run.FailedTests) {
 
136
                                Console.WriteLine ("Failed:  {0} ({2}) -- {1}", t.InputFile, t.FailedReason, t.Id);
 
137
                                if (run.VerboseLevel >= VerboseLevel.ShowShockerLines) {
 
138
                                        Console.WriteLine ("  Log Lines:");
 
139
                                        foreach (string str in run.LoggingServer.GetTestLogLines (t.InputFileName)) {
 
140
                                                Console.WriteLine ("    {0}", str);
 
141
                                        }
 
142
                                }
 
143
                                /*
 
144
                                if (run.VerboseLevel >= VerboseLevel.ShowStderr) {
 
145
                                        Console.WriteLine ("  Stderr:");
 
146
                                        foreach (string str in t.Stderr.Split (Environment.NewLine [0])) {
 
147
                                                Console.WriteLine ("    {0}", str);
 
148
                                        }
 
149
                                }
 
150
                                if (run.VerboseLevel >= VerboseLevel.ShowStdout) {
 
151
                                        Console.WriteLine ("  Stdout:");
 
152
                                        foreach (string str in t.Stdout.Split (Environment.NewLine [0])) {
 
153
                                                Console.WriteLine ("    {0}", str);
 
154
                                        }
 
155
                                }
 
156
                                */
 
157
                        }
 
158
 
 
159
                        Console.WriteLine ("\n");
 
160
                }
 
161
 
 
162
                private void ReportPassedTests ()
 
163
                {
 
164
                        // TODO:  This should only happen when we run-known-failures-only
 
165
                }
 
166
 
 
167
                private void ReportSummary ()
 
168
                {
 
169
                        Console.WriteLine ("Tests run:  {0}  {1} Pass, {2} Ignored,  {3} Failures,  {4} Known Failures",
 
170
                                        run.ExecutedTests.Count, run.PassedTests.Count, run.IgnoredTests.Count, run.FailedTests.Count, run.KnownFailures.Count);
 
171
                }
 
172
 
 
173
        }
 
174
}
 
175