1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- #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";
- }
|