Skip to content

Commit

Permalink
fix test working dir and throw if it is not handled
Browse files Browse the repository at this point in the history
Co-authored-by: Tobias Ribizel <[email protected]>
  • Loading branch information
yhmtsai and upsj committed May 8, 2024
1 parent cbcfa66 commit f0ddffe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
5 changes: 4 additions & 1 deletion extensions/test/config/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
ginkgo_create_test(json_config ADDITIONAL_LIBRARIES nlohmann_json::nlohmann_json)
configure_file("test.json" test.json COPYONLY)
# 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)
12 changes: 12 additions & 0 deletions extensions/test/config/json_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
//
// SPDX-License-Identifier: BSD-3-Clause

#include <stdexcept>


#include <gtest/gtest.h>
#include <nlohmann/json.hpp>

Expand All @@ -13,6 +16,15 @@
#include "core/test/utils.hpp"


TEST(JsonConfig, ThrowIfInvalid)
{
const char json[] = R"({"test": null})";
auto d = nlohmann::json::parse(json);

ASSERT_THROW(gko::ext::config::parse_json(d), std::runtime_error);
}


TEST(JsonConfig, ReadMap)
{
const char json[] = R"({"test": "A", "bool": true})";
Expand Down
5 changes: 4 additions & 1 deletion include/ginkgo/extensions/config/json_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


#include <fstream>
#include <stdexcept>
#include <string>


Expand Down Expand Up @@ -57,7 +58,9 @@ inline gko::config::pnode parse_json(const nlohmann::json& input)
return gko::config::pnode{
std::string(data.template get<std::string>())};
}
return gko::config::pnode{};
throw std::runtime_error(
"property_tree can not handle the node with content: " +
data.dump());
};

if (dom.is_array()) {
Expand Down

0 comments on commit f0ddffe

Please sign in to comment.