mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-17 09:06:26 +00:00
Hook the parser tests into the CMake build system.
This commit is contained in:
parent
9cf26ed2cb
commit
c4191d8af6
1
.gitignore
vendored
1
.gitignore
vendored
@ -10,3 +10,4 @@ rules.ninja
|
|||||||
|
|
||||||
# Build products
|
# Build products
|
||||||
librealm-object-store.dylib
|
librealm-object-store.dylib
|
||||||
|
tests/tests
|
||||||
|
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -1,3 +1,6 @@
|
|||||||
[submodule "external/pegtl"]
|
[submodule "external/pegtl"]
|
||||||
path = external/pegtl
|
path = external/pegtl
|
||||||
url = https://github.com/ColinH/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)
|
include(RealmCore)
|
||||||
download_realm_core(0.95.5)
|
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
|
add_subdirectory(src)
|
||||||
index_set.cpp
|
add_subdirectory(tests)
|
||||||
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})
|
|
||||||
|
1
external/catch
vendored
Submodule
1
external/catch
vendored
Submodule
@ -0,0 +1 @@
|
|||||||
|
Subproject commit f294c9847272b1b92c5119a6f711e57113b5f231
|
22
src/CMakeLists.txt
Normal file
22
src/CMakeLists.txt
Normal file
@ -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})
|
5
tests/CMakeLists.txt
Normal file
5
tests/CMakeLists.txt
Normal file
@ -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)
|
2
tests/main.cpp
Normal file
2
tests/main.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define CATCH_CONFIG_MAIN
|
||||||
|
#include "catch.hpp"
|
@ -1,10 +1,8 @@
|
|||||||
|
#include "catch.hpp"
|
||||||
#include "parser.hpp"
|
#include "parser/parser.hpp"
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <exception>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
static std::vector<std::string> valid_queries = {
|
static std::vector<std::string> valid_queries = {
|
||||||
// true/false predicates
|
// true/false predicates
|
||||||
@ -131,36 +129,16 @@ static std::vector<std::string> invalid_queries = {
|
|||||||
"truepredicate & truepredicate",
|
"truepredicate & truepredicate",
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace realm {
|
TEST_CASE("valid queries") {
|
||||||
namespace parser {
|
for (auto& query : valid_queries) {
|
||||||
|
INFO("query: " << query);
|
||||||
bool test_grammar()
|
CHECK_NOTHROW(realm::parser::parse(query));
|
||||||
{
|
|
||||||
bool success = true;
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto &query : invalid_queries) {
|
TEST_CASE("invalid queries") {
|
||||||
std::cout << "invalid query: " << query << std::endl;
|
for (auto& query : invalid_queries) {
|
||||||
try {
|
INFO("query: " << query);
|
||||||
realm::parser::parse(query);
|
CHECK_THROWS(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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user