From 382522db7682c6d0e8b9e6bb1e119634ee63898f Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 26 Nov 2014 17:45:59 +0100 Subject: [PATCH] improved testing --- run_tests.sh | 4 +++- src/sql_grammar_test.cpp | 12 ++++++------ src/sql_tests.cpp | 1 - src/tests/valid-queries.sql | 26 -------------------------- 4 files changed, 9 insertions(+), 34 deletions(-) delete mode 100644 src/tests/valid-queries.sql diff --git a/run_tests.sh b/run_tests.sh index e0f7a43..8df5f8e 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -2,5 +2,7 @@ echo "Compiling..." make clean -C src/ >/dev/null make tests -C src/ >/dev/null +make grammar_test -C src/ >/dev/null echo "Running tests:" -./bin/tests \ No newline at end of file +./bin/grammar_test -f "test/valid_queries.sql" +./bin/tests diff --git a/src/sql_grammar_test.cpp b/src/sql_grammar_test.cpp index 34f5a4e..b34a757 100644 --- a/src/sql_grammar_test.cpp +++ b/src/sql_grammar_test.cpp @@ -72,16 +72,16 @@ int main(int argc, char *argv[]) { end = std::chrono::system_clock::now(); std::chrono::duration elapsed_seconds = end-start; + double us = elapsed_seconds.count() * 1000 * 1000; if (expect_false == stmt_list->isValid) { - fprintf(stderr, "Parsing failed (%.3fms)! %s: \"%s\"\n", elapsed_seconds.count()*1000, stmt_list->parser_msg, sql.c_str()); + printf("\033[0;31m{ failed}\033[0m\n"); + printf("\t\033[0;31m%s\n\033[0m", stmt_list->parser_msg); + printf("\t%s\n", sql.c_str()); num_failed++; } else { - if (expect_false) { - // printf("Success (%.3fms)! %s: \"%s\"\n", elapsed_seconds.count()*1000, stmt_list->parser_msg, sql.c_str()); - } else { - // printf("Success (%.3fms)! \"%s\"\n", elapsed_seconds.count()*1000, sql.c_str()); - } + // TODO: indicate whether expect_false was set + printf("\033[0;32m{ ok} (%.1fus)\033[0m %s\n", us, sql.c_str()); } } diff --git a/src/sql_tests.cpp b/src/sql_tests.cpp index 9075def..8d0a9db 100644 --- a/src/sql_tests.cpp +++ b/src/sql_tests.cpp @@ -35,4 +35,3 @@ TEST(DeleteTest) { ASSERT_EQ(stmt->expr->expr2->fval, 2.0); } - diff --git a/src/tests/valid-queries.sql b/src/tests/valid-queries.sql deleted file mode 100644 index b3d7e35..0000000 --- a/src/tests/valid-queries.sql +++ /dev/null @@ -1,26 +0,0 @@ -# SELECT statement -SELECT * FROM orders; -SELECT a FROM foo WHERE a > 12 OR b > 3 AND NOT c LIMIT 10 -SELECT col1 AS myname, col2, 'test' FROM "table", foo AS t WHERE age > 12 AND zipcode = 12345 GROUP BY col1; -SELECT * from "table" JOIN table2 ON a = b WHERE (b OR NOT a) AND a = 12.5 -(SELECT a FROM foo WHERE a > 12 OR b > 3 AND c NOT LIKE 's%' LIMIT 10); -SELECT * FROM "table" LIMIT 10 OFFSET 10; -SELECT * FROM t1 UNION SELECT * FROM t2 ORDER BY col1; -# SELECT * FROM t1 UNION (SELECT * FROM t2 UNION SELECT * FROM t3) ORDER BY col1; -# JOIN -SELECT t1.a, t1.b, t2.c FROM "table" AS t1 JOIN (SELECT * FROM foo JOIN bar ON foo.id = bar.id) t2 ON t1.a = t2.b WHERE (t1.b OR NOT t1.a) AND t2.c = 12.5 -SELECT * FROM t1 JOIN t2 ON c1 = c2; -# CREATE statement -CREATE TABLE "table" FROM TBL FILE 'students.tbl' -CREATE TABLE IF NOT EXISTS "table" FROM TBL FILE 'students.tbl' -CREATE TABLE students (name TEXT, student_number INTEGER, city TEXT, grade DOUBLE) -# Multiple statements -CREATE TABLE "table" FROM TBL FILE 'students.tbl'; SELECT * FROM "table"; -# INSERT -INSERT INTO test_table VALUES (1, 2, 'test'); -INSERT INTO test_table (id, value, name) VALUES (1, 2, 'test'); -INSERT INTO test_table SELECT * FROM students; -# DELETE -DELETE FROM students WHERE grade > 3.0 -DELETE FROM students -TRUNCATE students \ No newline at end of file