From 3b4580186c23a32b68b9db322beaecfee481b7d0 Mon Sep 17 00:00:00 2001 From: Daniel Sipka Date: Fri, 10 Apr 2015 10:14:12 +0200 Subject: [PATCH] unit testing refactor --- CMakeLists.txt | 30 ++--- ...persand_escape.h => ampersand_escape.data} | 0 test/data/{apostrophe.h => apostrophe.data} | 0 ...ray_of_strings.h => array_of_strings.data} | 0 test/data/{backslashes.h => backslashes.data} | 0 ...espace.h => bug_11_eating_whitespace.data} | 0 ...th_property.h => bug_length_property.data} | 0 .../{context_lookup.h => context_lookup.data} | 0 ...tespace.h => disappearing_whitespace.data} | 0 .../{double_render.h => double_render.data} | 0 test/data/{empty_list.h => empty_list.data} | 0 .../{empty_sections.h => empty_sections.data} | 0 .../{empty_string.h => empty_string.data} | 0 .../{empty_template.h => empty_template.data} | 0 ...error_not_found.h => error_not_found.data} | 0 test/data/{falsy.h => falsy.data} | 0 test/main.cpp | 112 +----------------- 17 files changed, 18 insertions(+), 124 deletions(-) rename test/data/{ampersand_escape.h => ampersand_escape.data} (100%) rename test/data/{apostrophe.h => apostrophe.data} (100%) rename test/data/{array_of_strings.h => array_of_strings.data} (100%) rename test/data/{backslashes.h => backslashes.data} (100%) rename test/data/{bug_11_eating_whitespace.h => bug_11_eating_whitespace.data} (100%) rename test/data/{bug_length_property.h => bug_length_property.data} (100%) rename test/data/{context_lookup.h => context_lookup.data} (100%) rename test/data/{disappearing_whitespace.h => disappearing_whitespace.data} (100%) rename test/data/{double_render.h => double_render.data} (100%) rename test/data/{empty_list.h => empty_list.data} (100%) rename test/data/{empty_sections.h => empty_sections.data} (100%) rename test/data/{empty_string.h => empty_string.data} (100%) rename test/data/{empty_template.h => empty_template.data} (100%) rename test/data/{error_not_found.h => error_not_found.data} (100%) rename test/data/{falsy.h => falsy.data} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 761b68b..6b063e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,21 +30,21 @@ target_link_libraries(filetoheader ${Boost_PROGRAM_OPTIONS_LIBRARY}) add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/test_data.h COMMAND ${CMAKE_BINARY_DIR}/filetoheader --output ${CMAKE_BINARY_DIR}/test_data.h --namespace mstchtest - -Dampersand_escape.h -Sampersand_escape.mustache -Sampersand_escape.txt - -Dapostrophe.h -Sapostrophe.mustache -Sapostrophe.txt - -Darray_of_strings.h -Sarray_of_strings.mustache -Sarray_of_strings.txt - -Dbackslashes.h -Sbackslashes.mustache -Sbackslashes.txt - -Dbug_11_eating_whitespace.h -Sbug_11_eating_whitespace.mustache -Sbug_11_eating_whitespace.txt - -Dbug_length_property.h -Sbug_length_property.mustache -Sbug_length_property.txt - -Dcontext_lookup.h -Scontext_lookup.mustache -Scontext_lookup.txt - -Ddisappearing_whitespace.h -Sdisappearing_whitespace.mustache -Sdisappearing_whitespace.txt - -Ddouble_render.h -Sdouble_render.mustache -Sdouble_render.txt - -Dempty_list.h -Sempty_list.mustache -Sempty_list.txt - -Dempty_sections.h -Sempty_sections.mustache -Sempty_sections.txt - -Dempty_string.h -Sempty_string.mustache -Sempty_string.txt - -Dempty_template.h -Sempty_template.mustache -Sempty_template.txt - -Derror_not_found.h -Serror_not_found.mustache -Serror_not_found.txt - -Dfalsy.h -Sfalsy.mustache -Sfalsy.txt + -Dampersand_escape.data -Sampersand_escape.mustache -Sampersand_escape.txt + -Dapostrophe.data -Sapostrophe.mustache -Sapostrophe.txt + -Darray_of_strings.data -Sarray_of_strings.mustache -Sarray_of_strings.txt + -Dbackslashes.data -Sbackslashes.mustache -Sbackslashes.txt + -Dbug_11_eating_whitespace.data -Sbug_11_eating_whitespace.mustache -Sbug_11_eating_whitespace.txt + -Dbug_length_property.data -Sbug_length_property.mustache -Sbug_length_property.txt + -Dcontext_lookup.data -Scontext_lookup.mustache -Scontext_lookup.txt + -Ddisappearing_whitespace.data -Sdisappearing_whitespace.mustache -Sdisappearing_whitespace.txt + -Ddouble_render.data -Sdouble_render.mustache -Sdouble_render.txt + -Dempty_list.data -Sempty_list.mustache -Sempty_list.txt + -Dempty_sections.data -Sempty_sections.mustache -Sempty_sections.txt + -Dempty_string.data -Sempty_string.mustache -Sempty_string.txt + -Dempty_template.data -Sempty_template.mustache -Sempty_template.txt + -Derror_not_found.data -Serror_not_found.mustache -Serror_not_found.txt + -Dfalsy.data -Sfalsy.mustache -Sfalsy.txt DEPENDS ${CMAKE_BINARY_DIR}/filetoheader WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test/data/) set_source_files_properties(${CMAKE_BINARY_DIR}/test_data.h PROPERTIES GENERATED TRUE) diff --git a/test/data/ampersand_escape.h b/test/data/ampersand_escape.data similarity index 100% rename from test/data/ampersand_escape.h rename to test/data/ampersand_escape.data diff --git a/test/data/apostrophe.h b/test/data/apostrophe.data similarity index 100% rename from test/data/apostrophe.h rename to test/data/apostrophe.data diff --git a/test/data/array_of_strings.h b/test/data/array_of_strings.data similarity index 100% rename from test/data/array_of_strings.h rename to test/data/array_of_strings.data diff --git a/test/data/backslashes.h b/test/data/backslashes.data similarity index 100% rename from test/data/backslashes.h rename to test/data/backslashes.data diff --git a/test/data/bug_11_eating_whitespace.h b/test/data/bug_11_eating_whitespace.data similarity index 100% rename from test/data/bug_11_eating_whitespace.h rename to test/data/bug_11_eating_whitespace.data diff --git a/test/data/bug_length_property.h b/test/data/bug_length_property.data similarity index 100% rename from test/data/bug_length_property.h rename to test/data/bug_length_property.data diff --git a/test/data/context_lookup.h b/test/data/context_lookup.data similarity index 100% rename from test/data/context_lookup.h rename to test/data/context_lookup.data diff --git a/test/data/disappearing_whitespace.h b/test/data/disappearing_whitespace.data similarity index 100% rename from test/data/disappearing_whitespace.h rename to test/data/disappearing_whitespace.data diff --git a/test/data/double_render.h b/test/data/double_render.data similarity index 100% rename from test/data/double_render.h rename to test/data/double_render.data diff --git a/test/data/empty_list.h b/test/data/empty_list.data similarity index 100% rename from test/data/empty_list.h rename to test/data/empty_list.data diff --git a/test/data/empty_sections.h b/test/data/empty_sections.data similarity index 100% rename from test/data/empty_sections.h rename to test/data/empty_sections.data diff --git a/test/data/empty_string.h b/test/data/empty_string.data similarity index 100% rename from test/data/empty_string.h rename to test/data/empty_string.data diff --git a/test/data/empty_template.h b/test/data/empty_template.data similarity index 100% rename from test/data/empty_template.h rename to test/data/empty_template.data diff --git a/test/data/error_not_found.h b/test/data/error_not_found.data similarity index 100% rename from test/data/error_not_found.h rename to test/data/error_not_found.data diff --git a/test/data/falsy.h b/test/data/falsy.data similarity index 100% rename from test/data/falsy.h rename to test/data/falsy.data diff --git a/test/main.cpp b/test/main.cpp index dd19b02..3f405a8 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -1,11 +1,10 @@ #define CATCH_CONFIG_MAIN + #include "catch.hpp" - -#include - +#include "mstch.h" #include "test_data.h" -#define MSTCH_TEST(x,y) TEST_CASE(x) { REQUIRE(y ## _txt == mstch::render(y ## _mustache, y ## _h)); } +#define MSTCH_TEST(x,y) TEST_CASE(x) { REQUIRE(y ## _txt == mstch::render(y ## _mustache, y ## _data)); } MSTCH_TEST("Ampersand escape", mstchtest::ampersand_escape) MSTCH_TEST("Apostrophe", mstchtest::apostrophe) @@ -23,111 +22,6 @@ MSTCH_TEST("Empty template", mstchtest::empty_template) MSTCH_TEST("Error not found", mstchtest::error_not_found) MSTCH_TEST("Falsy", mstchtest::falsy) -/*TEST_CASE("Ampersand escape") { - #include "data/ampersand_escape.h" - auto tpl = file_to_string("data/ampersand_escape.mustache"); - auto exp = file_to_string("data/ampersand_escape.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Apostrophe") { - #include "data/apostrophe.h" - auto tpl = file_to_string("data/apostrophe.mustache"); - auto exp = file_to_string("data/apostrophe.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Array of strings") { - #include "data/array_of_strings.h" - auto tpl = file_to_string("data/array_of_strings.mustache"); - auto exp = file_to_string("data/array_of_strings.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Backslashes") { - #include "data/backslashes.h" - auto tpl = file_to_string("data/backslashes.mustache"); - auto exp = file_to_string("data/backslashes.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Bug 11 eating whitespace") { - #include "data/bug_11_eating_whitespace.h" - auto tpl = file_to_string("data/bug_11_eating_whitespace.mustache"); - auto exp = file_to_string("data/bug_11_eating_whitespace.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Bug length property") { - #include "data/bug_length_property.h" - auto tpl = file_to_string("data/bug_length_property.mustache"); - auto exp = file_to_string("data/bug_length_property.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Context lookup") { - #include "data/context_lookup.h" - auto tpl = file_to_string("data/context_lookup.mustache"); - auto exp = file_to_string("data/context_lookup.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Disappearing whitespace") { - #include "data/disappearing_whitespace.h" - auto tpl = file_to_string("data/disappearing_whitespace.mustache"); - auto exp = file_to_string("data/disappearing_whitespace.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Double render") { - #include "data/double_render.h" - auto tpl = file_to_string("data/double_render.mustache"); - auto exp = file_to_string("data/double_render.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Empty list") { - #include "data/empty_list.h" - auto tpl = file_to_string("data/empty_list.mustache"); - auto exp = file_to_string("data/empty_list.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Empty sections") { - #include "data/empty_sections.h" - auto tpl = file_to_string("data/empty_sections.mustache"); - auto exp = file_to_string("data/empty_sections.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Empty string") { - #include "data/empty_string.h" - auto tpl = file_to_string("data/empty_string.mustache"); - auto exp = file_to_string("data/empty_string.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Empty template") { - #include "data/empty_template.h" - auto tpl = file_to_string("data/empty_template.mustache"); - auto exp = file_to_string("data/empty_template.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Error not found") { - #include "data/error_not_found.h" - auto tpl = file_to_string("data/error_not_found.mustache"); - auto exp = file_to_string("data/error_not_found.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -} - -TEST_CASE("Falsy") { - #include "data/falsy.h" - auto tpl = file_to_string("data/falsy.mustache"); - auto exp = file_to_string("data/falsy.txt"); - REQUIRE(exp == mstch::render(tpl, data)); -}*/ - /*TEST_CASE("Falsy array") { #include "data/falsy_array.h" auto tpl = file_to_string("data/falsy_array.mustache");