12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- #include "TestLogger.h"
- TestLogger::TestLogger() {
- }
- TestLogger::~TestLogger() {
- }
- void TestLogger::print(const std::string* message, const std::exception* ex,
- const std::string* function, const std::string* scriptname, const Script* sc, int line) {
- (void) function;
- (void) scriptname;
- (void) sc;
- (void) line;
- if(ex == nullptr) {
- if(message != nullptr) {
- int start = 0;
- while(true) {
- int newLine = message->find('\n', start);
- if(newLine == -1) {
- output.push_back(message->substr(start, message->size() - start));
- break;
- }
- output.push_back(message->substr(start, newLine - start));
- start = newLine + 1;
- }
- }
- } else {
- output.push_back(ex->what());
- }
- }
- void TestLogger::reset() {
- output.clear();
- }
- bool TestLogger::check(const std::string& name, std::ifstream& check) {
- std::vector<std::string> file;
- while(!check.eof()) {
- std::string line;
- std::getline(check, line);
- if(!check.eof()) {
- file.push_back(line);
- }
- }
- if(file.size() != output.size()) {
- std::cout << file.size() << " " << output.size() << std::endl;
- printNoMatch(name, file, 0);
- return false;
- }
- for(size_t i = 0; i < file.size(); i++) {
- if(file[i] != output[i]) {
- printNoMatch(name, file, i + 1);
- return false;
- }
- }
- return true;
- }
- void TestLogger::printNoMatch(const std::string& name, std::vector<std::string>& file, unsigned int line) {
- std::cout << "error checking " << name << ", error starting at " << line << "\n";
- std::cout << "Expected ---------------------------------------------\n";
- for(unsigned int i = 0; i < file.size(); i++) {
- std::cout << file[i] << "\n";
- }
- std::cout << "Actual -----------------------------------------------\n";
- for(unsigned int i = 0; i < output.size(); i++) {
- std::cout << output[i] << "\n";
- }
- std::cout << "------------------------------------------------------\n";
- }
|