Hook the parser tests into the CMake build system.
This commit is contained in:
parent
9cf26ed2cb
commit
c4191d8af6
|
@ -10,3 +10,4 @@ rules.ninja
|
|||
|
||||
# Build products
|
||||
librealm-object-store.dylib
|
||||
tests/tests
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
[submodule "external/pegtl"]
|
||||
path = external/pegtl
|
||||
url = https://github.com/ColinH/PEGTL
|
||||
[submodule "external/catch"]
|
||||
path = external/catch
|
||||
url = https://github.com/philsquared/Catch
|
||||
|
|
|
@ -8,25 +8,7 @@ include(CompilerFlags)
|
|||
include(RealmCore)
|
||||
download_realm_core(0.95.5)
|
||||
|
||||
include_directories(${REALM_CORE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} impl external/pegtl)
|
||||
include_directories(${REALM_CORE_INCLUDE_DIR} src external/pegtl)
|
||||
|
||||
set(SOURCES
|
||||
index_set.cpp
|
||||
list.cpp
|
||||
object_schema.cpp
|
||||
object_store.cpp
|
||||
results.cpp
|
||||
schema.cpp
|
||||
shared_realm.cpp
|
||||
impl/transact_log_handler.cpp
|
||||
parser/parser.cpp
|
||||
parser/query_builder.cpp)
|
||||
|
||||
if(APPLE)
|
||||
include_directories(impl/apple)
|
||||
list(APPEND SOURCES impl/apple/external_commit_helper.cpp)
|
||||
find_library(CF_LIBRARY CoreFoundation)
|
||||
endif()
|
||||
|
||||
add_library(realm-object-store SHARED ${SOURCES})
|
||||
target_link_libraries(realm-object-store realm ${CF_LIBRARY})
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(tests)
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Subproject commit f294c9847272b1b92c5119a6f711e57113b5f231
|
|
@ -0,0 +1,22 @@
|
|||
include_directories(impl)
|
||||
|
||||
set(SOURCES
|
||||
index_set.cpp
|
||||
list.cpp
|
||||
object_schema.cpp
|
||||
object_store.cpp
|
||||
results.cpp
|
||||
schema.cpp
|
||||
shared_realm.cpp
|
||||
impl/transact_log_handler.cpp
|
||||
parser/parser.cpp
|
||||
parser/query_builder.cpp)
|
||||
|
||||
if(APPLE)
|
||||
include_directories(impl/apple)
|
||||
list(APPEND SOURCES impl/apple/external_commit_helper.cpp)
|
||||
find_library(CF_LIBRARY CoreFoundation)
|
||||
endif()
|
||||
|
||||
add_library(realm-object-store SHARED ${SOURCES})
|
||||
target_link_libraries(realm-object-store realm ${CF_LIBRARY})
|
|
@ -0,0 +1,5 @@
|
|||
include_directories(../external/catch/single_include)
|
||||
add_executable(tests main.cpp parser.cpp)
|
||||
target_link_libraries(tests realm-object-store)
|
||||
|
||||
add_custom_target(run-tests USES_TERMINAL DEPENDS tests COMMAND ./tests)
|
|
@ -0,0 +1,2 @@
|
|||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch.hpp"
|
|
@ -1,10 +1,8 @@
|
|||
|
||||
#include "parser.hpp"
|
||||
#include "catch.hpp"
|
||||
#include "parser/parser.hpp"
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
static std::vector<std::string> valid_queries = {
|
||||
// true/false predicates
|
||||
|
@ -131,36 +129,16 @@ static std::vector<std::string> invalid_queries = {
|
|||
"truepredicate & truepredicate",
|
||||
};
|
||||
|
||||
namespace realm {
|
||||
namespace parser {
|
||||
|
||||
bool test_grammar()
|
||||
{
|
||||
bool success = true;
|
||||
TEST_CASE("valid queries") {
|
||||
for (auto& query : valid_queries) {
|
||||
std::cout << "valid query: " << query << std::endl;
|
||||
try {
|
||||
realm::parser::parse(query);
|
||||
} catch (std::exception &ex) {
|
||||
std::cout << "FAILURE - " << ex.what() << std::endl;
|
||||
success = false;
|
||||
INFO("query: " << query);
|
||||
CHECK_NOTHROW(realm::parser::parse(query));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("invalid queries") {
|
||||
for (auto& query : invalid_queries) {
|
||||
std::cout << "invalid query: " << query << std::endl;
|
||||
try {
|
||||
realm::parser::parse(query);
|
||||
} catch (std::exception &ex) {
|
||||
// std::cout << "message: " << ex.what() << std::endl;
|
||||
continue;
|
||||
}
|
||||
std::cout << "FAILURE - query should throw an exception" << std::endl;
|
||||
success = false;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
INFO("query: " << query);
|
||||
CHECK_THROWS(realm::parser::parse(query));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue