Skip to content

Commit d9d4b01

Browse files
committed
add loop test + add test to cmake
1 parent 9af8dea commit d9d4b01

File tree

2 files changed

+48
-2
lines changed

2 files changed

+48
-2
lines changed

CMakeLists.txt

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
cmake_minimum_required(VERSION 3.12)
22
project(bourne)
33

4-
if(NOT DEFINED STEINWURF_TOP_NAME)
4+
find_package(Python COMPONENTS Interpreter)
5+
6+
# Use waf to resolve dependencies
7+
if(NOT DEFINED STEINWURF_RESOLVE)
8+
message(STATUS "Resolving dependencies...")
9+
execute_process(
10+
COMMAND ${Python_EXECUTABLE} waf resolve ${STEINWURF_RESOLVE_OPTIONS}
11+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
12+
RESULT_VARIABLE STATUS)
13+
14+
if(STATUS AND NOT STATUS EQUAL 0)
15+
message(FATAL_ERROR "Failed: ${STATUS}")
16+
endif()
17+
18+
set(STEINWURF_RESOLVE "${CMAKE_CURRENT_SOURCE_DIR}/resolve_symlinks")
519
set(STEINWURF_TOP_NAME bourne)
620
endif()
721

@@ -41,4 +55,28 @@ if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
4155
# Build executables
4256
add_executable(example examples/example.cpp)
4357
target_link_libraries(example bourne)
58+
59+
enable_testing()
60+
61+
if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
62+
# For Windows: Prevent overriding the parent project's compiler/linker
63+
# settings
64+
set(gtest_force_shared_crt
65+
ON
66+
CACHE BOOL "" FORCE)
67+
endif()
68+
69+
# Google Test dependency
70+
add_subdirectory("${STEINWURF_RESOLVE}/gtest-source")
71+
72+
# Build test executable
73+
file(GLOB_RECURSE bourne_test_sources ./test/*.cpp)
74+
add_executable(bourne_test ${bourne_test_sources})
75+
target_link_libraries(bourne_test gtest_main)
76+
target_link_libraries(bourne_test steinwurf::bourne)
77+
78+
# Copy test/test.json to build directory
79+
file(COPY test/test.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
80+
81+
add_test(bourne_test bourne_test)
4482
endif()

test/src/test_json.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ TEST(test_json, nested_assignment_cause_memory_leak)
309309
bourne::json object2;
310310
object1["key1"] = bourne::json::object();
311311
object2["key2"] = bourne::json::object();
312-
std::cout << "now" << std::endl;
313312
object1["key1"] = object2["key2"];
314313
}
315314

@@ -341,3 +340,12 @@ TEST(test_json, contains)
341340
object.contains(other)); // Check that the objects are not contained in
342341
// each other even though they are equal
343342
}
343+
344+
TEST(test_json, looped_reference)
345+
{
346+
bourne::json object = {"key", 1};
347+
object["loop"] = object;
348+
object = object["loop"];
349+
350+
EXPECT_EQ(1, object["key"].to_int());
351+
}

0 commit comments

Comments
 (0)