From 8f26c45c0113785b1fdfc827295b688d6112f3c4 Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 23 Dec 2015 16:14:39 +0100 Subject: [PATCH] build tests with library --- Makefile | 24 +++++++++++++++++++++++- test/{tests => lib}/helper.h | 0 test/{tests => lib}/select.cpp | 0 test/{tests => lib}/test.cpp | 0 test/{tests => lib}/test.h | 0 test/{tests => lib}/valid_queries.sql | 0 test/sql_tests.cpp | 4 ++-- 7 files changed, 25 insertions(+), 3 deletions(-) rename test/{tests => lib}/helper.h (100%) rename test/{tests => lib}/select.cpp (100%) rename test/{tests => lib}/test.cpp (100%) rename test/{tests => lib}/test.h (100%) rename test/{tests => lib}/valid_queries.sql (100%) diff --git a/Makefile b/Makefile index 3cee86a..2b8f7be 100644 --- a/Makefile +++ b/Makefile @@ -18,6 +18,7 @@ PARSERFILES = $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp LIBCPP = $(shell find $(SRC)/ -name '*.cpp' -not -path "$(SRCPARSER)/*") $(SRCPARSER)/bison_parser.cpp $(SRCPARSER)/flex_lexer.cpp LIBOBJ = $(LIBCPP:%.cpp=%.o) LIBHEADERS = $(shell find $(SRCSQL)/ -name '*.h') $(SRC)/SQLParser.h +TESTCPP = $(shell find test/lib/ -name '*.cpp') # compile & link flages CC = g++ @@ -25,11 +26,13 @@ CFLAGS = -std=c++11 -Wall -fPIC LIBFLAGS = -shared TARGET = libsqlparser.so +CTESTFLAGS = -Wall -Isrc/ -Itest/ -L./ -std=c++11 all: library +library: $(TARGET) -library: $(LIBOBJ) +$(TARGET): $(LIBOBJ) $(CC) $(LIBFLAGS) -o $(TARGET) $(LIBOBJ) @@ -43,9 +46,28 @@ parser: make -C $(SRCPARSER)/ clean: + rm -f $(TARGET) + rm -rf $(BIN) find $(SRC) -type f -name '*.o' -delete cleanparser: make -C $(SRCPARSER)/ clean + +############ +### Test ### +############ + +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 + +$(BIN)/sql_tests: library + @mkdir -p $(BIN)/ + $(CC) $(CTESTFLAGS) $(TESTCPP) test/sql_tests.cpp -o $(BIN)/sql_tests -lsqlparser + +$(BIN)/sql_grammar_test: library + @mkdir -p $(BIN)/ + $(CC) $(CTESTFLAGS) test/sql_grammar_test.cpp -o $(BIN)/sql_grammar_test -lsqlparser + FORCE: diff --git a/test/tests/helper.h b/test/lib/helper.h similarity index 100% rename from test/tests/helper.h rename to test/lib/helper.h diff --git a/test/tests/select.cpp b/test/lib/select.cpp similarity index 100% rename from test/tests/select.cpp rename to test/lib/select.cpp diff --git a/test/tests/test.cpp b/test/lib/test.cpp similarity index 100% rename from test/tests/test.cpp rename to test/lib/test.cpp diff --git a/test/tests/test.h b/test/lib/test.h similarity index 100% rename from test/tests/test.h rename to test/lib/test.h diff --git a/test/tests/valid_queries.sql b/test/lib/valid_queries.sql similarity index 100% rename from test/tests/valid_queries.sql rename to test/lib/valid_queries.sql diff --git a/test/sql_tests.cpp b/test/sql_tests.cpp index bb29555..dabfd2f 100644 --- a/test/sql_tests.cpp +++ b/test/sql_tests.cpp @@ -2,8 +2,8 @@ * sql_tests.cpp */ -#include "tests/test.h" -#include "tests/helper.h" +#include "lib/test.h" +#include "lib/helper.h" #include "SQLParser.h" #include "sqlhelper.h"