diff --git a/CMakeLists.txt b/CMakeLists.txt index aafa018..8215502 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.8) +cmake_minimum_required(VERSION 3.11) enable_testing() project(toml11) @@ -52,6 +52,8 @@ set(toml11_config_dir ${CMAKE_CURRENT_BINARY_DIR}/cmake/) set(toml11_config ${toml11_config_dir}/toml11Config.cmake) set(toml11_config_version ${toml11_config_dir}/toml11ConfigVersion.cmake) +add_subdirectory(dependencies) + add_library(toml11 INTERFACE) target_include_directories(toml11 INTERFACE $ diff --git a/dependencies/CMakeLists.txt b/dependencies/CMakeLists.txt new file mode 100644 index 0000000..d909a90 --- /dev/null +++ b/dependencies/CMakeLists.txt @@ -0,0 +1,9 @@ +include(FetchContent) + +if (toml11_BUILD_TEST) + FetchContent_Declare(toml + GIT_REPOSITORY https://github.com/toml-lang/toml + GIT_TAG v0.5.0) + + FetchContent_MakeAvailable(toml) +endif () diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e6a1f5b..a06f706 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,3 +1,10 @@ +include(FetchContent) +FetchContent_GetProperties(toml) +configure_file(include/toml11/test/files.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/include/toml11/test/files.hpp @ONLY) +add_library(toml11_test_files INTERFACE) +add_library(toml11::test_files ALIAS toml11_test_files) +target_include_directories(toml11_test_files INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/include) + set(TEST_NAMES test_datetime test_string @@ -143,7 +150,7 @@ add_definitions(-DUNITTEST_FRAMEWORK_LIBRARY_EXIST) foreach(TEST_NAME ${TEST_NAMES}) 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 toml11::test_files) target_include_directories(${TEST_NAME} PRIVATE ${Boost_INCLUDE_DIRS}) if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang") diff --git a/tests/include/toml11/test/files.hpp.in b/tests/include/toml11/test/files.hpp.in new file mode 100644 index 0000000..f4603ed --- /dev/null +++ b/tests/include/toml11/test/files.hpp.in @@ -0,0 +1,26 @@ +// Copyright Toru Niina 2020. +// Distributed under the MIT License. +#ifndef TOML11_TEST_PATHS_HPP +#define TOML11_TEST_PATHS_HPP + +namespace toml { + +namespace test { + +namespace file { + +constexpr char example[]{"@toml_SOURCE_DIR@/tests/example.toml"}; + +constexpr char fruit[]{"@toml_SOURCE_DIR@/tests/fruit.toml"}; + +constexpr char hard_example[]{"@toml_SOURCE_DIR@/tests/hard_example.toml"}; + +constexpr char hard_example_unicode[]{"@toml_SOURCE_DIR@/tests/hard_example_unicode.toml"}; + +} + +} + +} // toml + +#endif// TOML11_TEST_PATHS_HPP diff --git a/tests/test_parse_file.cpp b/tests/test_parse_file.cpp index 7a3dc8f..da41dbd 100644 --- a/tests/test_parse_file.cpp +++ b/tests/test_parse_file.cpp @@ -10,10 +10,11 @@ #include #include #include +#include BOOST_AUTO_TEST_CASE(test_example) { - const auto data = toml::parse("toml/tests/example.toml"); + const auto data = toml::parse(toml::test::file::example); BOOST_TEST(toml::find(data, "title") == "TOML Example"); const auto& owner = toml::find(data, "owner"); @@ -76,7 +77,7 @@ BOOST_AUTO_TEST_CASE(test_example) BOOST_AUTO_TEST_CASE(test_example_stream) { - std::ifstream ifs("toml/tests/example.toml"); + std::ifstream ifs(toml::test::file::example); const auto data = toml::parse(ifs); BOOST_TEST(toml::find(data, "title") == "TOML Example"); @@ -144,7 +145,7 @@ BOOST_AUTO_TEST_CASE(test_example_stream) BOOST_AUTO_TEST_CASE(test_fruit) { - const auto data = toml::parse("toml/tests/fruit.toml"); + const auto data = toml::parse(toml::test::file::fruit); const auto blah = toml::find(toml::find(data, "fruit"), "blah"); BOOST_TEST(toml::find(blah.at(0), "name") == "apple"); BOOST_TEST(toml::find(blah.at(1), "name") == "banana"); @@ -162,7 +163,7 @@ BOOST_AUTO_TEST_CASE(test_fruit) BOOST_AUTO_TEST_CASE(test_hard_example) { - const auto data = toml::parse("toml/tests/hard_example.toml"); + const auto data = toml::parse(toml::test::file::hard_example); const auto the = toml::find(data, "the"); BOOST_TEST(toml::find(the, "test_string") == "You'll hate me after this - #"); @@ -189,7 +190,7 @@ BOOST_AUTO_TEST_CASE(test_hard_example) } BOOST_AUTO_TEST_CASE(test_hard_example_comment) { - const auto data = toml::parse("toml/tests/hard_example.toml"); + const auto data = toml::parse(toml::test::file::hard_example); const auto the = toml::find(data, "the"); BOOST_TEST(toml::find(the, "test_string") == "You'll hate me after this - #"); @@ -218,7 +219,7 @@ BOOST_AUTO_TEST_CASE(test_hard_example_comment) BOOST_AUTO_TEST_CASE(test_example_preserve_comment) { - const auto data = toml::parse("toml/tests/example.toml"); + const auto data = toml::parse(toml::test::file::example); BOOST_TEST(toml::find(data, "title") == "TOML Example"); const auto& owner = toml::find(data, "owner"); @@ -301,7 +302,7 @@ BOOST_AUTO_TEST_CASE(test_example_preserve_comment) BOOST_AUTO_TEST_CASE(test_example_preserve_stdmap_stddeque) { const auto data = toml::parse("toml/tests/example.toml"); + >(toml::test::file::example); static_assert(std::is_same::type> diff --git a/tests/test_parse_unicode.cpp b/tests/test_parse_unicode.cpp index dbfe601..d9a4117 100644 --- a/tests/test_parse_unicode.cpp +++ b/tests/test_parse_unicode.cpp @@ -8,11 +8,12 @@ #include #include #include +#include #if defined(_MSC_VER) || defined(__INTEL_COMPILER) BOOST_AUTO_TEST_CASE(test_hard_example_unicode) { - const auto data = toml::parse("toml/tests/hard_example_unicode.toml"); + const auto data = toml::parse(toml::test::file::hard_example_unicode); const auto the = toml::find(data, "the"); BOOST_TEST(toml::get(the.at("test_string")) == @@ -43,7 +44,7 @@ BOOST_AUTO_TEST_CASE(test_hard_example_unicode) #else BOOST_AUTO_TEST_CASE(test_hard_example_unicode) { - const auto data = toml::parse("toml/tests/hard_example_unicode.toml"); + const auto data = toml::parse(toml::test::file::hard_example_unicode); const auto the = toml::find(data, "the"); BOOST_TEST(toml::get(the.at("test_string")) == diff --git a/tests/test_serialize_file.cpp b/tests/test_serialize_file.cpp index f7384bb..95fe22f 100644 --- a/tests/test_serialize_file.cpp +++ b/tests/test_serialize_file.cpp @@ -10,6 +10,7 @@ #include #include #include +#include template class Table, @@ -46,7 +47,7 @@ bool has_comment_inside(const toml::basic_value& v) BOOST_AUTO_TEST_CASE(test_example) { - const auto data = toml::parse("toml/tests/example.toml"); + const auto data = toml::parse(toml::test::file::example); { std::ofstream ofs("tmp1.toml"); ofs << std::setw(80) << data; @@ -68,7 +69,7 @@ BOOST_AUTO_TEST_CASE(test_example) BOOST_AUTO_TEST_CASE(test_example_map_dq) { const auto data = toml::parse( - "toml/tests/example.toml"); + toml::test::file::example); { std::ofstream ofs("tmp1_map_dq.toml"); ofs << std::setw(80) << data; @@ -90,7 +91,7 @@ BOOST_AUTO_TEST_CASE(test_example_map_dq) BOOST_AUTO_TEST_CASE(test_example_with_comment) { - const auto data = toml::parse("toml/tests/example.toml"); + const auto data = toml::parse(toml::test::file::example); { std::ofstream ofs("tmp1_com.toml"); ofs << std::setw(80) << data; @@ -116,7 +117,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment) BOOST_AUTO_TEST_CASE(test_example_with_comment_nocomment) { { - const auto data = toml::parse("toml/tests/example.toml"); + const auto data = toml::parse(toml::test::file::example); { std::ofstream ofs("tmp1_com_nocomment.toml"); ofs << std::setw(80) << toml::nocomment << data; @@ -126,7 +127,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_nocomment) BOOST_TEST(!has_comment_inside(serialized)); } { - const auto data_nocomment = toml::parse("toml/tests/example.toml"); + const auto data_nocomment = toml::parse(toml::test::file::example); auto serialized = toml::parse("tmp1_com_nocomment.toml"); { auto& owner = toml::find(serialized, "owner"); @@ -145,7 +146,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_nocomment) BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq) { const auto data = toml::parse( - "toml/tests/example.toml"); + toml::test::file::example); { std::ofstream ofs("tmp1_com_map_dq.toml"); ofs << std::setw(80) << data; @@ -172,7 +173,8 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq) BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq_nocomment) { { - const auto data = toml::parse("toml/tests/example.toml"); + const auto data = toml::parse( + toml::test::file::example); { std::ofstream ofs("tmp1_com_map_dq_nocomment.toml"); ofs << std::setw(80) << toml::nocomment << data; @@ -181,7 +183,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq_nocomment) BOOST_TEST(!has_comment_inside(serialized)); } { - const auto data_nocomment = toml::parse("toml/tests/example.toml"); + const auto data_nocomment = toml::parse(toml::test::file::example); auto serialized = toml::parse("tmp1_com_map_dq_nocomment.toml"); { auto& owner = toml::find(serialized, "owner"); @@ -198,7 +200,7 @@ BOOST_AUTO_TEST_CASE(test_example_with_comment_map_dq_nocomment) BOOST_AUTO_TEST_CASE(test_fruit) { - const auto data = toml::parse("toml/tests/fruit.toml"); + const auto data = toml::parse(toml::test::file::fruit); { std::ofstream ofs("tmp2.toml"); ofs << std::setw(80) << data; @@ -210,7 +212,7 @@ BOOST_AUTO_TEST_CASE(test_fruit) BOOST_AUTO_TEST_CASE(test_fruit_map_dq) { const auto data = toml::parse( - "toml/tests/fruit.toml"); + toml::test::file::fruit); { std::ofstream ofs("tmp2.toml"); ofs << std::setw(80) << data; @@ -222,7 +224,7 @@ BOOST_AUTO_TEST_CASE(test_fruit_map_dq) BOOST_AUTO_TEST_CASE(test_fruit_with_comments) { - const auto data = toml::parse("toml/tests/fruit.toml"); + const auto data = toml::parse(toml::test::file::fruit); { std::ofstream ofs("tmp2_com.toml"); ofs << std::setw(80) << data; @@ -234,7 +236,7 @@ BOOST_AUTO_TEST_CASE(test_fruit_with_comments) BOOST_AUTO_TEST_CASE(test_fruit_with_comments_map_dq) { const auto data = toml::parse( - "toml/tests/fruit.toml"); + toml::test::file::fruit); { std::ofstream ofs("tmp2_com.toml"); ofs << std::setw(80) << data; @@ -245,7 +247,7 @@ BOOST_AUTO_TEST_CASE(test_fruit_with_comments_map_dq) BOOST_AUTO_TEST_CASE(test_hard_example) { - const auto data = toml::parse("toml/tests/hard_example.toml"); + const auto data = toml::parse(toml::test::file::hard_example); { std::ofstream ofs("tmp3.toml"); ofs << std::setw(80) << data; @@ -257,7 +259,7 @@ BOOST_AUTO_TEST_CASE(test_hard_example) BOOST_AUTO_TEST_CASE(test_hard_example_map_dq) { const auto data = toml::parse( - "toml/tests/hard_example.toml"); + toml::test::file::hard_example); { std::ofstream ofs("tmp3.toml"); ofs << std::setw(80) << data; @@ -270,7 +272,7 @@ BOOST_AUTO_TEST_CASE(test_hard_example_map_dq) BOOST_AUTO_TEST_CASE(test_hard_example_with_comment) { const auto data = toml::parse( - "toml/tests/hard_example.toml"); + toml::test::file::hard_example); { std::ofstream ofs("tmp3_com.toml"); ofs << std::setw(80) << data;