Skip to content

Commit

Permalink
Merge Fix JSON Config MSCV Test
Browse files Browse the repository at this point in the history
This merge fixes the json config test for MSCV.

To avoid setting the lib path in msvc, gko makes all test works in the library path (dll location).
I changed the working directory to access testing file in #1607. However, it can not find the dll path now.
follow the `matrices/config.hpp.in` to pass the file path

Related PR: #1610
  • Loading branch information
MarcelKoch authored May 16, 2024
2 parents 368fada + 48f20a8 commit 3e4f2a9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
2 changes: 2 additions & 0 deletions dev_tools/scripts/format_header.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ convert_header () {
fi
elif [ "${header_file}" = "matrices/config.hpp" ]; then
echo "#include \"${header_file}\""
elif [ "${header_file}" = "extensions/test/config/file_location.hpp" ]; then
echo "#include \"${header_file}\""
elif [[ "${header_file}" =~ ${jacobi_regex} ]]; then
echo "#include \"${header_file}\""
else
Expand Down
9 changes: 5 additions & 4 deletions extensions/test/config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ginkgo_create_test(json_config ADDITIONAL_LIBRARIES nlohmann_json::nlohmann_json)
# set the working directory to the current binary folder for file test
file(RELATIVE_PATH REL_BINARY_DIR ${PROJECT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties("${REL_BINARY_DIR}/json_config" PROPERTIES WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
configure_file(test.json test.json COPYONLY)

# prepare the testing file and generate location
configure_file("${Ginkgo_SOURCE_DIR}/extensions/test/config/file_location.hpp.in"
"${Ginkgo_BINARY_DIR}/extensions/test/config/file_location.hpp" @ONLY)
configure_file(test.json "${Ginkgo_BINARY_DIR}/extensions/test/config/test.json")
23 changes: 23 additions & 0 deletions extensions/test/config/file_location.hpp.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2017 - 2024 The Ginkgo authors
//
// SPDX-License-Identifier: BSD-3-Clause

#ifndef GKO_EXTENSIONS_TEST_CONFIG_FILE_LOCATION_HPP_
#define GKO_EXTENSIONS_TEST_CONFIG_FILE_LOCATION_HPP_


namespace gko {
namespace ext {
namespace config {


const char* location_test_json =
"@Ginkgo_BINARY_DIR@/extensions/test/config/test.json";


} // namespace config
} // namespace ext
} // namespace gko


#endif // GKO_EXTENSIONS_TEST_CONFIG_FILE_LOCATION_HPP_
4 changes: 3 additions & 1 deletion extensions/test/config/json_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@


#include "core/test/utils.hpp"
#include "extensions/test/config/file_location.hpp"


TEST(JsonConfig, ThrowIfInvalid)
Expand Down Expand Up @@ -77,7 +78,8 @@ TEST(JsonConfig, ReadInput)

TEST(JsonConfig, ReadInputFromFile)
{
auto ptree = gko::ext::config::parse_json_file("test.json");
auto ptree =
gko::ext::config::parse_json_file(gko::ext::config::location_test_json);

auto& child_array = ptree.get("array").get_array();
auto& child_map = ptree.get("map").get_map();
Expand Down

0 comments on commit 3e4f2a9

Please sign in to comment.