Fixed up testing etc

This commit is contained in:
Nathan Braswell
2015-01-09 14:28:07 -05:00
parent ad0e90f74a
commit 9e9b4371da
54 changed files with 16 additions and 6 deletions

1
.gitignore vendored
View File

@@ -4,3 +4,4 @@ build
stats
*.swp
*.png
*krakout*

View File

@@ -20,6 +20,7 @@ int findPerenEnd(std::string str, int i);
std::vector<std::string> split(const std::string &str, char delim);
std::string join(const std::vector<std::string> &strVec, std::string joinStr);
std::string readFile(std::istream &file);
std::string padWithSpaces(std::string str, int padTo);
template <typename T>

View File

@@ -40,12 +40,18 @@ int main(int argc, char* argv[]) {
std::string testResults, line;
int passed = 0, failed = 0;
Tester test(argv[0], "../krakenGrammer.kgm");
// find the max length so we can pad the string and align the results
unsigned int maxLineLength = 0;
for (int i = 2; i < argc; i++) {
int strLen = std::string(argv[i]).length();
maxLineLength = maxLineLength < strLen ? strLen : maxLineLength;
}
for (int i = 2; i < argc; i++) {
bool result = test.run(argv[i]);
if (result)
line = std::string(argv[i]) + "\t\tpassed!\n", passed++;
line = padWithSpaces(std::string(argv[i]), maxLineLength) + "\t\tpassed!\n", passed++;
else
line = std::string(argv[i]) + "\t\tFAILED!\n", failed++;
line = padWithSpaces(std::string(argv[i]), maxLineLength) + "\t\tFAILED!!!!\n", failed++;
std::cout << line << std::endl;
testResults += line;
}

View File

@@ -61,8 +61,5 @@ bool Tester::compareFiles(std::string file1Path, std::string file2Path) {
std::string file1contents = readFile(file1);
std::string file2contents = readFile(file2);
// std::cout << "file1: " << file1contents << std::endl;
// std::cout << "file2: " << file2contents << std::endl;
// std::cout << "comp: " << file1contents.compare(file2contents) << std::endl;
return file1contents.compare(file2contents) == 0;
}

View File

@@ -80,4 +80,9 @@ std::string readFile(std::istream &file) {
return contents;
}
std::string padWithSpaces(std::string str, int padTo) {
while(str.length() < padTo)
str += " ";
return str;
}

View File

@@ -6,7 +6,7 @@ testDir="."
ext=${2:-"krak"}
fileList=""
for dir in `find ${testDir} -type f -name "*.${ext}"`; do
for dir in `find ${testDir} -type f -name "test_*.${ext}"`; do
filename=$(basename ${dir})
filename="${filename%.*}"
fileList+=\ $testDir\/$filename