Skip to content

Commit d6beb7a

Browse files
committed
Refactor util.hpp and perf_tests.cpp:
- Introduce type aliases for `nlohmann::json` exceptions in `util.hpp` for improved readability. - Update test cases in `perf_tests.cpp` to use the new aliases for exception handling consistency.
1 parent cc19fde commit d6beb7a

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

modules/core/performance/tests/perf_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@ TEST_NOLINT(GetStringTaskTypeEdgeCases, ThrowsIfFileCannotBeOpened) {
173173
TEST_NOLINT(GetStringTaskTypeEdgeCases, ThrowsIfJsonIsMalformed) {
174174
std::string path = (std::filesystem::temp_directory_path() / "bad_json.json").string();
175175
std::ofstream(path) << "{ this is not valid json ";
176-
EXPECT_THROW_NOLINT(GetStringTaskType(ppc::core::TypeOfTask::kSEQ, path), nlohmann::json::parse_error);
176+
EXPECT_THROW_NOLINT(GetStringTaskType(ppc::core::TypeOfTask::kSEQ, path), NlohmannJsonParseError);
177177
std::filesystem::remove(path);
178178
}
179179

180180
TEST_NOLINT(GetStringTaskTypeEdgeCases, ThrowsIfJsonValueIsNull) {
181181
std::string path = (std::filesystem::temp_directory_path() / "null_value.json").string();
182182
std::ofstream(path) << R"({"tasks": { "seq": null }})";
183183

184-
EXPECT_THROW_NOLINT(GetStringTaskType(ppc::core::TypeOfTask::kSEQ, path), nlohmann::json::type_error);
184+
EXPECT_THROW_NOLINT(GetStringTaskType(ppc::core::TypeOfTask::kSEQ, path), NlohmannJsonTypeError);
185185

186186
std::filesystem::remove(path);
187187
}

modules/core/util/include/util.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
#include <nlohmann/json.hpp> // NOLINT(misc-include-cleaner)
1515

16+
using NlohmannJsonParseError = nlohmann::json::parse_error;
17+
using NlohmannJsonTypeError = nlohmann::json::type_error;
18+
1619
#ifdef _MSC_VER
1720
#pragma warning(pop)
1821
#endif

0 commit comments

Comments
 (0)