Skip to content

Commit

Permalink
test: integrate handlebars and boost.url test suite
Browse files Browse the repository at this point in the history
This change integrates the test suite library developed for handlebars with the test suite library from boost.url that is being used for other tests.

With this integration, Handlebars tests are listed among any other tests in the library.

The features used for handlebars, such as the expression decomposer and the diff algorithm for golden master tests, have been integrated into the test library from Boost.URL.

fix #390
  • Loading branch information
alandefreitas committed Jul 10, 2023
1 parent fda33b1 commit 8aa8f80
Show file tree
Hide file tree
Showing 17 changed files with 773 additions and 660 deletions.
77 changes: 33 additions & 44 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ include(GNUInstallDirs)

option(MRDOX_BUILD_TESTS "Build tests" ${BUILD_TESTING})
option(MRDOX_BUILD_SHARED "Link shared" OFF)
option(MRDOX_BUILD_DOCS "Configure install target" OFF)
option(MRDOX_BUILD_DOCS "Build documentation" OFF)
option(MRDOX_INSTALL "Configure install target" ON)
option(MRDOX_PACKAGE "Build install package" ON)
option(MRDOX_GENERATE_REFERENCE "Generate reference.xml/reference.adoc" ON)
Expand Down Expand Up @@ -204,6 +204,7 @@ endif ()

