Skip to content

Commit

Permalink
Adds a unit test of one of the important YamlHelper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke Pickering committed Oct 30, 2024
1 parent d442469 commit 5ab2064
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 2 deletions.
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ set(MaCh3_VERSION ${PROJECT_VERSION})
#LP - This option name is confusing, but I wont change it now.
option(USE_CPU "Whether to *only* use the CPU (i.e. no GPU)" OFF)
option(MaCh3_PYTHON_ENABLED "Whether to build MaCh3 python bindings" OFF)
option(MaCh3_TESTS_ENABLED "Whether to build MaCh3 unit tests" OFF)

# Try to find CUDA
find_package(CUDAToolkit QUIET)
Expand Down Expand Up @@ -326,3 +327,17 @@ endif()

# KS: Configure the Doxygen input file, this is to ensure whenever we update MaCh3 version Doxyfile will have same version.
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/Templates/Doxyfile.in ${CMAKE_CURRENT_SOURCE_DIR}/Doc/Doxyfile @ONLY)


if(MaCh3_TESTS_ENABLED)
find_package(Catch2)
if(NOT Catch2_FOUND)
CPMAddPackage("gh:catchorg/[email protected]")
LIST(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
endif()

include(CTest)
include(Catch)

add_subdirectory(tests)
endif()
4 changes: 2 additions & 2 deletions manager/YamlHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ inline bool compareYAMLNodes(const YAML::Node& node1, const YAML::Node& node2) {
/// OverrideConfig(config, "General", "MyDouble", 5.3);
/// @endcode
template <typename TValue>
void OverrideConfig(YAML::Node &node, std::string const &key, TValue val) {
void OverrideConfig(YAML::Node node, std::string const &key, TValue val) {
// **********************
node[key] = val;
}
template <typename... Args>
void OverrideConfig(YAML::Node &node, std::string const &key, Args... args) {
void OverrideConfig(YAML::Node node, std::string const &key, Args... args) {
// **********************
OverrideConfig(node[key], args...);
}
4 changes: 4 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(manager_tests manager_tests.cpp)
target_link_libraries(manager_tests PRIVATE Catch2::Catch2WithMain Manager)

catch_discover_tests(manager_tests)
18 changes: 18 additions & 0 deletions tests/manager_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "catch2/catch_test_macros.hpp"

#include "manager/YamlHelper.h"

TEST_CASE("OverrideConfig", "[Yamlhelper]") {
YAML::Node lineup = YAML::Load("{1B: Prince Fielder, 2B: Rickie Weeks, LF: Ryan Braun}");

REQUIRE(lineup.size() == 3);
REQUIRE(lineup["1B"].as<std::string>() == "Prince Fielder");

OverrideConfig(lineup, "1B", "Fielder formerly know as Prince");

REQUIRE(lineup["1B"].as<std::string>() == "Fielder formerly know as Prince");

OverrideConfig(lineup, "1B", 123);

REQUIRE(lineup["1B"].as<unsigned>() == 123u);
}

0 comments on commit 5ab2064

Please sign in to comment.