Fixed up testing etc
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@ build
|
||||
stats
|
||||
*.swp
|
||||
*.png
|
||||
*krakout*
|
||||
|
||||
@@ -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>
|
||||
|
||||
10
main.cpp
10
main.cpp
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user