/[escript]/trunk/tools/CppUnitTest/src/TextTestResult.cpp
ViewVC logotype

Contents of /trunk/tools/CppUnitTest/src/TextTestResult.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3150 - (show annotations)
Fri Sep 3 05:40:27 2010 UTC (9 years, 1 month ago) by caltinay
File size: 5618 byte(s)
Removed executable prop from non-executables.

1 //
2 // Permission to reproduce and create derivative works from the Software ("Software Derivative Works")
3 // is hereby granted to you under the copyright of Michael Feathers. Michael Feathers also grants you
4 // the right to distribute the Software and Software Derivative Works.
5 //
6 // Michael Feathers licenses the Software to you on an "AS IS" basis, without warranty of any kind.
7 // Michael Feathers HEREBY EXPRESSLY DISCLAIMS ALL WARRANTIES OR CONDITIONS, EITHER EXPRESS OR IMPLIED,
8 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OR CONDITIONS OF MERCHANTABILITY, NON INFRINGEMENT
9 // AND FITNESS FOR A PARTICULAR PURPOSE.  You are solely responsible for determining the appropriateness
10 // of using the Software and assume all risks associated with the use and distribution of this Software,
11 // including but not limited to the risks of program errors, damage to or loss of data, programs or
12 // equipment, and unavailability or interruption of operations.  MICHAEL FEATHERS WILL NOT BE
13 // LIABLE FOR ANY DIRECT DAMAGES OR FOR ANY SPECIAL, INCIDENTAL, OR INDIRECT DAMAGES OR FOR ANY ECONOMIC
14 // CONSEQUENTIAL DAMAGES (INCLUDING LOST PROFITS OR SAVINGS), EVEN IF MICHAEL FEATHERS HAD BEEN ADVISED
15 // OF THE POSSIBILITY OF SUCH DAMAGE.  Michael Feathers will not be liable for the loss of, or damage
16 // to, your records or data, or any damages claimed by you based on a third party claim.
17 //
18 // You agree to distribute the Software and any Software Derivatives under a license agreement that:
19 //
20 // 1) is sufficient to notify all licensees of the Software and Software Derivatives that Michael
21 // Feathers assumes no liability for any claim that may arise regarding the Software or
22 // Software Derivatives, and
23 // 2) that disclaims all warranties, both express and implied, from Michael Feathers regarding the
24 // Software and Software Derivatives.  (If you include this Agreement with any distribution
25 // of the Software and Software Derivatives you will have meet this requirement) You agree that
26 // you will not delete any copyright notices in the Software.
27 //
28 // This Agreement is the exclusive statement of your rights in the Software as provided by Michael
29 // Feathers. Except for the licenses granted to you in the second paragraph above, no other licenses
30 // are granted hereunder, by estoppel, implication or otherwise.
31 //
32 #include <iostream>
33 #include <iomanip>
34
35 #include "TextTestResult.h"
36 #include "CppUnitException.h"
37 #include "estring.h"
38
39 USING_NAMESPACE_CPPUNITTEST
40
41 void TextTestResult::addError (Test *test, CppUnitException *e)
42 {
43 TestResult::addError (test, e);
44 std::cout << " Error: ";
45 std::cout << e->what() << std::endl;
46 }
47
48 void TextTestResult::addFailure (Test *test, CppUnitException *e)
49 {
50 TestResult::addFailure (test, e);
51 std::cout << " Failure" << std::endl;
52
53 }
54
55 void TextTestResult::startTest (Test *test)
56 {
57 TestResult::startTest (test);
58 std::cout << " Test: " << test->name();
59 }
60
61
62
63
64 void TextTestResult::printErrors (std::ostream& stream)
65 {
66 if (testErrors () != 0) {
67
68 if (testErrors () == 1)
69 stream << "There was " << testErrors () << " error: " << std::endl;
70 else
71 stream << "There were " << testErrors () << " errors: " << std::endl;
72
73 int i = 1;
74
75 for (std::vector<TestFailure *>::iterator it = errors ().begin (); it != errors ().end (); ++it) {
76 TestFailure *failure = *it;
77 CppUnitException *e = failure->thrownException ();
78
79 stream << i
80 << ") "
81 << (*failure).failedTest()->name() << " "
82 << "line: " << (e ? estring (e->lineNumber ()) : std::string("")) << " "
83 << (e ? e->fileName () : std::string("")) << " "
84 << "\"" << failure->thrownException ()->what () << "\""
85 << std::endl;
86 i++;
87 }
88 }
89
90 }
91
92 void TextTestResult::printFailures (std::ostream& stream)
93 {
94 if (testFailures () != 0) {
95 if (testFailures () == 1)
96 stream << "There was " << testFailures () << " failure: " << std::endl;
97 else
98 stream << "There were " << testFailures () << " failures: " << std::endl;
99
100 int i = 1;
101
102 for (std::vector<TestFailure *>::iterator it = failures ().begin (); it != failures ().end (); ++it) {
103 TestFailure *failure = *it;
104 CppUnitException *e = failure->thrownException ();
105
106 stream << i
107 << ") "
108 << (*failure).failedTest()->name() << " "
109 << "line: " << (e ? estring (e->lineNumber ()) : std::string("")) << " "
110 << (e ? e->fileName () : std::string("")) << " "
111 << "\"" << failure->thrownException ()->what () << "\""
112 << std::endl;
113 i++;
114 }
115 }
116
117 }
118
119
120 void TextTestResult::print (std::ostream& stream)
121 {
122 printHeader (stream);
123 printErrors (stream);
124 printFailures (stream);
125
126 }
127
128
129 void TextTestResult::printHeader (std::ostream& stream)
130 {
131 if (wasSuccessful ())
132 std::cout << std::endl << "OK (" << runTests () << " tests)" << std::endl;
133 else
134 std::cout << std::endl
135 << "!!!FAILURES!!!" << std::endl
136 << "Test Results:" << std::endl
137 << "Run: "
138 << runTests ()
139 << " Failures: "
140 << testFailures ()
141 << " Errors: "
142 << testErrors ()
143 << std::endl;
144
145 }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26