Jon Test
C++ Unit Test Tool. Not for production -- sample code only
Loading...
Searching...
No Matches
TestFailure.h
Go to the documentation of this file.
1#ifndef JON_TEST_TEST_FAILURE_H
2#define JON_TEST_TEST_FAILURE_H
3
4#include <exception>
5#include <string>
6#include <sstream>
7
8namespace JonTest
9{
10
16: public std::exception
17{
18public:
20 std::string file;
21
23 int line;
24
26 std::string message;
27
29 std::string firstExpression;
30
32 std::string firstValue;
33
35 std::string secondExpression;
36
38 std::string secondValue;
39
41 std::string operatorString;
42
44 std::string whatString;
45
49 const char* const file,
50 const int line,
51 const std::string& message
52 )
53 :file(file),
54 line(line),
59 {
60 {
61 std::ostringstream out;
62 out << message << "\n\t\tAt " << file << ":" << line;
63 whatString = out.str();
64 }
65 }
66
74 template<typename Type1, typename Type2>
76 const char* const file,
77 const int line,
78 const std::string& message,
79 const std::string& firstExpression,
80 const Type1& firstValue,
81 const std::string& secondExpression,
82 const Type2& secondValue,
83 const std::string& operatorString
84 )
85 :file(file),
86 line(line),
91 {
92 {
93 std::ostringstream out;
94 out << firstValue;
95 this->firstValue = out.str();
96 }
97
98 {
99 std::ostringstream out;
100 out << secondValue;
101 this->secondValue = out.str();
102 }
103
104 {
105 std::ostringstream out;
106 out << message << "\n\t\tAt " << file << ":" << line;
107 if(!this->operatorString.empty()) {
108 out << "\n\t\tExpression: " << firstExpression << " " << operatorString << " " << secondExpression << "\n";
109 out << "\t\tValue: " << firstValue << " " << operatorString << " " << secondValue;
110 }
111 whatString = out.str();
112 }
113 }
114
116 virtual ~TestFailure();
117
121 virtual const char* what() const noexcept;
122};
123
124}
125
126#endif
Exception thrown when a test fails an assert and should fail (unless wrapped in expectedFailure()).
Definition TestFailure.h:17
std::string file
Filename where failure occurred.
Definition TestFailure.h:20
int line
Line number of file where failure occurred.
Definition TestFailure.h:23
std::string whatString
Formatted representation of failure.
Definition TestFailure.h:44
std::string operatorString
String representation of operator that failed the test.
Definition TestFailure.h:41
std::string firstValue
String representation of evaluation of first expression that failed the test.
Definition TestFailure.h:32
virtual ~TestFailure()
Required virutal destructor.
virtual const char * what() const noexcept
Gets formatted message of string.
std::string secondValue
String representation of evaluation of second expression that failed the test.
Definition TestFailure.h:38
std::string message
Message provided where failure occurred.
Definition TestFailure.h:26
TestFailure(const char *const file, const int line, const std::string &message, const std::string &firstExpression, const Type1 &firstValue, const std::string &secondExpression, const Type2 &secondValue, const std::string &operatorString)
Construct Test Failure Exception.
Definition TestFailure.h:75
TestFailure(const char *const file, const int line, const std::string &message)
Construct Test Failure Exception without excpression or operator information.
Definition TestFailure.h:48
std::string secondExpression
String representation of second expression that failed the test.
Definition TestFailure.h:35
std::string firstExpression
String representation of first expression that failed the test.
Definition TestFailure.h:29
Definition Count.h:5