From 5267d070e81a8228a617cf820c9aecba9b6bef67 Mon Sep 17 00:00:00 2001 From: Pedro Date: Sat, 27 Feb 2016 15:48:20 +0100 Subject: [PATCH] return bad exit code when a test fails --- Makefile | 3 +-- test/lib/test.cpp | 12 ++++++++---- test/sql_grammar_test.cpp | 5 ++--- test/test.sh | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 9 deletions(-) create mode 100755 test/test.sh diff --git a/Makefile b/Makefile index cb365de..8bb3149 100644 --- a/Makefile +++ b/Makefile @@ -60,8 +60,7 @@ format: ############ test: $(BIN)/sql_tests $(BIN)/sql_grammar_test - @LD_LIBRARY_PATH=./ $(BIN)/sql_grammar_test -f "test/lib/valid_queries.sql" - @LD_LIBRARY_PATH=./ $(BIN)/sql_tests + bash test/test.sh $(BIN)/sql_tests: library @mkdir -p $(BIN)/ diff --git a/test/lib/test.cpp b/test/lib/test.cpp index c691f97..c2be54e 100644 --- a/test/lib/test.cpp +++ b/test/lib/test.cpp @@ -28,7 +28,7 @@ int AddTest(void (*foo)(void), std::string name) { -void RunTests() { +size_t RunTests() { size_t numFailed = 0; for (size_t i = 0; i < TestsManager::tests().size(); ++i) { 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()); numFailed++; } - } + return numFailed; } int main() { - RunTests(); - return 0; + size_t numFailed = RunTests(); + if (numFailed == 0) { + return 0; + } else { + return -1; + } } \ No newline at end of file diff --git a/test/sql_grammar_test.cpp b/test/sql_grammar_test.cpp index 2ea5dbd..e4ca602 100644 --- a/test/sql_grammar_test.cpp +++ b/test/sql_grammar_test.cpp @@ -86,10 +86,9 @@ int main(int argc, char *argv[]) { if (numFailed == 0) { printf("\033[0;32m{ ok} \033[0mAll %lu grammar tests completed successfully!\n", queries.size()); + return 0; } else { 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; } \ No newline at end of file diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..edf80fd --- /dev/null +++ b/test/test.sh @@ -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