From 3e52bf1a665d628d9d190c8f7a7d3b5c0cfb6140 Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 8 Mar 2017 19:28:25 +0100 Subject: [PATCH] Add test for grammar conflicts. Print summary at the end of tests --- src/parser/Makefile | 6 +++- test/test.sh | 70 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 66 insertions(+), 10 deletions(-) diff --git a/src/parser/Makefile b/src/parser/Makefile index a0102f4..10983c6 100644 --- a/src/parser/Makefile +++ b/src/parser/Makefile @@ -10,4 +10,8 @@ flex_lexer.cpp: flex_lexer.l flex flex_lexer.l clean: - rm -f bison_parser.cpp flex_lexer.cpp bison_parser.h flex_lexer.h *.output \ No newline at end of file + rm -f bison_parser.cpp flex_lexer.cpp bison_parser.h flex_lexer.h *.output + +# Tests if the parser builds correctly and doesn't contain conflicts. +test: + ! bison bison_parser.y -v 2>&1 | grep "conflict" >&2 diff --git a/test/test.sh b/test/test.sh index e7cae2a..73b3262 100755 --- a/test/test.sh +++ b/test/test.sh @@ -1,21 +1,73 @@ #!/bin/bash - # Has to be executed from the root of the repository. # Usually invoked by `make test`. export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./ +# Colors +RED='\033[1;31m' +GREEN='\033[1;32m' +NC='\033[0m' +BOLD='\033[1;39m' + RET=0 +SQL_TEST_RET=0 +MEM_LEAK_RET=0 +CONFLICT_RET=0 +################################################# +# Running SQL parser tests. +printf "\n${GREEN}Running SQL parser tests...${NC}\n" bin/sql_tests -f "test/valid_queries.sql" -RET=$? +SQL_TEST_RET=$? -if [ $RET -eq 0 ]; then - # Running memory leak checks. - echo "" - echo "Running memory leak checks..." - valgrind --leak-check=full --error-exitcode=1 --log-fd=3 \ - ./bin/sql_tests -f "test/valid_queries.sql" 3>&1 >/dev/null 2>/dev/null - RET=$? +if [ $SQL_TEST_RET -eq 0 ]; then + printf "${GREEN}SQL parser tests succeeded!${NC}\n" +else + RET=1 + printf "${RED}SQL parser tests failed!${NC}\n" fi +################################################# +# Running memory leak checks. +printf "\n${GREEN}Running memory leak checks...${NC}\n" +valgrind --leak-check=full --error-exitcode=200 --log-fd=3 \ + ./bin/sql_tests -f "test/valid_queries.sql" 3>&1 >/dev/null 2>/dev/null + +if [ $MEM_LEAK_RET -ne 200 ]; then + printf "${GREEN}Memory leak check succeeded!${NC}\n" +else + MEM_LEAK_RET=1 + RET=1 + printf "${RED}Memory leak check failed!${NC}\n" +fi + +################################################# +# Checking if the grammar is conflict free. +printf "\n${GREEN}Checking for conflicts in the grammer...${NC}\n" +printf "${RED}" +make -C src/parser/ test >>/dev/null +CONFLICT_RET=$? + +if [ $CONFLICT_RET -eq 0 ]; then + printf "${GREEN}Conflict check succeeded!${NC}\n" +else + RET=1 + printf "${RED}Conflict check failed!${NC}\n" +fi + +# Print a summary of the test results. +printf " +---------------------------------- +${BOLD}Summary:\n" +if [ $SQL_TEST_RET -eq 0 ]; then printf "SQL Tests: ${GREEN}Success${BOLD}\n"; +else printf "SQL Tests: ${RED}Failure${BOLD}\n"; fi +if [ $MEM_LEAK_RET -eq 0 ]; then printf "Memory Leak Check: ${GREEN}Success${BOLD}\n"; +else printf "Memory Leak Check: ${RED}Failure${BOLD}\n"; fi +if [ $CONFLICT_RET -eq 0 ]; then printf "Grammar Conflict Check: ${GREEN}Success${BOLD}\n"; +else printf "Grammar Conflict Check: ${RED}Failure${BOLD}\n"; fi + +if [ $RET -eq 0 ]; then printf "${GREEN}All tests passed!${NC}\n"; +else printf "${RED}Some tests failed!${NC}\n"; fi +printf "${NC}----------------------------------\n" + exit $RET