From 043e34b70c8b95b0236394740d5580fcb5d0043d Mon Sep 17 00:00:00 2001 From: Pedro Date: Wed, 8 Feb 2017 04:55:45 +0100 Subject: [PATCH] implement test for failing grammar in sql_grammar_test.cpp --- test/lib/valid_queries.sql | 9 ++++++++- test/sql_grammar_test.cpp | 10 ++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/test/lib/valid_queries.sql b/test/lib/valid_queries.sql index 2d4468f..ab5a6c5 100644 --- a/test/lib/valid_queries.sql +++ b/test/lib/valid_queries.sql @@ -36,4 +36,11 @@ PREPARE prep_inst: INSERT INTO test VALUES (?, ?, ?); PREPARE prep2 { INSERT INTO test VALUES (?, 0, 0); INSERT INTO test VALUES (0, ?, 0); INSERT INTO test VALUES (0, 0, ?); }; EXECUTE prep_inst(1, 2, 3); EXECUTE prep; -DEALLOCATE PREPARE prep; \ No newline at end of file +DEALLOCATE PREPARE prep; +# Error expeced +! +!1 +!gibberish; +!SELECT abc; +!CREATE TABLE "table" FROM TBL FILE 'students.tbl';SELECT 1 +!CREATE TABLE "table" FROM TBL FILE 'students.tbl';1 \ No newline at end of file diff --git a/test/sql_grammar_test.cpp b/test/sql_grammar_test.cpp index f273865..ad707eb 100644 --- a/test/sql_grammar_test.cpp +++ b/test/sql_grammar_test.cpp @@ -36,14 +36,14 @@ int main(int argc, char *argv[]) { return -1; } - bool expectFalse = false; + bool globalExpectFalse = false; bool useFile = false; std::string filePath = ""; // Parse command line arguments int i = 1; for (; i < argc; ++i) { - if (STREQ(argv[i], "--false")) expectFalse = true; + if (STREQ(argv[i], "--false")) globalExpectFalse = true; else if (STREQ(argv[i], "-f")) { useFile = true; filePath = argv[++i]; @@ -65,6 +65,12 @@ int main(int argc, char *argv[]) { // Execute queries int numFailed = 0; for (std::string sql : queries) { + bool expectFalse = globalExpectFalse; + if (sql.at(0) == '!') { + expectFalse = !expectFalse; + sql = sql.substr(1); + } + // Measuring the parsing time std::chrono::time_point start, end; start = std::chrono::system_clock::now();