Add test helper to use std::optional via CPPUNIT_ASSERT_EQUAL
This commit is contained in:
parent
c1152ca062
commit
7555e6854b
|
@ -114,8 +114,8 @@ set(META_APP_AUTHOR "Martchus")
|
|||
set(META_APP_URL "https://github.com/${META_APP_AUTHOR}/${META_PROJECT_NAME}")
|
||||
set(META_APP_DESCRIPTION "Useful C++ classes and routines such as argument parser, IO and conversion utilities")
|
||||
set(META_VERSION_MAJOR 5)
|
||||
set(META_VERSION_MINOR 14)
|
||||
set(META_VERSION_PATCH 1)
|
||||
set(META_VERSION_MINOR 15)
|
||||
set(META_VERSION_PATCH 0)
|
||||
|
||||
# find required 3rd party libraries
|
||||
include(3rdParty)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "../misc/traits.h"
|
||||
|
||||
#include <iomanip>
|
||||
#include <optional>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
|
@ -196,6 +197,19 @@ CPP_UTILITIES_EXPORT int execHelperAppInSearchPath(
|
|||
const char *appName, const char *const *args, std::string &output, std::string &errors, bool suppressLogging = false, int timeout = -1);
|
||||
#endif // PLATFORM_UNIX
|
||||
|
||||
/*!
|
||||
* \brief Allows printing std::optional objects so those can be asserted using CPPUNIT_ASSERT_EQUAL.
|
||||
*/
|
||||
template <typename Optional, Traits::EnableIf<Traits::IsSpecializationOf<Optional, std::optional>> * = nullptr>
|
||||
inline std::ostream &operator<<(std::ostream &out, const Optional &optional)
|
||||
{
|
||||
if (optional.has_value()) {
|
||||
return out << *optional;
|
||||
} else {
|
||||
return out << "[no value]";
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief The AsHexNumber class allows printing values asserted with cppunit (or similar test framework) using the
|
||||
* hex system in the error case.
|
||||
|
|
Loading…
Reference in New Issue