Merge pull request #200 from ctcmkl/several-simple-patches

Several simple patches
This commit is contained in:
Toru Niina
2022-09-30 23:33:57 +09:00
committed by GitHub
45 changed files with 339 additions and 397 deletions

View File

@@ -1,11 +1,20 @@
include(ExternalProject) include(ExternalProject)
ExternalProject_Add(toml
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/toml set(TOML11_LANGSPEC_GIT_REPOSITORY "https://github.com/toml-lang/toml" CACHE STRING
GIT_REPOSITORY https://github.com/toml-lang/toml "URL of the TOML language specification repository")
GIT_TAG v0.5.0
set(TOML11_LANGSPEC_SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/toml" CACHE FILEPATH
"directory for the TOML language specification tree")
if(NOT EXISTS "${TOML11_LANGSPEC_SOURCE_DIR}/toml.abnf")
ExternalProject_Add(toml
SOURCE_DIR "${TOML11_LANGSPEC_SOURCE_DIR}"
GIT_REPOSITORY "${TOML11_LANGSPEC_GIT_REPOSITORY}"
GIT_TAG "v0.5.0"
CONFIGURE_COMMAND "" CONFIGURE_COMMAND ""
BUILD_COMMAND "" BUILD_COMMAND ""
INSTALL_COMMAND "") INSTALL_COMMAND "")
endif()
set(TEST_NAMES set(TEST_NAMES
test_datetime test_datetime
@@ -62,6 +71,82 @@ CHECK_CXX_COMPILER_FLAG("-Wrange-loop-analysis" COMPILER_SUPPORTS_WRANGE_LOOP_AN
CHECK_CXX_COMPILER_FLAG("-Wundef" COMPILER_SUPPORTS_WUNDEF) CHECK_CXX_COMPILER_FLAG("-Wundef" COMPILER_SUPPORTS_WUNDEF)
CHECK_CXX_COMPILER_FLAG("-Wshadow" COMPILER_SUPPORTS_WSHADOW) CHECK_CXX_COMPILER_FLAG("-Wshadow" COMPILER_SUPPORTS_WSHADOW)
include(CheckCXXSourceCompiles)
# check which standard library implementation is used. If libstdc++ is used,
# it will fail to compile. It compiles if libc++ is used.
check_cxx_source_compiles("
#include <cstddef>
#ifdef __GLIBCXX__
static_assert(false);
#endif
int main() {
return 0;
}" TOML11_WITH_LIBCXX_LIBRARY)
# LLVM 8 requires -lc++fs if compiled with libc++ to use <filesystem>.
# LLVM 9+ does not require any special library.
# GCC 8 requires -lstdc++fs. GCC 9+ does not require it.
#
# Yes, we can check the version of the compiler used in the current build
# directly in CMake. But, in most cases, clang build uses libstdc++ as the
# standard library implementation and it makes the condition complicated.
# In many environment, the default installed C++ compiler is GCC and libstdc++
# is installed along with it. In most build on such an environment, even if we
# chose clang as the C++ compiler, still libstdc++ is used. Checking default
# gcc version makes the condition complicated.
# The purpose of this file is to compile tests. We know the environment on which
# the tests run. We can set this option and, I think, it is easier and better.
option(TOML11_REQUIRE_FILESYSTEM_LIBRARY "need to link -lstdc++fs or -lc++fs" OFF)
find_package(Boost COMPONENTS unit_test_framework REQUIRED)
set(PREVIOUSLY_REQUIRED_INCLUDES "${CMAKE_REQUIRED_INCLUDES}")
set(PREVIOUSLY_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}")
list(APPEND CMAKE_REQUIRED_INCLUDES ${Boost_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_LIBRARIES ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY})
check_cxx_source_compiles("
#define BOOST_TEST_MODULE \"dummy\"
#undef BOOST_TEST_DYN_LINK
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
BOOST_AUTO_TEST_CASE(proforma) { BOOST_TEST(true); }
" TOML11_WITH_BOOST_TEST_HEADER)
check_cxx_source_compiles("
#define BOOST_TEST_MODULE \"dummy\"
#undef BOOST_TEST_DYN_LINK
#undef BOOST_TEST_NO_LIB
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(proforma) { BOOST_TEST(true); }
" TOML11_WITH_BOOST_TEST_STATIC)
check_cxx_source_compiles("
#define BOOST_TEST_MODULE \"dummy\"
#define BOOST_TEST_DYN_LINK
#undef BOOST_TEST_NO_LIB
#include <boost/test/unit_test.hpp>
BOOST_AUTO_TEST_CASE(proforma) { BOOST_TEST(true); }
" TOML11_WITH_BOOST_TEST_DYNAMIC)
set(CMAKE_REQUIRED_INCLUDES "${PREVIOUSLY_REQUIRED_INCLUDES}")
set(CMAKE_REQUIRED_LIBRARIES "${PREVIOUSLY_REQUIRED_LIBRARIES}")
unset(PREVIOUSLY_REQUIRED_INCLUDES)
unset(PREVIOUSLY_REQUIRED_LIBRARIES)
if(TOML11_WITH_BOOST_TEST_DYNAMIC)
add_definitions(-DUNITTEST_FRAMEWORK_LIBRARY_EXIST -DBOOST_TEST_DYN_LINK)
elseif(TOML11_WITH_BOOST_TEST_STATIC)
add_definitions(-DUNITTEST_FRAMEWORK_LIBRARY_EXIST)
elseif(TOML11_WITH_BOOST_TEST_HEADER)
add_definitions(-DBOOST_TEST_NO_LIB)
else()
message(FATAL_ERROR "Neither the Boost.Test static or shared library nor the header-only version seem to be usable.")
endif()
if(COMPILER_SUPPORTS_WALL) if(COMPILER_SUPPORTS_WALL)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
endif() endif()
@@ -152,41 +237,18 @@ if(MSVC)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4265") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4265")
endif() endif()
find_package(Boost COMPONENTS unit_test_framework REQUIRED) set(TEST_ENVIRON "TOMLDIR=${TOML11_LANGSPEC_SOURCE_DIR}")
add_definitions(-DBOOST_TEST_DYN_LINK) if(WIN32)
add_definitions(-DUNITTEST_FRAMEWORK_LIBRARY_EXIST) # Set the PATH to be able to find Boost DLL
STRING(REPLACE ";" "\\;" PATH_STRING "$ENV{PATH}")
# check which standard library implementation is used. If libstdc++ is used, list(APPEND TEST_ENVIRON "PATH=${PATH_STRING}\;${Boost_LIBRARY_DIRS}")
# it will fail to compile. It compiles if libc++ is used. endif()
include(CheckCXXSourceCompiles)
check_cxx_source_compiles("
#include <cstddef>
#ifdef __GLIBCXX__
static_assert(false);
#endif
int main() {
return 0;
}" TOML11_WITH_LIBCXX_LIBRARY)
# LLVM 8 requires -lc++fs if compiled with libc++ to use <filesystem>.
# LLVM 9+ does not require any special library.
# GCC 8 requires -lstdc++fs. GCC 9+ does not require it.
#
# Yes, we can check the version of the compiler used in the current build
# directly in CMake. But, in most cases, clang build uses libstdc++ as the
# standard library implementation and it makes the condition complicated.
# In many environment, the default installed C++ compiler is GCC and libstdc++
# is installed along with it. In most build on such an environment, even if we
# chose clang as the C++ compiler, still libstdc++ is used. Checking default
# gcc version makes the condition complicated.
# The purpose of this file is to compile tests. We know the environment on which
# the tests run. We can set this option and, I think, it is easier and better.
option(TOML11_REQUIRE_FILESYSTEM_LIBRARY "need to link -lstdc++fs or -lc++fs" OFF)
foreach(TEST_NAME ${TEST_NAMES}) foreach(TEST_NAME ${TEST_NAMES})
add_executable(${TEST_NAME} ${TEST_NAME}.cpp) add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
target_link_libraries(${TEST_NAME} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} toml11::toml11) target_link_libraries(${TEST_NAME} ${Boost_UNIT_TEST_FRAMEWORK_LIBRARY} toml11::toml11)
target_include_directories(${TEST_NAME} SYSTEM PRIVATE ${Boost_INCLUDE_DIRS}) target_include_directories(${TEST_NAME} SYSTEM PRIVATE ${Boost_INCLUDE_DIRS})
target_compile_definitions(${TEST_NAME} PRIVATE "BOOST_TEST_MODULE=\"${TEST_NAME}\"")
# to compile tests with <filesystem>... # to compile tests with <filesystem>...
if(TOML11_REQUIRE_FILESYSTEM_LIBRARY) if(TOML11_REQUIRE_FILESYSTEM_LIBRARY)
@@ -212,14 +274,7 @@ foreach(TEST_NAME ${TEST_NAMES})
endif() endif()
add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_test(NAME ${TEST_NAME} COMMAND ${TEST_NAME} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
set_tests_properties(${TEST_NAME} PROPERTIES ENVIRONMENT "${TEST_ENVIRON}")
# Set the PATH to be able to find Boost DLL
if(WIN32)
STRING(REPLACE ";" "\\;" PATH_STRING "$ENV{PATH}")
set_tests_properties(${TEST_NAME}
PROPERTIES ENVIRONMENT "PATH=${PATH_STRING}\;${Boost_LIBRARY_DIRS}"
)
endif()
endforeach(TEST_NAME) endforeach(TEST_NAME)

View File

@@ -1,4 +1,5 @@
#include "toml.hpp" #include <toml.hpp>
#include <iostream> #include <iostream>
#include <iomanip> #include <iomanip>

View File

@@ -1,6 +1,7 @@
#include "toml.hpp" #include <toml.hpp>
#include <iostream>
#include <iomanip> #include <iomanip>
#include <iostream>
int main(int argc, char **argv) int main(int argc, char **argv)
{ {

View File

@@ -1,6 +1,7 @@
#include "toml.hpp" #include <toml.hpp>
#include <iostream>
#include <iomanip> #include <iomanip>
#include <iostream>
struct json_serializer struct json_serializer
{ {

View File

@@ -1,13 +1,7 @@
#define BOOST_TEST_MODULE "test_comments"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include "unit_test.hpp"
BOOST_AUTO_TEST_CASE(test_comment_before) BOOST_AUTO_TEST_CASE(test_comment_before)
{ {
{ {

View File

@@ -1,12 +1,7 @@
#define BOOST_TEST_MODULE "test_datetime"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/datetime.hpp> #include <toml/datetime.hpp>
#include "unit_test.hpp"
BOOST_AUTO_TEST_CASE(test_local_date) BOOST_AUTO_TEST_CASE(test_local_date)
{ {
const toml::local_date date(2018, toml::month_t::Jan, 1); const toml::local_date date(2018, toml::month_t::Jan, 1);

View File

@@ -1,13 +1,9 @@
#define BOOST_TEST_MODULE "test_error_detection"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include <iostream>
#include "unit_test.hpp"
#include <fstream> #include <fstream>
#include <iostream>
BOOST_AUTO_TEST_CASE(test_detect_empty_key) BOOST_AUTO_TEST_CASE(test_detect_empty_key)
{ {

View File

@@ -1,16 +1,12 @@
#define BOOST_TEST_MODULE "test_expect"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include "unit_test.hpp"
#include <array>
#include <deque>
#include <list>
#include <map> #include <map>
#include <unordered_map> #include <unordered_map>
#include <list>
#include <deque>
#include <array>
BOOST_AUTO_TEST_CASE(test_expect) BOOST_AUTO_TEST_CASE(test_expect)
{ {

View File

@@ -1,11 +1,7 @@
#define BOOST_TEST_MODULE "test_extended_conversions"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include "unit_test.hpp"
#include <deque> #include <deque>
#include <map> #include <map>

View File

@@ -1,22 +1,17 @@
#define BOOST_TEST_MODULE "test_find"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include <map>
#include <unordered_map> #include "unit_test.hpp"
#include <list>
#include <deque>
#include <array> #include <array>
#include <deque>
#include <list>
#include <map>
#include <tuple>
#include <unordered_map>
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L #if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
#include <string_view> #include <string_view>
#endif #endif
#include <tuple>
using test_value_types = std::tuple< using test_value_types = std::tuple<
toml::basic_value<toml::discard_comments>, toml::basic_value<toml::discard_comments>,
@@ -830,4 +825,3 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_get_toml_offset_datetime, value_type, test_va
BOOST_TEST(tm.tm_sec == 0); BOOST_TEST(tm.tm_sec == 0);
} }
} }

View File

@@ -1,17 +1,14 @@
#define BOOST_TEST_MODULE "test_find_or"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include <map>
#include <unordered_map> #include "unit_test.hpp"
#include <list>
#include <deque>
#include <array> #include <array>
#include <deque>
#include <list>
#include <map>
#include <tuple> #include <tuple>
#include <unordered_map>
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L #if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
#include <string_view> #include <string_view>
#endif #endif

View File

@@ -1,17 +1,14 @@
#define BOOST_TEST_MODULE "test_find_or_recursive"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include <map>
#include <unordered_map> #include "unit_test.hpp"
#include <list>
#include <deque>
#include <array> #include <array>
#include <deque>
#include <list>
#include <map>
#include <tuple> #include <tuple>
#include <unordered_map>
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L #if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
#include <string_view> #include <string_view>
#endif #endif
@@ -394,8 +391,3 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_find_or_move_only, value_type, test_value_typ
BOOST_TEST(ref == toml::find_or(v, "key1", "key2", std::move(opt))); BOOST_TEST(ref == toml::find_or(v, "key1", "key2", std::move(opt)));
} }
} }

View File

@@ -1,11 +1,7 @@
#define BOOST_TEST_MODULE "test_format_error"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include "unit_test.hpp"
#include <iostream> #include <iostream>
// to check it successfully compiles. it does not check the formatted string. // to check it successfully compiles. it does not check the formatted string.

View File

@@ -1,17 +1,14 @@
#define BOOST_TEST_MODULE "test_get"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include <map>
#include <unordered_map> #include "unit_test.hpp"
#include <list>
#include <deque>
#include <array> #include <array>
#include <deque>
#include <list>
#include <map>
#include <tuple> #include <tuple>
#include <unordered_map>
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L #if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
#include <string_view> #include <string_view>
#endif #endif
@@ -506,4 +503,3 @@ BOOST_AUTO_TEST_CASE_TEMPLATE(test_get_toml_offset_datetime, value_type, test_va
BOOST_TEST(tm.tm_sec == 0); BOOST_TEST(tm.tm_sec == 0);
} }
} }

View File

@@ -1,17 +1,14 @@
#define BOOST_TEST_MODULE "test_get_or"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include <map>
#include <unordered_map> #include "unit_test.hpp"
#include <list>
#include <deque>
#include <array> #include <array>
#include <deque>
#include <list>
#include <map>
#include <tuple> #include <tuple>
#include <unordered_map>
#if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L #if TOML11_CPLUSPLUS_STANDARD_VERSION >= 201703L
#include <string_view> #include <string_view>
#endif #endif

View File

@@ -1,6 +1,6 @@
#define BOOST_TEST_MODULE "test_lex_boolean"
#include <boost/test/unit_test.hpp>
#include <toml/lexer.hpp> #include <toml/lexer.hpp>
#include "unit_test.hpp"
#include "test_lex_aux.hpp" #include "test_lex_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,6 +1,6 @@
#define BOOST_TEST_MODULE "test_lex_datetime"
#include <boost/test/unit_test.hpp>
#include <toml/lexer.hpp> #include <toml/lexer.hpp>
#include "unit_test.hpp"
#include "test_lex_aux.hpp" #include "test_lex_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,9 +1,10 @@
#define BOOST_TEST_MODULE "test_lex_floating"
#include <boost/test/unit_test.hpp>
#include <toml/lexer.hpp> #include <toml/lexer.hpp>
#include <limits>
#include "unit_test.hpp"
#include "test_lex_aux.hpp" #include "test_lex_aux.hpp"
#include <limits>
using namespace toml; using namespace toml;
using namespace detail; using namespace detail;

View File

@@ -1,6 +1,6 @@
#define BOOST_TEST_MODULE "test_lex_integer"
#include <boost/test/unit_test.hpp>
#include <toml/lexer.hpp> #include <toml/lexer.hpp>
#include "unit_test.hpp"
#include "test_lex_aux.hpp" #include "test_lex_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,6 +1,6 @@
#define BOOST_TEST_MODULE "lex_key_comment_test"
#include <boost/test/unit_test.hpp>
#include <toml/lexer.hpp> #include <toml/lexer.hpp>
#include "unit_test.hpp"
#include "test_lex_aux.hpp" #include "test_lex_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,6 +1,6 @@
#define BOOST_TEST_MODULE "test_lex_string"
#include <boost/test/unit_test.hpp>
#include <toml/lexer.hpp> #include <toml/lexer.hpp>
#include "unit_test.hpp"
#include "test_lex_aux.hpp" #include "test_lex_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,11 +1,7 @@
#define BOOST_TEST_MODULE "test_literals"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include "unit_test.hpp"
#include <map> #include <map>
BOOST_AUTO_TEST_CASE(test_file_as_literal) BOOST_AUTO_TEST_CASE(test_file_as_literal)

View File

@@ -1,11 +1,6 @@
#define BOOST_TEST_MODULE "parse_array<toml::value>_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp> #include <toml/parser.hpp>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,11 +1,6 @@
#define BOOST_TEST_MODULE "test_parse_boolean"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp> #include <toml/parser.hpp>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,11 +1,6 @@
#define BOOST_TEST_MODULE "parse_datetime_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp> #include <toml/parser.hpp>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,19 +1,15 @@
#define BOOST_TEST_MODULE "test_parse_file"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include <iostream>
#include <fstream> #include "unit_test.hpp"
#include <map>
#include <deque> #include <deque>
#include <fstream>
#include <iostream>
#include <map>
BOOST_AUTO_TEST_CASE(test_example) BOOST_AUTO_TEST_CASE(test_example)
{ {
const auto data = toml::parse("toml/tests/example.toml"); const auto data = toml::parse(testinput("example.toml"));
BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example"); BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example");
const auto& owner = toml::find(data, "owner"); const auto& owner = toml::find(data, "owner");
@@ -76,7 +72,7 @@ BOOST_AUTO_TEST_CASE(test_example)
BOOST_AUTO_TEST_CASE(test_example_stream) BOOST_AUTO_TEST_CASE(test_example_stream)
{ {
std::ifstream ifs("toml/tests/example.toml", std::ios::binary); std::ifstream ifs(testinput("example.toml"), std::ios::binary);
const auto data = toml::parse(ifs); const auto data = toml::parse(ifs);
BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example"); BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example");
@@ -144,7 +140,7 @@ BOOST_AUTO_TEST_CASE(test_example_stream)
BOOST_AUTO_TEST_CASE(test_example_file_pointer) BOOST_AUTO_TEST_CASE(test_example_file_pointer)
{ {
FILE * file = fopen("toml/tests/example.toml", "rb"); FILE * file = fopen(testinput("example.toml").c_str(), "rb");
const auto data = toml::parse(file, "toml/tests/example.toml"); const auto data = toml::parse(file, "toml/tests/example.toml");
fclose(file); fclose(file);
@@ -213,7 +209,7 @@ BOOST_AUTO_TEST_CASE(test_example_file_pointer)
BOOST_AUTO_TEST_CASE(test_fruit) BOOST_AUTO_TEST_CASE(test_fruit)
{ {
const auto data = toml::parse("toml/tests/fruit.toml"); const auto data = toml::parse(testinput("fruit.toml"));
const auto blah = toml::find<toml::array>(toml::find(data, "fruit"), "blah"); const auto blah = toml::find<toml::array>(toml::find(data, "fruit"), "blah");
BOOST_TEST(toml::find<std::string>(blah.at(0), "name") == "apple"); BOOST_TEST(toml::find<std::string>(blah.at(0), "name") == "apple");
BOOST_TEST(toml::find<std::string>(blah.at(1), "name") == "banana"); BOOST_TEST(toml::find<std::string>(blah.at(1), "name") == "banana");
@@ -231,7 +227,7 @@ BOOST_AUTO_TEST_CASE(test_fruit)
BOOST_AUTO_TEST_CASE(test_hard_example) BOOST_AUTO_TEST_CASE(test_hard_example)
{ {
const auto data = toml::parse("toml/tests/hard_example.toml"); const auto data = toml::parse(testinput("hard_example.toml"));
const auto the = toml::find(data, "the"); const auto the = toml::find(data, "the");
BOOST_TEST(toml::find<std::string>(the, "test_string") == BOOST_TEST(toml::find<std::string>(the, "test_string") ==
"You'll hate me after this - #"); "You'll hate me after this - #");
@@ -258,7 +254,7 @@ BOOST_AUTO_TEST_CASE(test_hard_example)
} }
BOOST_AUTO_TEST_CASE(test_hard_example_comment) BOOST_AUTO_TEST_CASE(test_hard_example_comment)
{ {
const auto data = toml::parse<toml::preserve_comments>("toml/tests/hard_example.toml"); const auto data = toml::parse<toml::preserve_comments>(testinput("hard_example.toml"));
const auto the = toml::find(data, "the"); const auto the = toml::find(data, "the");
BOOST_TEST(toml::find<std::string>(the, "test_string") == BOOST_TEST(toml::find<std::string>(the, "test_string") ==
"You'll hate me after this - #"); "You'll hate me after this - #");
@@ -287,7 +283,7 @@ BOOST_AUTO_TEST_CASE(test_hard_example_comment)
BOOST_AUTO_TEST_CASE(test_example_preserve_comment) BOOST_AUTO_TEST_CASE(test_example_preserve_comment)
{ {
const auto data = toml::parse<toml::preserve_comments>("toml/tests/example.toml"); const auto data = toml::parse<toml::preserve_comments>(testinput("example.toml"));
BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example"); BOOST_TEST(toml::find<std::string>(data, "title") == "TOML Example");
const auto& owner = toml::find(data, "owner"); const auto& owner = toml::find(data, "owner");
@@ -369,8 +365,8 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_comment)
BOOST_AUTO_TEST_CASE(test_example_preserve_stdmap_stddeque) BOOST_AUTO_TEST_CASE(test_example_preserve_stdmap_stddeque)
{ {
const auto data = toml::parse<toml::preserve_comments, std::map, std::deque const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>(
>("toml/tests/example.toml"); testinput("example.toml"));
static_assert(std::is_same<typename decltype(data)::table_type, static_assert(std::is_same<typename decltype(data)::table_type,
std::map<toml::key, typename std::remove_cv<decltype(data)>::type> std::map<toml::key, typename std::remove_cv<decltype(data)>::type>
@@ -993,40 +989,18 @@ BOOST_AUTO_TEST_CASE(test_file_ends_without_lf)
BOOST_AUTO_TEST_CASE(test_parse_function_compiles) BOOST_AUTO_TEST_CASE(test_parse_function_compiles)
{ {
// toml::parse(""); using result_type = decltype(toml::parse("string literal"));
const auto string_literal = toml::parse("toml/tests/example.toml"); (void) [](const char* that) -> result_type { return toml::parse(that); };
(void) [](char* that) -> result_type { return toml::parse(that); };
BOOST_TEST_MESSAGE("string_literal"); (void) [](const std::string& that) -> result_type { return toml::parse(that); };
(void) [](std::string& that) -> result_type { return toml::parse(that); };
const char* fname_cstring = "toml/tests/example.toml"; (void) [](std::string&& that) -> result_type { return toml::parse(that); };
// toml::parse(const char*);
const auto cstring = toml::parse(fname_cstring);
BOOST_TEST_MESSAGE("const char*");
// toml::parse(char*);
std::array<char, 24> fname_char_ptr;
std::strncpy(fname_char_ptr.data(), fname_cstring, 24);
const auto char_ptr = toml::parse(fname_char_ptr.data());
BOOST_TEST_MESSAGE("char*");
// toml::parse(const std::string&);
const std::string fname_string("toml/tests/example.toml");
const auto string = toml::parse(fname_string);
std::string fname_string_mut("toml/tests/example.toml");
// toml::parse(std::string&);
const auto string_mutref = toml::parse(fname_string_mut);
// toml::parse(std::string&&);
const auto string_rref = toml::parse(std::move(fname_string_mut));
BOOST_TEST_MESSAGE("strings");
#ifdef TOML11_HAS_STD_FILESYSTEM #ifdef TOML11_HAS_STD_FILESYSTEM
const std::filesystem::path fname_path(fname_string.begin(), fname_string.end()); (void) [](const std::filesystem::path& that) -> result_type { return toml::parse(that); };
const auto filesystem_path = toml::parse(fname_path); (void) [](std::filesystem::path& that) -> result_type { return toml::parse(that); };
BOOST_TEST_MESSAGE("path"); (void) [](std::filesystem::path&& that) -> result_type { return toml::parse(that); };
#endif #endif
(void) [](std::FILE* that) -> result_type { return toml::parse(that, "mandatory.toml"); };
} }
BOOST_AUTO_TEST_CASE(test_parse_nonexistent_file) BOOST_AUTO_TEST_CASE(test_parse_nonexistent_file)

View File

@@ -1,14 +1,10 @@
#define BOOST_TEST_MODULE "parse_floating_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp> #include <toml/parser.hpp>
#include <cmath>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
#include <cmath>
using namespace toml; using namespace toml;
using namespace detail; using namespace detail;

View File

@@ -1,11 +1,6 @@
#define BOOST_TEST_MODULE "parse_inline_table_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp> #include <toml/parser.hpp>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,11 +1,6 @@
#define BOOST_TEST_MODULE "parse_integer_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp> #include <toml/parser.hpp>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,11 +1,6 @@
#define BOOST_TEST_MODULE "parse_key_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp> #include <toml/parser.hpp>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,11 +1,6 @@
#define BOOST_TEST_MODULE "parse_string_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp> #include <toml/parser.hpp>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,12 +1,7 @@
#define BOOST_TEST_MODULE "parse_table_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp>
#include <toml/get.hpp> #include <toml/get.hpp>
#include <toml/parser.hpp>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,11 +1,6 @@
#define BOOST_TEST_MODULE "parse_table_key_test"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/parser.hpp> #include <toml/parser.hpp>
#include "unit_test.hpp"
#include "test_parse_aux.hpp" #include "test_parse_aux.hpp"
using namespace toml; using namespace toml;

View File

@@ -1,17 +1,13 @@
#define BOOST_TEST_MODULE "test_parse_unicode"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include <iostream>
#include "unit_test.hpp"
#include <fstream> #include <fstream>
#include <iostream>
BOOST_AUTO_TEST_CASE(test_hard_example_unicode) BOOST_AUTO_TEST_CASE(test_hard_example_unicode)
{ {
const auto data = toml::parse("toml/tests/hard_example_unicode.toml"); const auto data = toml::parse(testinput("hard_example_unicode.toml"));
const auto the = toml::find<toml::table>(data, "the"); const auto the = toml::find<toml::table>(data, "the");
BOOST_TEST(toml::get<std::string>(the.at("test_string")) == BOOST_TEST(toml::get<std::string>(the.at("test_string")) ==

View File

@@ -1,8 +1,9 @@
#define BOOST_TEST_MODULE "test_result"
#include <boost/test/unit_test.hpp>
#include <iostream>
#include <toml/result.hpp> #include <toml/result.hpp>
#include "unit_test.hpp"
#include <iostream>
BOOST_AUTO_TEST_CASE(test_construct) BOOST_AUTO_TEST_CASE(test_construct)
{ {
{ {
@@ -437,5 +438,3 @@ BOOST_AUTO_TEST_CASE(test_and_or_other)
BOOST_TEST("foo" == r1_gen().and_other(r2_gen()).unwrap_err()); BOOST_TEST("foo" == r1_gen().and_other(r2_gen()).unwrap_err());
} }
} }

View File

@@ -1,15 +1,11 @@
#define BOOST_TEST_MODULE "test_serialize_file"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include "unit_test.hpp"
#include <deque> #include <deque>
#include <map>
#include <iostream>
#include <fstream> #include <fstream>
#include <iostream>
#include <map>
#include <sstream> #include <sstream>
template<typename Comment, template<typename Comment,
@@ -47,7 +43,7 @@ bool has_comment_inside(const toml::basic_value<Comment, Table, Array>& v)
BOOST_AUTO_TEST_CASE(test_example) BOOST_AUTO_TEST_CASE(test_example)
{ {
const auto data = toml::parse("toml/tests/example.toml"); const auto data = toml::parse(testinput("example.toml"));
{ {
std::ofstream ofs("tmp1.toml"); std::ofstream ofs("tmp1.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -69,7 +65,7 @@ BOOST_AUTO_TEST_CASE(test_example)
BOOST_AUTO_TEST_CASE(test_example_map_dq) BOOST_AUTO_TEST_CASE(test_example_map_dq)
{ {
const auto data = toml::parse<toml::discard_comments, std::map, std::deque>( const auto data = toml::parse<toml::discard_comments, std::map, std::deque>(
"toml/tests/example.toml"); testinput("example.toml"));
{ {
std::ofstream ofs("tmp1_map_dq.toml"); std::ofstream ofs("tmp1_map_dq.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -91,7 +87,7 @@ BOOST_AUTO_TEST_CASE(test_example_map_dq)
BOOST_AUTO_TEST_CASE(test_example_with_comment) BOOST_AUTO_TEST_CASE(test_example_with_comment)
{ {
const auto data = toml::parse<toml::preserve_comments>("toml/tests/example.toml"); const auto data = toml::parse<toml::preserve_comments>(testinput("example.toml"));
{ {
std::ofstream ofs("tmp1_com.toml"); std::ofstream ofs("tmp1_com.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -117,7 +113,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment)
BOOST_AUTO_TEST_CASE(test_example_with_comment_nocomment) BOOST_AUTO_TEST_CASE(test_example_with_comment_nocomment)
{ {
{ {
const auto data = toml::parse<toml::preserve_comments>("toml/tests/example.toml"); const auto data = toml::parse<toml::preserve_comments>(testinput("example.toml"));
{ {
std::ofstream ofs("tmp1_com_nocomment.toml"); std::ofstream ofs("tmp1_com_nocomment.toml");
ofs << std::setw(80) << toml::nocomment << data; ofs << std::setw(80) << toml::nocomment << data;
@@ -127,7 +123,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_nocomment)
BOOST_TEST(!has_comment_inside(serialized)); BOOST_TEST(!has_comment_inside(serialized));
} }
{ {
const auto data_nocomment = toml::parse<toml::discard_comments>("toml/tests/example.toml"); const auto data_nocomment = toml::parse<toml::discard_comments>(testinput("example.toml"));
auto serialized = toml::parse<toml::discard_comments>("tmp1_com_nocomment.toml"); auto serialized = toml::parse<toml::discard_comments>("tmp1_com_nocomment.toml");
{ {
auto& owner = toml::find(serialized, "owner"); auto& owner = toml::find(serialized, "owner");
@@ -146,7 +142,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_nocomment)
BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq) BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq)
{ {
const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>( const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>(
"toml/tests/example.toml"); testinput("example.toml"));
{ {
std::ofstream ofs("tmp1_com_map_dq.toml"); std::ofstream ofs("tmp1_com_map_dq.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -173,7 +169,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq)
BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq_nocomment) BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq_nocomment)
{ {
{ {
const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>("toml/tests/example.toml"); const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>(testinput("example.toml"));
{ {
std::ofstream ofs("tmp1_com_map_dq_nocomment.toml"); std::ofstream ofs("tmp1_com_map_dq_nocomment.toml");
ofs << std::setw(80) << toml::nocomment << data; ofs << std::setw(80) << toml::nocomment << data;
@@ -182,7 +178,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq_nocomment)
BOOST_TEST(!has_comment_inside(serialized)); BOOST_TEST(!has_comment_inside(serialized));
} }
{ {
const auto data_nocomment = toml::parse<toml::discard_comments>("toml/tests/example.toml"); const auto data_nocomment = toml::parse<toml::discard_comments>(testinput("example.toml"));
auto serialized = toml::parse<toml::discard_comments>("tmp1_com_map_dq_nocomment.toml"); auto serialized = toml::parse<toml::discard_comments>("tmp1_com_map_dq_nocomment.toml");
{ {
auto& owner = toml::find(serialized, "owner"); auto& owner = toml::find(serialized, "owner");
@@ -199,7 +195,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq_nocomment)
BOOST_AUTO_TEST_CASE(test_fruit) BOOST_AUTO_TEST_CASE(test_fruit)
{ {
const auto data = toml::parse("toml/tests/fruit.toml"); const auto data = toml::parse(testinput("fruit.toml"));
{ {
std::ofstream ofs("tmp2.toml"); std::ofstream ofs("tmp2.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -211,7 +207,7 @@ BOOST_AUTO_TEST_CASE(test_fruit)
BOOST_AUTO_TEST_CASE(test_fruit_map_dq) BOOST_AUTO_TEST_CASE(test_fruit_map_dq)
{ {
const auto data = toml::parse<toml::discard_comments, std::map, std::deque>( const auto data = toml::parse<toml::discard_comments, std::map, std::deque>(
"toml/tests/fruit.toml"); testinput("fruit.toml"));
{ {
std::ofstream ofs("tmp2.toml"); std::ofstream ofs("tmp2.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -223,7 +219,7 @@ BOOST_AUTO_TEST_CASE(test_fruit_map_dq)
BOOST_AUTO_TEST_CASE(test_fruit_with_comments) BOOST_AUTO_TEST_CASE(test_fruit_with_comments)
{ {
const auto data = toml::parse<toml::preserve_comments>("toml/tests/fruit.toml"); const auto data = toml::parse<toml::preserve_comments>(testinput("fruit.toml"));
{ {
std::ofstream ofs("tmp2_com.toml"); std::ofstream ofs("tmp2_com.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -235,7 +231,7 @@ BOOST_AUTO_TEST_CASE(test_fruit_with_comments)
BOOST_AUTO_TEST_CASE(test_fruit_with_comments_map_dq) BOOST_AUTO_TEST_CASE(test_fruit_with_comments_map_dq)
{ {
const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>( const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>(
"toml/tests/fruit.toml"); testinput("fruit.toml"));
{ {
std::ofstream ofs("tmp2_com.toml"); std::ofstream ofs("tmp2_com.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -246,7 +242,7 @@ BOOST_AUTO_TEST_CASE(test_fruit_with_comments_map_dq)
BOOST_AUTO_TEST_CASE(test_hard_example) BOOST_AUTO_TEST_CASE(test_hard_example)
{ {
const auto data = toml::parse("toml/tests/hard_example.toml"); const auto data = toml::parse(testinput("hard_example.toml"));
{ {
std::ofstream ofs("tmp3.toml"); std::ofstream ofs("tmp3.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -258,7 +254,7 @@ BOOST_AUTO_TEST_CASE(test_hard_example)
BOOST_AUTO_TEST_CASE(test_hard_example_map_dq) BOOST_AUTO_TEST_CASE(test_hard_example_map_dq)
{ {
const auto data = toml::parse<toml::discard_comments, std::map, std::deque>( const auto data = toml::parse<toml::discard_comments, std::map, std::deque>(
"toml/tests/hard_example.toml"); testinput("hard_example.toml"));
{ {
std::ofstream ofs("tmp3.toml"); std::ofstream ofs("tmp3.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;
@@ -271,7 +267,7 @@ BOOST_AUTO_TEST_CASE(test_hard_example_map_dq)
BOOST_AUTO_TEST_CASE(test_hard_example_with_comment) BOOST_AUTO_TEST_CASE(test_hard_example_with_comment)
{ {
const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>( const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>(
"toml/tests/hard_example.toml"); testinput("hard_example.toml"));
{ {
std::ofstream ofs("tmp3_com.toml"); std::ofstream ofs("tmp3_com.toml");
ofs << std::setw(80) << data; ofs << std::setw(80) << data;

View File

@@ -1,7 +1,7 @@
#define BOOST_TEST_MODULE "test_string"
#include <boost/test/unit_test.hpp>
#include <toml.hpp> #include <toml.hpp>
#include "unit_test.hpp"
BOOST_AUTO_TEST_CASE(test_basic_string) BOOST_AUTO_TEST_CASE(test_basic_string)
{ {
{ {
@@ -151,4 +151,3 @@ BOOST_AUTO_TEST_CASE(test_string_add_assign)
} }

View File

@@ -1,21 +1,16 @@
#define BOOST_TEST_MODULE "test_traits"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/types.hpp> #include <toml/types.hpp>
#include <list> #include "unit_test.hpp"
#include <forward_list>
#include <deque>
#include <array> #include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map> #include <map>
#include <set> #include <set>
#include <string>
#include <unordered_map> #include <unordered_map>
#include <unordered_set> #include <unordered_set>
#include <string>
struct dummy_type{}; struct dummy_type{};

View File

@@ -1,13 +1,9 @@
#define BOOST_TEST_MODULE "test_acceptor"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml/utility.hpp> #include <toml/utility.hpp>
#include <vector>
#include "unit_test.hpp"
#include <array> #include <array>
#include <vector>
BOOST_AUTO_TEST_CASE(test_try_reserve) BOOST_AUTO_TEST_CASE(test_try_reserve)
{ {

View File

@@ -1,11 +1,7 @@
#define BOOST_TEST_MODULE "test_value"
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
#include <boost/test/unit_test.hpp>
#else
#define BOOST_TEST_NO_LIB
#include <boost/test/included/unit_test.hpp>
#endif
#include <toml.hpp> #include <toml.hpp>
#include "unit_test.hpp"
#include <map> #include <map>
#include <list> #include <list>

23
tests/unit_test.hpp Normal file
View File

@@ -0,0 +1,23 @@
#ifndef BOOST_TEST_MODULE
# error "Please #define BOOST_TEST_MODULE before you #include <unit_test.hpp>"
#endif
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
# include <boost/test/unit_test.hpp>
#else
# include <boost/test/included/unit_test.hpp>
#endif
#include <cstdlib>
#include <string>
static inline auto testinput(const std::string& basename) -> std::string
{
const auto this_or_that = [](const char *const s, const char *const t) { return s ? s : t; };
std::string directory = this_or_that(std::getenv("TOMLDIR"), "toml");
if (!directory.empty() && directory.back() != '/')
{
directory.push_back('/');
}
return directory.append("tests/").append(basename);
}

View File

@@ -425,14 +425,14 @@ struct discard_comments
// empty, so accessing through operator[], front/back, data causes address // empty, so accessing through operator[], front/back, data causes address
// error. // error.
reference operator[](const size_type) noexcept {return *data();} reference operator[](const size_type) noexcept {never_call("toml::discard_comment::operator[]");}
const_reference operator[](const size_type) const noexcept {return *data();} const_reference operator[](const size_type) const noexcept {never_call("toml::discard_comment::operator[]");}
reference at(const size_type) {throw std::out_of_range("toml::discard_comment is always empty.");} reference at(const size_type) {throw std::out_of_range("toml::discard_comment is always empty.");}
const_reference at(const size_type) const {throw std::out_of_range("toml::discard_comment is always empty.");} const_reference at(const size_type) const {throw std::out_of_range("toml::discard_comment is always empty.");}
reference front() noexcept {return *data();} reference front() noexcept {never_call("toml::discard_comment::front");}
const_reference front() const noexcept {return *data();} const_reference front() const noexcept {never_call("toml::discard_comment::front");}
reference back() noexcept {return *data();} reference back() noexcept {never_call("toml::discard_comment::back");}
const_reference back() const noexcept {return *data();} const_reference back() const noexcept {never_call("toml::discard_comment::back");}
pointer data() noexcept {return nullptr;} pointer data() noexcept {return nullptr;}
const_pointer data() const noexcept {return nullptr;} const_pointer data() const noexcept {return nullptr;}
@@ -450,6 +450,18 @@ struct discard_comments
const_reverse_iterator rend() const noexcept {return const_iterator{};} const_reverse_iterator rend() const noexcept {return const_iterator{};}
const_reverse_iterator crbegin() const noexcept {return const_iterator{};} const_reverse_iterator crbegin() const noexcept {return const_iterator{};}
const_reverse_iterator crend() const noexcept {return const_iterator{};} const_reverse_iterator crend() const noexcept {return const_iterator{};}
private:
[[noreturn]] static void never_call(const char *const this_function)
{
#ifdef __has_builtin
# if __has_builtin(__builtin_unreachable)
__builtin_unreachable();
# endif
#endif
throw std::logic_error{this_function};
}
}; };
inline bool operator==(const discard_comments&, const discard_comments&) noexcept {return true;} inline bool operator==(const discard_comments&, const discard_comments&) noexcept {return true;}

View File

@@ -85,9 +85,9 @@ enum class month_t : std::uint8_t
struct local_date struct local_date
{ {
std::int16_t year; // A.D. (like, 2018) std::int16_t year{}; // A.D. (like, 2018)
std::uint8_t month; // [0, 11] std::uint8_t month{}; // [0, 11]
std::uint8_t day; // [1, 31] std::uint8_t day{}; // [1, 31]
local_date(int y, month_t m, int d) local_date(int y, month_t m, int d)
: year (static_cast<std::int16_t>(y)), : year (static_cast<std::int16_t>(y)),
@@ -181,12 +181,12 @@ operator<<(std::basic_ostream<charT, traits>& os, const local_date& date)
struct local_time struct local_time
{ {
std::uint8_t hour; // [0, 23] std::uint8_t hour{}; // [0, 23]
std::uint8_t minute; // [0, 59] std::uint8_t minute{}; // [0, 59]
std::uint8_t second; // [0, 60] std::uint8_t second{}; // [0, 60]
std::uint16_t millisecond; // [0, 999] std::uint16_t millisecond{}; // [0, 999]
std::uint16_t microsecond; // [0, 999] std::uint16_t microsecond{}; // [0, 999]
std::uint16_t nanosecond; // [0, 999] std::uint16_t nanosecond{}; // [0, 999]
local_time(int h, int m, int s, local_time(int h, int m, int s,
int ms = 0, int us = 0, int ns = 0) int ms = 0, int us = 0, int ns = 0)
@@ -297,8 +297,8 @@ operator<<(std::basic_ostream<charT, traits>& os, const local_time& time)
struct time_offset struct time_offset
{ {
std::int8_t hour; // [-12, 12] std::int8_t hour{}; // [-12, 12]
std::int8_t minute; // [-59, 59] std::int8_t minute{}; // [-59, 59]
time_offset(int h, int m) time_offset(int h, int m)
: hour (static_cast<std::int8_t>(h)), : hour (static_cast<std::int8_t>(h)),
@@ -364,8 +364,8 @@ operator<<(std::basic_ostream<charT, traits>& os, const time_offset& offset)
struct local_datetime struct local_datetime
{ {
local_date date; local_date date{};
local_time time; local_time time{};
local_datetime(local_date d, local_time t): date(d), time(t) {} local_datetime(local_date d, local_time t): date(d), time(t) {}
@@ -478,9 +478,9 @@ operator<<(std::basic_ostream<charT, traits>& os, const local_datetime& dt)
struct offset_datetime struct offset_datetime
{ {
local_date date; local_date date{};
local_time time; local_time time{};
time_offset offset; time_offset offset{};
offset_datetime(local_date d, local_time t, time_offset o) offset_datetime(local_date d, local_time t, time_offset o)
: date(d), time(t), offset(o) : date(d), time(t), offset(o)

View File

@@ -2414,12 +2414,14 @@ parse(std::vector<char>& letters, const std::string& fname)
} }
} }
const auto data = detail::parse_toml_file<value_type>(loc); if (auto data = detail::parse_toml_file<value_type>(loc))
if(!data)
{ {
throw syntax_error(data.unwrap_err(), source_location(loc)); return std::move(data).unwrap();
}
else
{
throw syntax_error(std::move(data).unwrap_err(), source_location(loc));
} }
return data.unwrap();
} }
} // detail } // detail

View File

@@ -227,8 +227,7 @@ struct region final : public region_base
region& operator+=(const region& other) region& operator+=(const region& other)
{ {
// different regions cannot be concatenated // different regions cannot be concatenated
assert(this->begin() == other.begin() && this->end() == other.end() && assert(this->source_ == other.source_ && this->last_ == other.first_);
this->last_ == other.first_);
this->last_ = other.last_; this->last_ = other.last_;
return *this; return *this;