Files
Sun1602/include/Failure.h
T
2022-10-26 12:25:11 +08:00

44 lines
922 B
C++

#ifndef FAILURE_H
#define FAILURE_H
// Failure records the circumstances surrounding a test failure. Using C++
// macros were are able to record the name of the file where the failure
// occurred, the line number, and the text of the condition which provoked
// the failure.
#include <string>
#include <iostream>
class Failure
{
public:
Failure (std::string theCondition, std::string theTestName, std::string theFileName, long theLineNumber)
: condition (theCondition), testName (theTestName), fileName (theFileName), lineNumber (theLineNumber)
{
}
std::string condition;
std::string testName;
std::string fileName;
long lineNumber;
};
inline std::ostream& operator<< (std::ostream& stream, const Failure& failure)
{
stream
<< failure.fileName.c_str ()
<< "(" << failure.lineNumber << "):"
<< "Failure: \"" << failure.condition.c_str () << "\" "
<< std::endl;
return stream;
}
#endif