use ctest for unit tests

This commit is contained in:
Daniel Sipka 2015-04-12 16:13:21 +02:00
parent 7e124ec47b
commit 23e8b46879
3 changed files with 58 additions and 49 deletions

View File

@ -1,10 +1,9 @@
cmake_minimum_required(VERSION 3.0.2 FATAL_ERROR)
cmake_minimum_required(VERSION 2.8)
project(mstch)
option (WITH_UNIT_TESTS "enable building unit test executable" OFF)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall")
add_subdirectory(src)
add_subdirectory(test)
if(WITH_UNIT_TESTS)
enable_testing()
add_test(NAME mstch_tests COMMAND mstch_test)
add_subdirectory(test)
endif()

View File

@ -8,6 +8,7 @@ include_directories(
add_executable(filetoheader filetoheader.cpp)
target_link_libraries(filetoheader ${Boost_PROGRAM_OPTIONS_LIBRARY})
set(filetoheader_exe ${CMAKE_CURRENT_BINARY_DIR}/filetoheader${CMAKE_EXECUTABLE_SUFFIX})
file(GLOB data_files RELATIVE
"${CMAKE_SOURCE_DIR}/test/data"
@ -15,6 +16,8 @@ file(GLOB data_files RELATIVE
foreach(data_file ${data_files})
list(APPEND genargs "-D${data_file}")
string(REGEX REPLACE "\\.data" "" test_name "${data_file}")
list(APPEND tests "${test_name}")
endforeach(data_file)
file(GLOB string_files RELATIVE
@ -28,8 +31,8 @@ endforeach(string_file)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/test_data.hpp
COMMAND ${CMAKE_CURRENT_BINARY_DIR}/filetoheader --output ${CMAKE_CURRENT_BINARY_DIR}/test_data.hpp --namespace mstchtest ${genargs}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/filetoheader
COMMAND ${filetoheader_exe} --output ${CMAKE_CURRENT_BINARY_DIR}/test_data.hpp --namespace mstchtest ${genargs}
DEPENDS ${filetoheader_exe}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/test/data/)
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/test_data.hpp PROPERTIES GENERATED TRUE)
add_custom_target(test_data_hpp DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/test_data.hpp)
@ -37,3 +40,7 @@ add_custom_target(test_data_hpp DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/test_data.hp
add_executable(mstch_test test_main.cpp)
target_link_libraries(mstch_test mstch)
add_dependencies(mstch_test test_data_hpp)
foreach(test ${tests})
add_test(NAME ${test} COMMAND mstch_test ${test})
endforeach(test)

View File

@ -1,46 +1,49 @@
#define CATCH_CONFIG_MAIN
#include <catch.hpp>
#include "catch.hpp"
#include "mstch/mstch.hpp"
#include "test_data.hpp"
#define MSTCH_TEST(x,y) TEST_CASE(x) { REQUIRE(y ## _txt == mstch::render(y ## _mustache, y ## _data)); }
using namespace mstchtest;
MSTCH_TEST("Ampersand escape", mstchtest::ampersand_escape)
MSTCH_TEST("Apostrophe", mstchtest::apostrophe)
MSTCH_TEST("Array of strings", mstchtest::array_of_strings)
MSTCH_TEST("Backslashes", mstchtest::backslashes)
MSTCH_TEST("Eating whitespace", mstchtest::bug_11_eating_whitespace)
MSTCH_TEST("Length property", mstchtest::bug_length_property)
MSTCH_TEST("Context lookup", mstchtest::context_lookup)
MSTCH_TEST("Disappearing whitespace", mstchtest::disappearing_whitespace)
MSTCH_TEST("Double render", mstchtest::double_render)
MSTCH_TEST("Empty list", mstchtest::empty_list)
MSTCH_TEST("Empty sections", mstchtest::empty_sections)
MSTCH_TEST("Empty string", mstchtest::empty_string)
MSTCH_TEST("Empty template", mstchtest::empty_template)
MSTCH_TEST("Error not found", mstchtest::error_not_found)
MSTCH_TEST("Falsy", mstchtest::falsy)
MSTCH_TEST("Falsy array", mstchtest::falsy_array)
MSTCH_TEST("Grandparent context", mstchtest::grandparent_context)
MSTCH_TEST("Implicit iterator", mstchtest::implicit_iterator)
MSTCH_TEST("Included tag", mstchtest::included_tag)
MSTCH_TEST("Inverted section", mstchtest::inverted_section)
MSTCH_TEST("Keys with questionsmarks", mstchtest::keys_with_questionmarks)
MSTCH_TEST("Multiline comment", mstchtest::multiline_comment)
MSTCH_TEST("Nested dot", mstchtest::nested_dot)
MSTCH_TEST("Nested iterating", mstchtest::nested_iterating)
MSTCH_TEST("Nesting", mstchtest::nesting)
MSTCH_TEST("Nesting same name", mstchtest::nesting_same_name)
MSTCH_TEST("Null lookup array", mstchtest::null_lookup_array)
MSTCH_TEST("Null lookup object", mstchtest::null_lookup_object)
MSTCH_TEST("Null view", mstchtest::null_view)
MSTCH_TEST("Recursion with same names", mstchtest::recursion_with_same_names)
MSTCH_TEST("Reuse of enumerables", mstchtest::reuse_of_enumerables)
MSTCH_TEST("Section as context", mstchtest::section_as_context)
MSTCH_TEST("String as context", mstchtest::string_as_context)
MSTCH_TEST("Two in a row", mstchtest::two_in_a_row)
MSTCH_TEST("Two sections", mstchtest::two_sections)
MSTCH_TEST("Whitespace", mstchtest::whitespace)
MSTCH_TEST("Zero view", mstchtest::zero_view)
#define MSTCH_TEST(x) TEST_CASE(#x) { \
REQUIRE(x ## _txt == mstch::render(x ## _mustache, x ## _data)); \
}
MSTCH_TEST(ampersand_escape)
MSTCH_TEST(apostrophe)
MSTCH_TEST(array_of_strings)
MSTCH_TEST(backslashes)
MSTCH_TEST(bug_11_eating_whitespace)
MSTCH_TEST(bug_length_property)
MSTCH_TEST(context_lookup)
MSTCH_TEST(disappearing_whitespace)
MSTCH_TEST(double_render)
MSTCH_TEST(empty_list)
MSTCH_TEST(empty_sections)
MSTCH_TEST(empty_string)
MSTCH_TEST(empty_template)
MSTCH_TEST(error_not_found)
MSTCH_TEST(falsy)
MSTCH_TEST(falsy_array)
MSTCH_TEST(grandparent_context)
MSTCH_TEST(implicit_iterator)
MSTCH_TEST(included_tag)
MSTCH_TEST(inverted_section)
MSTCH_TEST(keys_with_questionmarks)
MSTCH_TEST(multiline_comment)
MSTCH_TEST(nested_dot)
MSTCH_TEST(nested_iterating)
MSTCH_TEST(nesting)
MSTCH_TEST(nesting_same_name)
MSTCH_TEST(null_lookup_array)
MSTCH_TEST(null_lookup_object)
MSTCH_TEST(null_view)
MSTCH_TEST(recursion_with_same_names)
MSTCH_TEST(reuse_of_enumerables)
MSTCH_TEST(section_as_context)
MSTCH_TEST(string_as_context)
MSTCH_TEST(two_in_a_row)
MSTCH_TEST(two_sections)
MSTCH_TEST(whitespace)
MSTCH_TEST(zero_view)