mirror of
https://github.com/ToruNiina/toml11.git
synced 2024-11-08 13:50:06 +00:00
use FetchContent to retrieve TOML test data
This commit is contained in:
parent
ac1130f9f4
commit
4c34986db0
@ -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
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
|
||||
|
9
dependencies/CMakeLists.txt
vendored
Normal file
9
dependencies/CMakeLists.txt
vendored
Normal file
@ -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 ()
|
@ -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")
|
||||
|
26
tests/include/toml11/test/files.hpp.in
Normal file
26
tests/include/toml11/test/files.hpp.in
Normal file
@ -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
|
@ -10,10 +10,11 @@
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <deque>
|
||||
#include <toml11/test/files.hpp>
|
||||
|
||||
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<std::string>(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<std::string>(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::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(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<std::string>(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::preserve_comments>("toml/tests/hard_example.toml");
|
||||
const auto data = toml::parse<toml::preserve_comments>(toml::test::file::hard_example);
|
||||
const auto the = toml::find(data, "the");
|
||||
BOOST_TEST(toml::find<std::string>(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::preserve_comments>("toml/tests/example.toml");
|
||||
const auto data = toml::parse<toml::preserve_comments>(toml::test::file::example);
|
||||
|
||||
BOOST_TEST(toml::find<std::string>(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::preserve_comments, std::map, std::deque
|
||||
>("toml/tests/example.toml");
|
||||
>(toml::test::file::example);
|
||||
|
||||
static_assert(std::is_same<typename decltype(data)::table_type,
|
||||
std::map<toml::key, typename std::remove_cv<decltype(data)>::type>
|
||||
|
@ -8,11 +8,12 @@
|
||||
#include <toml.hpp>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <toml11/test/files.hpp>
|
||||
|
||||
#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<toml::table>(data, "the");
|
||||
BOOST_TEST(toml::get<std::string>(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<toml::table>(data, "the");
|
||||
BOOST_TEST(toml::get<std::string>(the.at("test_string")) ==
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include <map>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <toml11/test/files.hpp>
|
||||
|
||||
template<typename Comment,
|
||||
template<typename ...> class Table,
|
||||
@ -46,7 +47,7 @@ bool has_comment_inside(const toml::basic_value<Comment, Table, Array>& 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::discard_comments, std::map, std::deque>(
|
||||
"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::preserve_comments>("toml/tests/example.toml");
|
||||
const auto data = toml::parse<toml::preserve_comments>(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::preserve_comments>("toml/tests/example.toml");
|
||||
const auto data = toml::parse<toml::preserve_comments>(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::preserve_comments, std::map, std::deque>(
|
||||
"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::preserve_comments, std::map, std::deque>("toml/tests/example.toml");
|
||||
const auto data = toml::parse<toml::preserve_comments, std::map, std::deque>(
|
||||
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::discard_comments, std::map, std::deque>(
|
||||
"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::preserve_comments>("toml/tests/fruit.toml");
|
||||
const auto data = toml::parse<toml::preserve_comments>(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::preserve_comments, std::map, std::deque>(
|
||||
"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::discard_comments, std::map, std::deque>(
|
||||
"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::preserve_comments, std::map, std::deque>(
|
||||
"toml/tests/hard_example.toml");
|
||||
toml::test::file::hard_example);
|
||||
{
|
||||
std::ofstream ofs("tmp3_com.toml");
|
||||
ofs << std::setw(80) << data;
|
||||
|
Loading…
Reference in New Issue
Block a user