mirror of
https://github.com/ToruNiina/toml11.git
synced 2025-01-09 17:10:10 +00:00
fe471bcbe9
The conditional inclusion of either the library or the header-only version of the Boost.Test header wasn't tremendously useful in practice because the tests/CMakeLists.txt file would unconditionally add compile definitions to basically fore dynamic linking. This patch adds feature detection to the tests/CMakeLists.txt file to determine whether to use dynamic linking, static linking or the header-only version (in that order of preference, for best performance). The automatic detection could be overridden if needed by defining the TOML11_WITH_BOOST_TEST_{HEADER,STATIC,DYNAMIC} variables on the CMake command line. While we are at it, instead of having a conditional #define BOOST_TEST_NO_LIB in each unit test file, handle this once in the CMakeLists.txt file.
76 lines
2.3 KiB
C++
76 lines
2.3 KiB
C++
#define BOOST_TEST_MODULE "test_format_error"
|
|
#ifdef UNITTEST_FRAMEWORK_LIBRARY_EXIST
|
|
#include <boost/test/unit_test.hpp>
|
|
#else
|
|
#include <boost/test/included/unit_test.hpp>
|
|
#endif
|
|
#include <toml.hpp>
|
|
#include <iostream>
|
|
|
|
// to check it successfully compiles. it does not check the formatted string.
|
|
|
|
BOOST_AUTO_TEST_CASE(test_1_value)
|
|
{
|
|
toml::value val(42);
|
|
|
|
{
|
|
const std::string pretty_error =
|
|
toml::format_error("[error] test error", val, "this is a value");
|
|
std::cout << pretty_error << std::endl;
|
|
}
|
|
|
|
{
|
|
const std::string pretty_error =
|
|
toml::format_error("[error] test error", val, "this is a value",
|
|
{"this is a hint"});
|
|
std::cout << pretty_error << std::endl;
|
|
}
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_2_values)
|
|
{
|
|
toml::value v1(42);
|
|
toml::value v2(3.14);
|
|
{
|
|
const std::string pretty_error =
|
|
toml::format_error("[error] test error with two values",
|
|
v1, "this is the answer",
|
|
v2, "this is the pi");
|
|
std::cout << pretty_error << std::endl;
|
|
}
|
|
|
|
{
|
|
const std::string pretty_error =
|
|
toml::format_error("[error] test error with two values",
|
|
v1, "this is the answer",
|
|
v2, "this is the pi",
|
|
{"hint"});
|
|
std::cout << pretty_error << std::endl;
|
|
}
|
|
}
|
|
|
|
BOOST_AUTO_TEST_CASE(test_3_values)
|
|
{
|
|
toml::value v1(42);
|
|
toml::value v2(3.14);
|
|
toml::value v3("foo");
|
|
{
|
|
const std::string pretty_error =
|
|
toml::format_error("[error] test error with two values",
|
|
v1, "this is the answer",
|
|
v2, "this is the pi",
|
|
v3, "this is a meta-syntactic variable");
|
|
std::cout << pretty_error << std::endl;
|
|
}
|
|
|
|
{
|
|
const std::string pretty_error =
|
|
toml::format_error("[error] test error with two values",
|
|
v1, "this is the answer",
|
|
v2, "this is the pi",
|
|
v3, "this is a meta-syntactic variable",
|
|
{"hint 1", "hint 2"});
|
|
std::cout << pretty_error << std::endl;
|
|
}
|
|
}
|