return bad exit code when a test fails

This commit is contained in:
Pedro 2016-02-27 15:48:20 +01:00
parent 4632abf92d
commit 5267d070e8
4 changed files with 25 additions and 9 deletions

View File

@ -60,8 +60,7 @@ format:
############ ############
test: $(BIN)/sql_tests $(BIN)/sql_grammar_test test: $(BIN)/sql_tests $(BIN)/sql_grammar_test
@LD_LIBRARY_PATH=./ $(BIN)/sql_grammar_test -f "test/lib/valid_queries.sql" bash test/test.sh
@LD_LIBRARY_PATH=./ $(BIN)/sql_tests
$(BIN)/sql_tests: library $(BIN)/sql_tests: library
@mkdir -p $(BIN)/ @mkdir -p $(BIN)/

View File

@ -28,7 +28,7 @@ int AddTest(void (*foo)(void), std::string name) {
void RunTests() { size_t RunTests() {
size_t numFailed = 0; size_t numFailed = 0;
for (size_t i = 0; i < TestsManager::tests().size(); ++i) { for (size_t i = 0; i < TestsManager::tests().size(); ++i) {
printf("\033[0;32m{ running}\033[0m %s\n", TestsManager::testNames()[i].c_str()); printf("\033[0;32m{ running}\033[0m %s\n", TestsManager::testNames()[i].c_str());
@ -43,13 +43,17 @@ void RunTests() {
printf("\tAssertion failed: %s\n\033[0m", e.what()); printf("\tAssertion failed: %s\n\033[0m", e.what());
numFailed++; numFailed++;
} }
} }
return numFailed;
} }
int main() { int main() {
RunTests(); size_t numFailed = RunTests();
if (numFailed == 0) {
return 0; return 0;
} else {
return -1;
}
} }

View File

@ -86,10 +86,9 @@ int main(int argc, char *argv[]) {
if (numFailed == 0) { if (numFailed == 0) {
printf("\033[0;32m{ ok} \033[0mAll %lu grammar tests completed successfully!\n", queries.size()); printf("\033[0;32m{ ok} \033[0mAll %lu grammar tests completed successfully!\n", queries.size());
return 0;
} else { } else {
fprintf(stderr, "\033[0;31m{ failed} \033[0mSome grammar tests failed! %d out of %lu tests failed!\n", numFailed, queries.size()); fprintf(stderr, "\033[0;31m{ failed} \033[0mSome grammar tests failed! %d out of %lu tests failed!\n", numFailed, queries.size());
return -1;
} }
return 0;
} }

14
test/test.sh Executable file
View File

@ -0,0 +1,14 @@
# has to be executed from the root of the repository
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./
bin/sql_grammar_test -f "test/lib/valid_queries.sql"
RET1=$?
bin/sql_tests
RET2=$?
if [[ $RET1 != 0 ]]; then exit $RET1; fi
if [[ $RET2 != 0 ]]; then exit $RET2; fi
exit 0