60 lines
1.1 KiB
C
Raw Normal View History

2019-09-23 04:09:58 +07:00
#pragma once
#include <exception>
#include <sstream>
class TestFailException : public std::exception {
public:
2021-04-12 21:51:51 +07:00
TestFailException(std::string message, std::string fileName, long lineNumber, bool onlyWarning = false) {
2019-09-23 04:09:58 +07:00
std::stringstream ss;
ss << message << " at " << fileName << " line " << lineNumber;
this->message = ss.str();
this->fileName = fileName;
this->lineNumber = lineNumber;
2021-04-12 21:51:51 +07:00
this->warning = onlyWarning;
2019-09-23 04:09:58 +07:00
}
virtual ~TestFailException() throw() {
}
std::string message;
std::string fileName;
long lineNumber;
2021-04-12 21:51:51 +07:00
bool warning;
2019-09-23 04:09:58 +07:00
virtual const char * what() const throw() {
return message.c_str();
}
};
class Failure {
public:
Failure (TestFailException &e, std::string testName) {
this->testName = testName;
this->message = e.message;
this->fileName = e.fileName;
this->lineNumber = e.lineNumber;
2021-04-12 21:51:51 +07:00
this->warning = e.warning;
2019-09-23 04:09:58 +07:00
}
Failure (std::string message, std::string testName) {
this->testName = testName;
this->message = message;
this->fileName = "<unknown>";
this->lineNumber = -1;
}
std::string testName;
std::string message;
std::string fileName;
long lineNumber;
2021-04-12 21:51:51 +07:00
bool warning;
2019-09-23 04:09:58 +07:00
};