diff --git a/.travis.yml b/.travis.yml index 79dc657e..7db4866a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ language: cpp matrix: include: - - name: gcc-6 + - name: ubuntu16.04-gcc-6 + os: linux dist: xenial addons: apt: @@ -15,48 +16,63 @@ matrix: - bison - flex env: - - MATRIX_EVAL="CC=gcc-6 && CXX=g++-6" - - - name: gcc-10 - dist: focal + - MATRIX_EVAL="CC=gcc-6 && CXX=g++-6 && BISON=bison && FLEX=flex" + - name: ubuntu22.04-gcc-12 + os: linux + dist: jammy addons: apt: packages: - - g++-10 + - g++-12 - valgrind - bison - flex env: - - MATRIX_EVAL="CC=gcc-10 && CXX=g++-10" + - MATRIX_EVAL="CC=gcc-12 && CXX=g++-12 && BISON=bison && FLEX=flex" - - name: clang-12 - dist: focal + - name: ubuntu22.04-clang-14 + os: linux + dist: jammy addons: apt: packages: - - clang-12 + - clang-14 - valgrind - bison - flex env: - - MATRIX_EVAL="CC=clang-12 && CXX=clang++-12" + - MATRIX_EVAL="CC=clang-14 && CXX=clang++-14 && BISON=bison && FLEX=flex" + + - name: macOS12.04-clang + os: osx + osx_image: xcode13.4 + addons: + homebrew: + packages: + - bison + - flex + env: + - BREW_PREFIX="$(brew --prefix)/opt" + - MATRIX_EVAL="CC=clang && CXX=clang++ && BISON=${BREW_PREFIX}/bison/bin/bison && FLEX=${BREW_PREFIX}/flex/bin/flex" before_install: - eval "${MATRIX_EVAL}" script: # print package versions - - bison --version - - flex --version - - valgrind --version + - ${CC} --version + - ${CXX} --version + - ${BISON} --version + - ${FLEX} --version + - awk -v a=$(uname) 'BEGIN { if (a == "Linux") system("valgrind --version") }' # build with flex/bison files checked into repo - make -j4 - - make test + - BISON=${BISON} FLEX=${FLEX} make test - make test_example # build flex/bison files in CI - - make cleanall - - make -j4 - - make test + - BISON=${BISON} FLEX=${FLEX} make cleanall + - BISON=${BISON} FLEX=${FLEX} make -j4 + - BISON=${BISON} FLEX=${FLEX} make test - make test_example diff --git a/format.sh b/format.sh index c5417847..f645403f 100755 --- a/format.sh +++ b/format.sh @@ -2,7 +2,7 @@ unamestr=$(uname) if [[ "$unamestr" == 'Darwin' ]]; then - clang_format="/usr/local/opt/llvm/bin/clang-format" + clang_format="$(brew --prefix llvm)/bin/clang-format" format_cmd="$clang_format -i -style=file '{}'" elif [[ "$unamestr" == 'Linux' ]]; then format_cmd="clang-format -i -style=file '{}'" diff --git a/src/parser/Makefile b/src/parser/Makefile index dbebc14e..1a9d70d6 100644 --- a/src/parser/Makefile +++ b/src/parser/Makefile @@ -2,16 +2,25 @@ BISON?=bison FLEX?=flex +OS_TYPE=$(shell uname) +ifeq ($(OS_TYPE), Darwin) +BREW_PREFIX=$(shell brew --prefix) +BREW_INSTALLED=$(shell echo $(BREW_PREFIX) | wc -w | xargs) +ifeq ($(BREW_INSTALLED), 0) +$(error On macOS, Homebrew (see https://brew.sh) is required to install recent Bison and Flex versions) +endif +endif + BISON_VERSION=$(shell $(BISON) --version | head -n 1 | grep -o '[0-9]\.[0-9]\+') BISON_VERSION_SUPPORTED=$(shell awk -v a=$(BISON_VERSION) -v b="3.0" 'BEGIN { print (a >= b) ? 1 : 0 }') ifneq ($(BISON_VERSION_SUPPORTED), 1) -$(error Bison version $(BISON_VERSION) not supported. If you are using OS X, `bison` uses the system default instead of the brew version. Run BISON=/usr/local/opt/bison/bin/bison make) +$(error Bison version $(BISON_VERSION) not supported. If you are using macOS, `bison` uses the system default instead of the brew version. Run BISON=$(BREW_PREFIX)/opt/bison/bin/bison make) endif FLEX_VERSION=$(shell $(FLEX) --version | head -n 1 | grep -o '[0-9]\.[0-9]\+') FLEX_VERSION_SUPPORTED=$(shell awk -v a=$(FLEX_VERSION) -v b="2.6" 'BEGIN { print (a >= b) ? 1 : 0 }') ifneq ($(FLEX_VERSION_SUPPORTED), 1) -$(error Flex version $(FLEX_VERSION) not supported. If you are using OS X, `flex` uses the system default instead of the brew version. Run FLEX=/usr/local/opt/flex/bin/flex make) +$(error Flex version $(FLEX_VERSION) not supported. If you are using macOS, `flex` uses the system default instead of the brew version. Run FLEX=$(BREW_PREFIX)/opt/flex/bin/flex make) endif all: bison_parser.cpp flex_lexer.cpp diff --git a/test/test.sh b/test/test.sh index 7fea4846..f240a934 100755 --- a/test/test.sh +++ b/test/test.sh @@ -6,11 +6,13 @@ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./ # Colors RED='\033[1;31m' GREEN='\033[1;32m' +YELLOW='\033[1;33m' NC='\033[0m' BOLD='\033[1;39m' RET=0 SQL_TEST_RET=0 +MEM_LEAK_EXECUTED=$? MEM_LEAK_RET=0 CONFLICT_RET=0 @@ -21,32 +23,39 @@ bin/tests -f "test/queries/queries-good.sql" -f "test/queries/queries-bad.sql" SQL_TEST_RET=$? if [ $SQL_TEST_RET -eq 0 ]; then - printf "${GREEN}SQL parser tests succeeded!${NC}\n" + printf "${GREEN}SQL parser tests succeeded!${NC}\n" else - RET=1 - printf "${RED}SQL parser tests failed!${NC}\n" + 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/tests -f "test/queries/queries-good.sql" -f "test/queries/queries-bad.sql" \ - 3>&1>/dev/null; +# Running memory leak checks (only on Linux). +unamestr=$(uname) +if [[ "$unamestr" == 'Linux' ]]; then + printf "\n${GREEN}Running memory leak checks...${NC}\n" + valgrind --leak-check=full --error-exitcode=200 --log-fd=3 \ + bin/tests -f "test/queries/queries-good.sql" -f "test/queries/queries-bad.sql" \ + 3>&1>/dev/null; -MEM_LEAK_RET=$? -RET=1 + MEM_LEAK_EXECUTED=true + MEM_LEAK_RET=$? + RET=1 -if [ $MEM_LEAK_RET -eq 0 ]; then - printf "${GREEN}Memory leak check succeeded!${NC}\n" - MEM_LEAK_RET=0 - RET=0 -elif [ $MEM_LEAK_RET -eq 200 ]; then - printf "${RED}Memory leak check failed!${NC}\n" -elif [ $MEM_LEAK_RET -eq 127 ]; then - printf "${RED}Memory leak check failed: command 'valgrind' not found!${NC}\n" + if [ $MEM_LEAK_RET -eq 0 ]; then + printf "${GREEN}Memory leak check succeeded!${NC}\n" + MEM_LEAK_RET=0 + RET=0 + elif [ $MEM_LEAK_RET -eq 200 ]; then + printf "${RED}Memory leak check failed!${NC}\n" + elif [ $MEM_LEAK_RET -eq 127 ]; then + printf "${RED}Memory leak check failed: command 'valgrind' not found!${NC}\n" + else + printf "${RED}Memory leak check failed: error code ${MEM_LEAK_RET}!${NC}\n" + fi else - printf "${RED}Memory leak check failed: error code ${MEM_LEAK_RET}!${NC}\n" + printf "\n${YELLOW}Skipping memory leak checks (can only be executed on Linux)!${NC}\n" + MEM_LEAK_EXECUTED=false fi ################################################# @@ -57,10 +66,10 @@ make -C src/parser/ test >>/dev/null CONFLICT_RET=$? if [ $CONFLICT_RET -eq 0 ]; then - printf "${GREEN}Conflict check succeeded!${NC}\n" + printf "${GREEN}Conflict check succeeded!${NC}\n" else - RET=1 - printf "${RED}Conflict check failed!${NC}\n" + RET=1 + printf "${RED}Conflict check failed!${NC}\n" fi # Print a summary of the test results. @@ -68,14 +77,19 @@ 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 +else printf "SQL Tests: ${RED}Failure${BOLD}\n"; fi +if [ "$MEM_LEAK_EXECUTED" = true ]; then + 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 +else printf "Memory Leak Check: ${YELLOW}Skipped${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 +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 +if [ $RET -ne 0 ]; then printf "${RED}Some tests failed!${NC}\n" +elif [ "$MEM_LEAK_EXECUTED" = false ]; then printf "${YELLOW}Some tests were skipped!${NC}\n" +else printf "${GREEN}All tests passed!${NC}\n" +fi printf "${NC}----------------------------------\n" exit $RET