Skip to content
52 changes: 34 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ language: cpp

matrix:
include:
- name: gcc-6
- name: ubuntu16.04-gcc-6
os: linux
dist: xenial
addons:
apt:
Expand All @@ -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
2 changes: 1 addition & 1 deletion format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 '{}'"
Expand Down
13 changes: 11 additions & 2 deletions src/parser/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
70 changes: 42 additions & 28 deletions test/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

#################################################
Expand All @@ -57,25 +66,30 @@ 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.
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