diff --git a/meson.build b/meson.build index 1d5f480..6446a20 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,9 @@ -project('inja', 'cpp') +project('inja', 'cpp', default_options : ['cpp_std=c++11']) inja_inc = include_directories('src') inja_dep = declare_dependency( include_directories : inja_inc ) + +subdir('test') diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d7e77f5..862ca41 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -42,7 +42,7 @@ if(HUNTER_ENABLED) # Use Hunter to manage dependencies else() # Manage dependencies manually # Prepare "Catch" library for other executables add_library(Catch INTERFACE) - target_include_directories(Catch INTERFACE "thirdparty/catch") + target_include_directories(Catch INTERFACE "thirdparty") # Prepare "JSON" library for other executables add_library(JSON INTERFACE) target_include_directories(JSON INTERFACE "thirdparty") diff --git a/test/meson.build b/test/meson.build new file mode 100644 index 0000000..ee6d295 --- /dev/null +++ b/test/meson.build @@ -0,0 +1,11 @@ +unit_test = executable( + 'inja-test', + 'src/unit.cpp', + 'src/unit-files.cpp', + 'src/unit-renderer.cpp', + 'src/unit-string-helper.cpp', + dependencies: inja_dep, + include_directories: include_directories('thirdparty') +) + +test('Inja unit test', unit_test) diff --git a/test/src/unit-files.cpp b/test/src/unit-files.cpp index 6408690..662b4a4 100644 --- a/test/src/unit-files.cpp +++ b/test/src/unit-files.cpp @@ -1,4 +1,4 @@ -#include "catch.hpp" +#include "catch/catch.hpp" #include "nlohmann/json.hpp" #include "inja.hpp" @@ -12,20 +12,20 @@ TEST_CASE("loading") { data["name"] = "Jeff"; SECTION("Files should be loaded") { - CHECK( env.load_global_file("data/simple.txt") == "Hello {{ name }}." ); + CHECK( env.load_global_file("../test/data/simple.txt") == "Hello {{ name }}." ); } SECTION("Files should be rendered") { - CHECK( env.render_file("data/simple.txt", data) == "Hello Jeff." ); + CHECK( env.render_file("../test/data/simple.txt", data) == "Hello Jeff." ); } SECTION("File includes should be rendered") { - CHECK( env.render_file("data/include.txt", data) == "Answer: Hello Jeff." ); + CHECK( env.render_file("../test/data/include.txt", data) == "Answer: Hello Jeff." ); } } TEST_CASE("complete-files") { - inja::Environment env = inja::Environment("data/"); + inja::Environment env = inja::Environment("../test/data/"); for (std::string test_name : {"simple-file", "nested", "nested-line"}) { SECTION(test_name) { @@ -35,23 +35,13 @@ TEST_CASE("complete-files") { } TEST_CASE("global-path") { - inja::Environment env = inja::Environment("data/"); + inja::Environment env = inja::Environment("../test/data/", "test/"); + inja::Environment env_result = inja::Environment("test/"); json data; data["name"] = "Jeff"; SECTION("Files should be written") { - env.write("simple.txt", data, "result.txt"); - CHECK( env.load_global_file("result.txt") == "Hello Jeff." ); - } -} - -TEST_CASE("input-output-path") { - inja::Environment env = inja::Environment("data/", "data/"); - json data; - data["name"] = "Jeff"; - - SECTION("Files should be written") { - env.write("simple.txt", data, "simple-result.txt"); - CHECK( env.load_global_file("simple-result.txt") == "Hello Jeff." ); + env.write("simple.txt", data, "global-path-result.txt"); + CHECK( env_result.load_global_file("global-path-result.txt") == "Hello Jeff." ); } } diff --git a/test/src/unit-renderer.cpp b/test/src/unit-renderer.cpp index f39fd2c..ffdbb00 100644 --- a/test/src/unit-renderer.cpp +++ b/test/src/unit-renderer.cpp @@ -1,4 +1,4 @@ -#include "catch.hpp" +#include "catch/catch.hpp" #include "nlohmann/json.hpp" #include "inja.hpp" diff --git a/test/src/unit-string-helper.cpp b/test/src/unit-string-helper.cpp index f8b36a3..2eadc45 100644 --- a/test/src/unit-string-helper.cpp +++ b/test/src/unit-string-helper.cpp @@ -1,4 +1,4 @@ -#include "catch.hpp" +#include "catch/catch.hpp" #include "nlohmann/json.hpp" #include "inja.hpp" diff --git a/test/src/unit.cpp b/test/src/unit.cpp index 0c7c351..1c77b13 100644 --- a/test/src/unit.cpp +++ b/test/src/unit.cpp @@ -1,2 +1,2 @@ #define CATCH_CONFIG_MAIN -#include "catch.hpp" +#include "catch/catch.hpp"