From 65aa8a669dfa1d7aae4aed457cbf8834f33ad419 Mon Sep 17 00:00:00 2001 From: pantor Date: Mon, 31 Mar 2025 23:22:36 +0200 Subject: [PATCH] move tests to std::filesystem::path --- test/benchmark.cpp | 10 +++++----- test/test-common.hpp | 2 +- test/test-files.cpp | 10 +++++----- test/test.cpp | 4 +++- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/test/benchmark.cpp b/test/benchmark.cpp index a08c435..3e3a7c1 100644 --- a/test/benchmark.cpp +++ b/test/benchmark.cpp @@ -5,12 +5,12 @@ inja::Environment env; -const std::string test_file_directory {"../test/data/benchmark/"}; +const std::filesystem::path test_file_directory {"../test/data/benchmark/"}; -const auto small_data = env.load_json(test_file_directory + "small_data.json"); -const auto large_data = env.load_json(test_file_directory + "large_data.json"); -const std::string medium_template = env.load_file(test_file_directory + "medium_template.txt"); -const std::string large_template = env.load_file(test_file_directory + "large_template.txt"); +const auto small_data = env.load_json(test_file_directory / "small_data.json"); +const auto large_data = env.load_json(test_file_directory / "large_data.json"); +const std::string medium_template = env.load_file(test_file_directory / "medium_template.txt"); +const std::string large_template = env.load_file(test_file_directory / "large_template.txt"); BENCHMARK(SmallDataMediumTemplate, render, 5, 30) { env.render(medium_template, small_data); diff --git a/test/test-common.hpp b/test/test-common.hpp index 512012d..c702558 100644 --- a/test/test-common.hpp +++ b/test/test-common.hpp @@ -4,6 +4,6 @@ #include #include -extern const std::string test_file_directory; +extern const std::filesystem::path test_file_directory; #endif // INCLUDE_TEST_COMMON_HPP_ diff --git a/test/test-files.cpp b/test/test-files.cpp index 3ae499d..8ad3fff 100644 --- a/test/test-files.cpp +++ b/test/test-files.cpp @@ -10,19 +10,19 @@ TEST_CASE("loading") { data["name"] = "Jeff"; SUBCASE("Files should be loaded") { - CHECK(env.load_file(test_file_directory + "simple.txt") == "Hello {{ name }}."); + CHECK(env.load_file(test_file_directory / "simple.txt") == "Hello {{ name }}."); } SUBCASE("Files should be rendered") { - CHECK(env.render_file(test_file_directory + "simple.txt", data) == "Hello Jeff."); + CHECK(env.render_file(test_file_directory / "simple.txt", data) == "Hello Jeff."); } SUBCASE("File includes should be rendered") { - CHECK(env.render_file(test_file_directory + "include.txt", data) == "Answer: Hello Jeff."); + CHECK(env.render_file(test_file_directory / "include.txt", data) == "Answer: Hello Jeff."); } SUBCASE("File error should throw") { - std::string path(test_file_directory + "does-not-exist"); + std::string path(test_file_directory / "does-not-exist"); std::string file_error_message = "[inja.exception.file_error] failed accessing file at '" + path + "'"; CHECK_THROWS_WITH(env.load_file(path), file_error_message.c_str()); @@ -98,7 +98,7 @@ TEST_CASE("include-in-memory-and-file-template") { inja::json data; data["name"] = "Jeff"; - std::string error_message = "[inja.exception.file_error] failed accessing file at '" + test_file_directory + "body'"; + std::string error_message = "[inja.exception.file_error] failed accessing file at '" + test_file_directory.string() + "/body'"; CHECK_THROWS_WITH(env.render_file("include-both.txt", data), error_message.c_str()); const auto parsed_body_template = env.parse("Bye {{ name }}."); diff --git a/test/test.cpp b/test/test.cpp index 3136b2c..738c1ba 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -4,6 +4,8 @@ #define JSON_USE_IMPLICIT_CONVERSIONS 0 #define JSON_NO_IO 1 +#include + #include "test-files.cpp" #include "test-functions.cpp" #include "test-renderer.cpp" @@ -12,4 +14,4 @@ #define xstr(s) str(s) #define str(s) #s -const std::string test_file_directory { xstr(__TEST_DIR__)"/data/" }; +const std::filesystem::path test_file_directory { std::filesystem::path(xstr(__TEST_DIR__)) / "data" };