file(GLOB_RECURSE TOOL_SOURCES CONFIGURE_DEPENDS tool/*.cpp tool/*.hpp)
add_executable(mrdox ${TOOL_SOURCES})
target_compile_definitions(mrdox PRIVATE -DMRDOX_TOOL)

target_include_directories(mrdox
PUBLIC
Expand All @@ -225,39 +226,6 @@ if (MRDOX_CLANG)
)
endif ()


#-------------------------------------------------
#
# Tests
#
#-------------------------------------------------

file(GLOB TEST_SOURCES CONFIGURE_DEPENDS
test/*.cpp
test/*.hpp)
add_executable(mrdox-test ${TEST_SOURCES})

target_include_directories(mrdox-test
PRIVATE
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/lib"
"${PROJECT_SOURCE_DIR}/test"
"${PROJECT_SOURCE_DIR}/tool"
)

target_compile_definitions(mrdox PRIVATE -DMRDOX_TOOL)
target_link_libraries(mrdox-test PUBLIC mrdox-core)

if (MRDOX_CLANG)
target_compile_options(
mrdox-test
PRIVATE
-Wno-covered-switch-default
)
endif ()

#-------------------------------------------------------------------------------

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
#source_group(TREE ${PROJECT_SOURCE_DIR} PREFIX "" FILES CMakeLists.txt)
source_group(TREE ${PROJECT_SOURCE_DIR}/include/mrdox PREFIX "include" FILES ${INCLUDES})
Expand All @@ -270,8 +238,27 @@ source_group(TREE ${PROJECT_SOURCE_DIR}/source PREFIX "source" FILES ${SOURCES})
#-------------------------------------------------

if (MRDOX_BUILD_TESTS)
# if we run tests, we need the addons in the right place.
#-------------------------------------------------
# Unit tests
#-------------------------------------------------
include(CTest)
file(GLOB_RECURSE TEST_SUITE_FILES CONFIGURE_DEPENDS test/test_suite/*.cpp test/test_suite/*.hpp)
file(GLOB_RECURSE UNIT_TEST_SOURCES CONFIGURE_DEPENDS test/unit/*.cpp test/unit/*.hpp)
add_executable(mrdox-test ${TEST_SUITE_FILES} ${UNIT_TEST_SOURCES})
target_include_directories(mrdox-test
PRIVATE
"${PROJECT_SOURCE_DIR}/include"
"${PROJECT_SOURCE_DIR}/lib"
"${PROJECT_SOURCE_DIR}/tool"
"${PROJECT_SOURCE_DIR}/test/test_suite"
)
target_link_libraries(mrdox-test PUBLIC mrdox-core)
if (MRDOX_CLANG)
target_compile_options(mrdox-test PRIVATE -Wno-covered-switch-default)
endif ()
target_compile_definitions(mrdox-test PRIVATE -DMRDOX_UNIT_TEST_DIR="${CMAKE_CURRENT_SOURCE_DIR}/test/unit")
add_custom_command(
# if we run tests, we need the addons in the right place.
TARGET mrdox-test
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy
Expand All @@ -280,25 +267,28 @@ if (MRDOX_BUILD_TESTS)
BYPRODUCTS ${CMAKE_BINARY_DIR}/addons
DEPENDS ${CMAKE_SOURCE_DIR}/addons
)
add_test(NAME mrdox-test COMMAND mrdox-test --action test "${PROJECT_SOURCE_DIR}/test-files/old-tests")

file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS source/*.cpp source/*.hpp)
enable_testing()
add_test(NAME mrdox-test COMMAND mrdox-test --action test
"${PROJECT_SOURCE_DIR}/test-files/old-tests"
)

#-------------------------------------------------
# Reference documentation
#-------------------------------------------------
if (MRDOX_GENERATE_REFERENCE)
# test run
file(GLOB_RECURSE REFERENCE_SOURCES CONFIGURE_DEPENDS source/*.cpp source/*.hpp)

set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
include(mrdox.cmake)

mrdox(FORMAT adoc CONFIG docs/mrdox.yml SOURCES ${TEST_SOURCES})
mrdox(FORMAT xml CONFIG docs/mrdox.yml SOURCES ${TEST_SOURCES})
mrdox(FORMAT adoc CONFIG docs/mrdox.yml SOURCES ${REFERENCE_SOURCES})
mrdox(FORMAT xml CONFIG docs/mrdox.yml SOURCES ${REFERENCE_SOURCES})

add_custom_target(reference_adoc ALL DEPENDS reference.adoc)
add_custom_target(reference_xml ALL DEPENDS reference.xml)
endif()

#-------------------------------------------------
# XML lint
#-------------------------------------------------
find_package(LibXml2)
if (LibXml2_FOUND)
find_package(Java REQUIRED Runtime)
Expand All @@ -320,7 +310,6 @@ if (MRDOX_BUILD_TESTS)
--relaxng ${CMAKE_CURRENT_BINARY_DIR}/mrdox.rng ${XML_SOURCES}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
endif()

endif()


Expand Down
6 changes: 4 additions & 2 deletions include/mrdox/Platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,10 @@ namespace mrdox {
# endif
#endif

#if ! defined(__GNUC__) && defined(_MSC_VER)
#define FMT_CONSTEVAL
#ifndef FMT_CONSTEVAL
# if !defined(__GNUC__) && defined(_MSC_VER)
# define FMT_CONSTEVAL
# endif
#endif

} // mrdox
Expand Down
2 changes: 1 addition & 1 deletion include/mrdox/Support/Handlebars.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ struct HandlebarsOptions
{
/** Escape HTML entities
*/
bool noHTMLEscape = false;
bool noEscape = false;

/** Templates will throw rather than ignore missing fields
*/
Expand Down
12 changes: 6 additions & 6 deletions lib/Support/Handlebars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ escapeExpression(
std::string_view str,
HandlebarsOptions opt)
{
if (opt.noHTMLEscape)
if (opt.noEscape)
{
out << str;
}
Expand Down Expand Up @@ -370,7 +370,7 @@ struct defaultLogger {
os << ']';
for (std::size_t i = 0; i < args.size(); ++i) {
HandlebarsOptions opt;
opt.noHTMLEscape = true;
opt.noEscape = true;
format_to(os, args.at(i), opt);
os << " ";
}
Expand Down Expand Up @@ -1352,7 +1352,7 @@ renderExpression(
return;

auto opt2 = opt;
opt2.noHTMLEscape = tag.forceNoHTMLEscape || opt.noHTMLEscape;
opt2.noEscape = tag.forceNoHTMLEscape || opt.noEscape;

auto it = helpers_.find(tag.helper);
if (it != helpers_.end()) {
Expand All @@ -1368,7 +1368,7 @@ renderExpression(
if (render == HelperBehavior::RENDER_RESULT) {
format_to(out, res, opt2);
} else if (render == HelperBehavior::RENDER_RESULT_NOESCAPE) {
opt2.noHTMLEscape = true;
opt2.noEscape = true;
format_to(out, res, opt2);
}
if (tag.removeRWhitespace) {
Expand All @@ -1394,7 +1394,7 @@ renderExpression(
if (render == HelperBehavior::RENDER_RESULT) {
format_to(out, res, opt2);
} else if (render == HelperBehavior::RENDER_RESULT_NOESCAPE) {
opt2.noHTMLEscape = true;
opt2.noEscape = true;
format_to(out, res, opt2);
}
if (tag.removeRWhitespace) {
Expand Down Expand Up @@ -1688,7 +1688,7 @@ renderBlock(
format_to(out, res, opt);
} else if (render == HelperBehavior::RENDER_RESULT_NOESCAPE) {
HandlebarsOptions opt2 = opt;
opt2.noHTMLEscape = true;
opt2.noEscape = true;
format_to(out, res, opt2);
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions test/test_suite/detail/decomposer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright (c) 2023 Alan de Freitas ([email protected])
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/url
//

#include "decomposer.hpp"

#if __has_include(<cxxabi.h>)
#include <cxxabi.h>
#endif

namespace test_suite {
namespace detail {
std::string demangle(const char *mangled)
{
#if __has_include(<cxxabi.h>)
int status;
char *demangled = abi::__cxa_demangle(mangled, nullptr, nullptr, &status);
std::string result;
if (status == 0) {
result = demangled;
} else {
result = mangled;
}
std::free(demangled);
return result;
#else
return mangled;
#endif
}
} // detail
} // test_suite
Loading

0 comments on commit 8aa8f80

Please sign in to comment.