2014-05-20 22:21:07 -04:00
|
|
|
#include "Tester.h"
|
|
|
|
|
|
|
|
|
|
Tester::Tester(std::string krakenInvocation, std::string krakenGrammerLocation) : krakenInvocation(krakenInvocation), krakenGrammerLocation(krakenGrammerLocation) {
|
|
|
|
|
//initlization list
|
2014-12-30 01:22:09 -05:00
|
|
|
removeCmd = "rm -r";
|
2014-05-20 22:21:07 -04:00
|
|
|
resultsExtention = ".results";
|
|
|
|
|
expectedExtention = ".expected_results";
|
|
|
|
|
krakenExtention = ".krak";
|
|
|
|
|
changePermissions = "chmod 755";
|
|
|
|
|
shell = "sh";
|
2014-12-30 01:22:09 -05:00
|
|
|
cd = "cd";
|
2014-05-20 22:21:07 -04:00
|
|
|
redirect = ">";
|
2014-12-30 01:22:09 -05:00
|
|
|
sep = "/";
|
2014-05-20 22:21:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Tester::~Tester() {
|
|
|
|
|
//Nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Tester::cleanExtras(std::string fileName) {
|
|
|
|
|
ssystem(removeCmd + " " + fileName);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-30 01:22:09 -05:00
|
|
|
bool Tester::run(std::string path) {
|
|
|
|
|
std::string fileName = split(path, *sep.c_str()).back();
|
2014-05-20 22:21:07 -04:00
|
|
|
std::cout << "Testing: " << fileName << " with " << krakenInvocation << " and " << krakenGrammerLocation << std::endl;
|
|
|
|
|
|
2014-12-30 01:22:09 -05:00
|
|
|
cleanExtras(path);
|
2015-03-15 18:41:55 -04:00
|
|
|
ssystem(krakenInvocation + " " + path + krakenExtention + " " + path);
|
2016-01-24 03:14:24 -05:00
|
|
|
// done automatically now
|
|
|
|
|
//ssystem(changePermissions + " " + path + sep + fileName + ".sh");
|
|
|
|
|
//ssystem(cd + " " + path + "; " + "./" + fileName + ".sh");
|
|
|
|
|
//ssystem(changePermissions + " " + path + sep + fileName);
|
2014-12-30 01:22:09 -05:00
|
|
|
ssystem(path + sep + fileName + " " + redirect + " " + path + sep + fileName + resultsExtention);
|
|
|
|
|
|
|
|
|
|
bool result = compareFiles(fileName + expectedExtention, path + sep + fileName + resultsExtention);
|
|
|
|
|
|
2014-05-20 22:21:07 -04:00
|
|
|
//If the test was succesful, we don't need all the extra files
|
|
|
|
|
if (result)
|
2014-12-30 01:22:09 -05:00
|
|
|
cleanExtras(path);
|
2014-05-20 22:21:07 -04:00
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Tester::compareFiles(std::string file1Path, std::string file2Path) {
|
|
|
|
|
std::ifstream file1, file2;
|
|
|
|
|
file1.open(file1Path);
|
|
|
|
|
if (!file1.is_open()) {
|
|
|
|
|
std::cout << file1Path << " could not be opened!" << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
file2.open(file2Path);
|
|
|
|
|
if (!file2.is_open()) {
|
|
|
|
|
std::cout << file2Path << " could not be opened!" << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string file1contents = readFile(file1);
|
|
|
|
|
std::string file2contents = readFile(file2);
|
|
|
|
|
|
|
|
|
|
return file1contents.compare(file2contents) == 0;
|
|
|
|
|
}
|