Test infrastructure (ctest)

This commit is contained in:
Marko Budiselic 2016-05-25 00:37:14 +02:00
parent 18838f5318
commit 14e38ff358
22 changed files with 73 additions and 26 deletions

View File

@ -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)

View File

@ -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
```

View File

@ -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"

View File

@ -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()

View File

@ -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;
}

View File

@ -1 +1 @@
OPTIONAL MATCH (n)-[r]->(m) RETURN n
# OPTIONAL MATCH (n)-[r]->(m) RETURN n

View File

@ -1 +1 @@
MATCH p = (n:Person)-->(m:Dog {name: 'Bos'}) RETURN p
# MATCH p = (n:Person)-->(m:Dog {name: 'Bos'}) RETURN p

View File

@ -1 +1 @@
MATCH (n {name:'Alice'})-->(m) RETURN m
# MATCH (n {name:'Alice'})-->(m) RETURN m

View File

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

View File

@ -1 +1 @@
MATCH (n) RETURN n AS columnName
# MATCH (n) RETURN n AS columnName

View File

@ -1 +1 @@
RETURN count(*)
# RETURN count(*)

View File

@ -1 +1 @@
LIMIT 10
# LIMIT 10

View File

@ -1 +1 @@
ORDER BY n.property
# ORDER BY n.property

View File

@ -1 +1 @@
ORDER BY n.property DESC
# ORDER BY n.property DESC

View File

@ -1 +1 @@
SKIP 2 LIMIT 3
# SKIP 2 LIMIT 3

View File

@ -1 +1 @@
SKIP 10
# SKIP 10

View File

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

View File

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

View File

@ -1 +1 @@
MATCH n WHERE n.property <> "100"
# MATCH n WHERE n.property <> "100"

View File

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

View File

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

7
tests/dummy.cpp Normal file
View File

@ -0,0 +1,7 @@
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
TEST_CASE("Dummy test")
{
REQUIRE(true == true);
}