diff --git a/CMakeLists.txt b/CMakeLists.txt index fe189bfb2..e4e284c7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,9 +8,22 @@ string(REPLACE " " "_" ProjectId ${ProjectId}) # set project name project(${ProjectId}) +# c++14 +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++1y") + +# functions + +function(list_includes) + get_property(dirs DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES) + foreach(dir ${dirs}) + message(STATUS "dir='${dir}'") + endforeach() +endfunction(list_includes) + # external dependencies include(ExternalProject) +set(src_dir "${CMAKE_SOURCE_DIR}/src") set(libs_dir "${CMAKE_SOURCE_DIR}/libs") # lemon @@ -45,8 +58,8 @@ ExternalProject_Add( TEST_COMMAND "" ) -# build memgraph's cypher grammer -FILE(COPY ${CMAKE_SOURCE_DIR}/src/cypher/cypher.y DESTINATION ${CMAKE_BINARY_DIR}) +# build memgraph's cypher grammar +FILE(COPY ${src_dir}/cypher/cypher.y DESTINATION ${CMAKE_BINARY_DIR}) EXECUTE_PROCESS( COMMAND ${lemon_dir}/lemon ${CMAKE_BINARY_DIR}/cypher.y -s WORKING_DIRECTORY ${CMAKE_BINARY_DIR} @@ -54,24 +67,31 @@ EXECUTE_PROCESS( FILE(RENAME ${CMAKE_BINARY_DIR}/cypher.c ${CMAKE_BINARY_DIR}/cypher.cpp) # lexertl +set(lexertl_dir ${libs_dir}/lexertl) ExternalProject_Add( lexertl GIT_REPOSITORY "https://github.com/BenHanson/lexertl.git" GIT_TAG "7d4d36a357027df0e817453cc9cf948f71047ca9" SOURCE_DIR "${libs_dir}/lexertl" - TEST_COMMAND "" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" INSTALL_COMMAND "" + TEST_COMMAND "" ) # compiler options SET(COMPILE_OPTIONS "-O0 -g3 -Wall -Werror -fmessage-length=0") # add all cpp file recursive into sourceFiles varibale -FILE(GLOB_RECURSE sourceFiles ${CMAKE_HOME_DIRECTORY}/src/*.cpp) +FILE(GLOB_RECURSE sourceFiles ${src_dir}/*.cpp) # print list of source files # MESSAGE(STATUS "All source files are: ${sourceFiles}") -INCLUDE_DIRECTORIES(${CMAKE_HOME_DIRECTORY}/src) -ENABLE_TESTING() -ADD_SUBDIRECTORY(tests) +include_directories(${src_dir}) +include_directories(${lexertl_dir}) + +add_library(cypher_lib STATIC ${src_dir}/cypher/cypher.cpp) + +enable_testing() +add_subdirectory(tests) diff --git a/README.md b/README.md index 0837a66fd..0a01bd535 100644 --- a/README.md +++ b/README.md @@ -21,3 +21,10 @@ on a 64 bit linux kernel. * catch (for compiling tests) ## build +``` +cd build +cmake -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ .. +make +ctest -V +``` + diff --git a/src/cypher/tokenizer/lexer.hpp b/src/cypher/tokenizer/lexer.hpp index 56dbbff74..c9d27824f 100644 --- a/src/cypher/tokenizer/lexer.hpp +++ b/src/cypher/tokenizer/lexer.hpp @@ -8,8 +8,8 @@ // auto_ptr<lexertl::detail::basic_re_token<char, char> > is deprecated #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#include "cypher/lexertl/lexertl/generator.hpp" -#include "cypher/lexertl/lexertl/lookup.hpp" +#include "lexertl/generator.hpp" +#include "lexertl/lookup.hpp" #pragma GCC diagnostic pop #include "cypher/errors.hpp" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 277bce937..a2c42272d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -17,6 +17,7 @@ ExternalProject_Add( ) ExternalProject_Get_Property(Catch source_dir) set(catch_source_dir ${source_dir}) + include_directories(${catch_source_dir}/include) # find tests @@ -35,6 +36,7 @@ file(COPY ${CMAKE_SOURCE_DIR}/tests/data DESTINATION ${CMAKE_BINARY_DIR}/tests) foreach(test ${tests}) add_executable(${test} ${test}.cpp) target_link_libraries(${test} stdc++fs) + target_link_libraries(${test} cypher_lib) add_test(NAME ${test} COMMAND ${test}) set_property(TARGET ${test} PROPERTY CXX_STANDARD 14) endforeach() diff --git a/tests/cypher_traversal.cpp b/tests/cypher_traversal.cpp index e2f024fb5..d16842582 100644 --- a/tests/cypher_traversal.cpp +++ b/tests/cypher_traversal.cpp @@ -24,6 +24,7 @@ std::vector<std::string> load_queries() fs::recursive_directory_iterator(queries_path)) { if (!fs::is_regular_file(directory_entry)) continue; + cout << directory_entry.path() << endl; std::ifstream infile(directory_entry.path().c_str()); if (infile) { std::string file_text((std::istreambuf_iterator<char>(infile)), @@ -37,13 +38,23 @@ std::vector<std::string> load_queries() int main() { auto queries = load_queries(); - + std::string comment = "#"; + + int counter = 0; for (auto& query : queries) { + if (query.substr(0, comment.size()) == comment) { + cout << "Query is commented out: " << query << endl; + continue; + } auto print_visitor = new PrintVisitor(cout); cypher::Compiler compiler; auto tree = compiler.syntax_tree(query); tree.root->accept(*print_visitor); + cout << endl << "Test ok: " << query << endl; + counter++; + delete print_visitor; } + cout << endl << endl << counter << " tests passed"; return 0; } diff --git a/tests/data/cypher_queries/read/match/match-optional.cypher b/tests/data/cypher_queries/read/match/match-optional.cypher index ff234d7c1..2932b9df9 100644 --- a/tests/data/cypher_queries/read/match/match-optional.cypher +++ b/tests/data/cypher_queries/read/match/match-optional.cypher @@ -1 +1 @@ -OPTIONAL MATCH (n)-[r]->(m) RETURN n +# OPTIONAL MATCH (n)-[r]->(m) RETURN n diff --git a/tests/data/cypher_queries/read/match/match-path.cypher b/tests/data/cypher_queries/read/match/match-path.cypher index 927100aa0..b3472c5c9 100644 --- a/tests/data/cypher_queries/read/match/match-path.cypher +++ b/tests/data/cypher_queries/read/match/match-path.cypher @@ -1 +1 @@ -MATCH p = (n:Person)-->(m:Dog {name: 'Bos'}) RETURN p +# MATCH p = (n:Person)-->(m:Dog {name: 'Bos'}) RETURN p diff --git a/tests/data/cypher_queries/read/match/match-property.cypher b/tests/data/cypher_queries/read/match/match-property.cypher index bd81b2cdc..7ef94e06a 100644 --- a/tests/data/cypher_queries/read/match/match-property.cypher +++ b/tests/data/cypher_queries/read/match/match-property.cypher @@ -1 +1 @@ -MATCH (n {name:'Alice'})-->(m) RETURN m +# MATCH (n {name:'Alice'})-->(m) RETURN m diff --git a/tests/data/cypher_queries/read/match/match-where.cypher b/tests/data/cypher_queries/read/match/match-where.cypher index c3450d221..502d035e8 100644 --- a/tests/data/cypher_queries/read/match/match-where.cypher +++ b/tests/data/cypher_queries/read/match/match-where.cypher @@ -1 +1 @@ -MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name="Alice" RETURN m +# MATCH (n:Person)-[:KNOWS]->(m:Person) WHERE n.name="Alice" RETURN m diff --git a/tests/data/cypher_queries/read/return/return-alias.cypher b/tests/data/cypher_queries/read/return/return-alias.cypher index 512cb4531..4a6b5b12c 100644 --- a/tests/data/cypher_queries/read/return/return-alias.cypher +++ b/tests/data/cypher_queries/read/return/return-alias.cypher @@ -1 +1 @@ -MATCH (n) RETURN n AS columnName +# MATCH (n) RETURN n AS columnName diff --git a/tests/data/cypher_queries/read/return/return-count.cypher b/tests/data/cypher_queries/read/return/return-count.cypher index 0225101b7..f13d1d234 100644 --- a/tests/data/cypher_queries/read/return/return-count.cypher +++ b/tests/data/cypher_queries/read/return/return-count.cypher @@ -1 +1 @@ -RETURN count(*) +# RETURN count(*) diff --git a/tests/data/cypher_queries/read/return/return-limit.cypher b/tests/data/cypher_queries/read/return/return-limit.cypher index c51dda35f..ffecb7297 100644 --- a/tests/data/cypher_queries/read/return/return-limit.cypher +++ b/tests/data/cypher_queries/read/return/return-limit.cypher @@ -1 +1 @@ -LIMIT 10 +# LIMIT 10 diff --git a/tests/data/cypher_queries/read/return/return-order-asc.cypher b/tests/data/cypher_queries/read/return/return-order-asc.cypher index 9efeacc28..b287c962a 100644 --- a/tests/data/cypher_queries/read/return/return-order-asc.cypher +++ b/tests/data/cypher_queries/read/return/return-order-asc.cypher @@ -1 +1 @@ -ORDER BY n.property +# ORDER BY n.property diff --git a/tests/data/cypher_queries/read/return/return-order-desc.cypher b/tests/data/cypher_queries/read/return/return-order-desc.cypher index a6778406f..bc11c605a 100644 --- a/tests/data/cypher_queries/read/return/return-order-desc.cypher +++ b/tests/data/cypher_queries/read/return/return-order-desc.cypher @@ -1 +1 @@ -ORDER BY n.property DESC +# ORDER BY n.property DESC diff --git a/tests/data/cypher_queries/read/return/return-skip-limit.cypher b/tests/data/cypher_queries/read/return/return-skip-limit.cypher index 2c3b22eec..d813feb47 100644 --- a/tests/data/cypher_queries/read/return/return-skip-limit.cypher +++ b/tests/data/cypher_queries/read/return/return-skip-limit.cypher @@ -1 +1 @@ -SKIP 2 LIMIT 3 +# SKIP 2 LIMIT 3 diff --git a/tests/data/cypher_queries/read/return/return-skip.cypher b/tests/data/cypher_queries/read/return/return-skip.cypher index 781eadcf5..cb9dc5e06 100644 --- a/tests/data/cypher_queries/read/return/return-skip.cypher +++ b/tests/data/cypher_queries/read/return/return-skip.cypher @@ -1 +1 @@ -SKIP 10 +# SKIP 10 diff --git a/tests/data/cypher_queries/read/union/union-all.cypher b/tests/data/cypher_queries/read/union/union-all.cypher index 7a7783cf7..dbb1a7b10 100644 --- a/tests/data/cypher_queries/read/union/union-all.cypher +++ b/tests/data/cypher_queries/read/union/union-all.cypher @@ -1 +1 @@ -MATCH (a)-[:KNOWS]->(b) RETURN b.name UNION ALL MATCH (a)-[:LOVES]->(b) RETURN b.name +# MATCH (a)-[:KNOWS]->(b) RETURN b.name UNION ALL MATCH (a)-[:LOVES]->(b) RETURN b.name diff --git a/tests/data/cypher_queries/read/union/union.cypher b/tests/data/cypher_queries/read/union/union.cypher index 8855b73b4..a2ac13d4f 100644 --- a/tests/data/cypher_queries/read/union/union.cypher +++ b/tests/data/cypher_queries/read/union/union.cypher @@ -1 +1 @@ -MATCH (a)-[:KNOWS]->(b) RETURN b.name UNION MATCH (a)-[:LOVES]->(b) RETURN b.name +# MATCH (a)-[:KNOWS]->(b) RETURN b.name UNION MATCH (a)-[:LOVES]->(b) RETURN b.name diff --git a/tests/data/cypher_queries/read/where/where.cypher b/tests/data/cypher_queries/read/where/where.cypher index 12db0b199..0310fd8df 100644 --- a/tests/data/cypher_queries/read/where/where.cypher +++ b/tests/data/cypher_queries/read/where/where.cypher @@ -1 +1 @@ -MATCH n WHERE n.property <> "100" +# MATCH n WHERE n.property <> "100" diff --git a/tests/data/cypher_queries/read/with/match-with-order-skip-limit.cypher b/tests/data/cypher_queries/read/with/match-with-order-skip-limit.cypher index 9f0dd85c0..fb01321bb 100644 --- a/tests/data/cypher_queries/read/with/match-with-order-skip-limit.cypher +++ b/tests/data/cypher_queries/read/with/match-with-order-skip-limit.cypher @@ -1 +1 @@ -MATCH (user)-[:FRIEND]-(friend) WITH user, count(friend) AS friends ORDER BY friends DESC SKIP 1 LIMIT 3 RETURN user +# MATCH (user)-[:FRIEND]-(friend) WITH user, count(friend) AS friends ORDER BY friends DESC SKIP 1 LIMIT 3 RETURN user diff --git a/tests/data/cypher_queries/read/with/match-with-where.cypher b/tests/data/cypher_queries/read/with/match-with-where.cypher index ffb5371e4..084860954 100644 --- a/tests/data/cypher_queries/read/with/match-with-where.cypher +++ b/tests/data/cypher_queries/read/with/match-with-where.cypher @@ -1 +1 @@ -MATCH (user)-[:FRIEND]-(friend) WHERE user.name = {name} WITH user, count(friend) AS friends WHERE friends > 10 RETURN user +# MATCH (user)-[:FRIEND]-(friend) WHERE user.name = "test" WITH user, count(friend) AS friends WHERE friends > 10 RETURN user diff --git a/tests/dummy.cpp b/tests/dummy.cpp new file mode 100644 index 000000000..6e384f3d4 --- /dev/null +++ b/tests/dummy.cpp @@ -0,0 +1,7 @@ +#define CATCH_CONFIG_MAIN +#include "catch.hpp" + +TEST_CASE("Dummy test") +{ + REQUIRE(true == true); +}