[yul-phaser] TestHelpers: Generic operator << for printing tuples in boost tests

This commit is contained in:
Kamil Śliwak 2020-03-19 17:08:53 +01:00
parent 806c835647
commit 2750bb9b90

View File

@ -33,12 +33,39 @@
#include <tools/yulPhaser/Mutations.h>
#include <tools/yulPhaser/Population.h>
#include <boost/test/tools/detail/print_helper.hpp>
#include <cassert>
#include <functional>
#include <map>
#include <string>
#include <tuple>
#include <vector>
// OPERATORS FOR BOOST::TEST
/// Output operator for arbitrary two-element tuples.
/// Necessary to make BOOST_TEST() work with such tuples.
template<typename T1, typename T2>
std::ostream& operator<<(std::ostream& _output, std::tuple<T1, T2> const& _tuple)
{
_output << "(" << std::get<0>(_tuple) << ", " << std::get<1>(_tuple) << ")";
return _output;
}
namespace boost::test_tools::tt_detail
{
// Boost won't find find the << operator unless we put it in the std namespace which is illegal.
// The recommended solution is to overload print_log_value<> struct and make it use our global operator.
template<typename T1,typename T2>
struct print_log_value<std::tuple<T1, T2>>
{
void operator()(std::ostream& _output, std::tuple<T1, T2> const& _tuple) { ::operator<<(_output, _tuple); }
};
}
namespace solidity::phaser::test
{