Skip to content

Commit

Permalink
add loop test + add test to cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
jpihl committed Jan 23, 2025
1 parent 9af8dea commit d9d4b01
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
40 changes: 39 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
cmake_minimum_required(VERSION 3.12)
project(bourne)

if(NOT DEFINED STEINWURF_TOP_NAME)
find_package(Python COMPONENTS Interpreter)

# Use waf to resolve dependencies
if(NOT DEFINED STEINWURF_RESOLVE)
message(STATUS "Resolving dependencies...")
execute_process(
COMMAND ${Python_EXECUTABLE} waf resolve ${STEINWURF_RESOLVE_OPTIONS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
RESULT_VARIABLE STATUS)

if(STATUS AND NOT STATUS EQUAL 0)
message(FATAL_ERROR "Failed: ${STATUS}")
endif()

set(STEINWURF_RESOLVE "${CMAKE_CURRENT_SOURCE_DIR}/resolve_symlinks")
set(STEINWURF_TOP_NAME bourne)
endif()

Expand Down Expand Up @@ -41,4 +55,28 @@ if(${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME})
# Build executables
add_executable(example examples/example.cpp)
target_link_libraries(example bourne)

enable_testing()

if(CMAKE_C_COMPILER_ID MATCHES "MSVC")
# For Windows: Prevent overriding the parent project's compiler/linker
# settings
set(gtest_force_shared_crt
ON
CACHE BOOL "" FORCE)
endif()

# Google Test dependency
add_subdirectory("${STEINWURF_RESOLVE}/gtest-source")

# Build test executable
file(GLOB_RECURSE bourne_test_sources ./test/*.cpp)
add_executable(bourne_test ${bourne_test_sources})
target_link_libraries(bourne_test gtest_main)
target_link_libraries(bourne_test steinwurf::bourne)

# Copy test/test.json to build directory
file(COPY test/test.json DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

add_test(bourne_test bourne_test)
endif()
10 changes: 9 additions & 1 deletion test/src/test_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,6 @@ TEST(test_json, nested_assignment_cause_memory_leak)
bourne::json object2;
object1["key1"] = bourne::json::object();
object2["key2"] = bourne::json::object();
std::cout << "now" << std::endl;
object1["key1"] = object2["key2"];
}

Expand Down Expand Up @@ -341,3 +340,12 @@ TEST(test_json, contains)
object.contains(other)); // Check that the objects are not contained in
// each other even though they are equal
}

TEST(test_json, looped_reference)
{
bourne::json object = {"key", 1};
object["loop"] = object;
object = object["loop"];

EXPECT_EQ(1, object["key"].to_int());
}

0 comments on commit d9d4b01

Please sign in to comment.