mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Removed default error policy keeping only Boost.Test integration
git-svn-id: https://svn.code.sf.net/p/turtle/code/trunk@533 860be788-9bd5-4423-9f1e-828f051e677b
This commit is contained in:
parent
1b3bef3e8c
commit
cd3886aede
9 changed files with 110 additions and 243 deletions
|
|
@ -19,15 +19,12 @@
|
||||||
</ProjectConfiguration>
|
</ProjectConfiguration>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="..\..\turtle\boost_test_error.hpp" />
|
|
||||||
<ClInclude Include="..\..\turtle\config.hpp" />
|
<ClInclude Include="..\..\turtle\config.hpp" />
|
||||||
<ClInclude Include="..\..\turtle\constraint.hpp" />
|
<ClInclude Include="..\..\turtle\constraint.hpp" />
|
||||||
<ClInclude Include="..\..\turtle\constraints.hpp" />
|
<ClInclude Include="..\..\turtle\constraints.hpp" />
|
||||||
<ClInclude Include="..\..\turtle\default_error.hpp" />
|
|
||||||
<ClInclude Include="..\..\turtle\detail\action.hpp" />
|
<ClInclude Include="..\..\turtle\detail\action.hpp" />
|
||||||
<ClInclude Include="..\..\turtle\detail\check.hpp" />
|
<ClInclude Include="..\..\turtle\detail\check.hpp" />
|
||||||
<ClInclude Include="..\..\turtle\detail\child.hpp" />
|
<ClInclude Include="..\..\turtle\detail\child.hpp" />
|
||||||
<ClInclude Include="..\..\turtle\detail\cleanup.hpp" />
|
|
||||||
<ClInclude Include="..\..\turtle\detail\context.hpp" />
|
<ClInclude Include="..\..\turtle\detail\context.hpp" />
|
||||||
<ClInclude Include="..\..\turtle\detail\expectation_base.hpp" />
|
<ClInclude Include="..\..\turtle\detail\expectation_base.hpp" />
|
||||||
<ClInclude Include="..\..\turtle\detail\expectation_template.hpp" />
|
<ClInclude Include="..\..\turtle\detail\expectation_template.hpp" />
|
||||||
|
|
|
||||||
|
|
@ -19,9 +19,6 @@
|
||||||
<ClInclude Include="..\..\turtle\constraints.hpp">
|
<ClInclude Include="..\..\turtle\constraints.hpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\turtle\default_error.hpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\turtle\error.hpp">
|
<ClInclude Include="..\..\turtle\error.hpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -37,9 +34,6 @@
|
||||||
<ClInclude Include="..\..\turtle\sequence.hpp">
|
<ClInclude Include="..\..\turtle\sequence.hpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\turtle\boost_test_error.hpp">
|
|
||||||
<Filter>Source Files</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\turtle\detail\signature.hpp">
|
<ClInclude Include="..\..\turtle\detail\signature.hpp">
|
||||||
<Filter>Source Files\detail</Filter>
|
<Filter>Source Files\detail</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
@ -70,9 +64,6 @@
|
||||||
<ClInclude Include="..\..\turtle\detail\yes_no_type.hpp">
|
<ClInclude Include="..\..\turtle\detail\yes_no_type.hpp">
|
||||||
<Filter>Source Files\detail</Filter>
|
<Filter>Source Files\detail</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="..\..\turtle\detail\cleanup.hpp">
|
|
||||||
<Filter>Source Files\detail</Filter>
|
|
||||||
</ClInclude>
|
|
||||||
<ClInclude Include="..\..\turtle\detail\action.hpp">
|
<ClInclude Include="..\..\turtle\detail\action.hpp">
|
||||||
<Filter>Source Files\detail</Filter>
|
<Filter>Source Files\detail</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
|
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
// http://turtle.sourceforge.net
|
|
||||||
//
|
|
||||||
// Copyright Mathieu Champlon 2011
|
|
||||||
//
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
#ifndef MOCK_BOOST_TEST_ERROR_POLICY_HPP_INCLUDED
|
|
||||||
#define MOCK_BOOST_TEST_ERROR_POLICY_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <boost/test/framework.hpp>
|
|
||||||
#include <boost/test/test_tools.hpp>
|
|
||||||
#include <boost/test/unit_test_suite.hpp>
|
|
||||||
#include <boost/test/execution_monitor.hpp>
|
|
||||||
#include <boost/exception/enable_current_exception.hpp>
|
|
||||||
|
|
||||||
namespace mock
|
|
||||||
{
|
|
||||||
struct exception : virtual boost::execution_aborted
|
|
||||||
{};
|
|
||||||
|
|
||||||
template< typename Result >
|
|
||||||
struct boost_test_error_policy
|
|
||||||
{
|
|
||||||
static Result abort()
|
|
||||||
{
|
|
||||||
boost::unit_test::framework::test_unit_aborted(
|
|
||||||
boost::unit_test::framework::current_test_case() );
|
|
||||||
throw boost::enable_current_exception( exception() );
|
|
||||||
}
|
|
||||||
|
|
||||||
static void checkpoint( const char* file, int line )
|
|
||||||
{
|
|
||||||
boost::unit_test::unit_test_log.set_checkpoint( file,
|
|
||||||
static_cast< std::size_t >( line ) );
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename Context >
|
|
||||||
static void fail(
|
|
||||||
const char* message, const Context& context,
|
|
||||||
const char* file = "unknown location", int line = 0 )
|
|
||||||
{
|
|
||||||
boost::unit_test::framework::assertion_result( false );
|
|
||||||
boost::unit_test::unit_test_log
|
|
||||||
<< boost::unit_test::log::begin( file,
|
|
||||||
static_cast< std::size_t >( line ) )
|
|
||||||
<< boost::unit_test::log_all_errors
|
|
||||||
<< message << ": " << context
|
|
||||||
<< boost::unit_test::log::end();
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename Context >
|
|
||||||
static void expected_call( const Context& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
boost::unit_test::framework::assertion_result( true );
|
|
||||||
boost::unit_test::unit_test_log
|
|
||||||
<< boost::unit_test::log::begin( file,
|
|
||||||
static_cast< std::size_t >( line ) )
|
|
||||||
<< boost::unit_test::log_successful_tests
|
|
||||||
<< "mock expectation fulfilled: " << context
|
|
||||||
<< boost::unit_test::log::end();
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename Context >
|
|
||||||
static void missing_action( const Context& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
fail( "missing action", context, file, line );
|
|
||||||
}
|
|
||||||
template< typename Context >
|
|
||||||
static void unexpected_call( const Context& context )
|
|
||||||
{
|
|
||||||
fail( "unexpected call", context );
|
|
||||||
}
|
|
||||||
template< typename Context >
|
|
||||||
static void sequence_failed( const Context& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
fail( "sequence failed", context, file, line );
|
|
||||||
}
|
|
||||||
template< typename Context >
|
|
||||||
static void verification_failed( const Context& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
fail( "verification failed", context, file, line );
|
|
||||||
}
|
|
||||||
template< typename Context >
|
|
||||||
static void untriggered_expectation( const Context& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
fail( "untriggered expectation", context, file, line );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_BOOST_TEST_ERROR_POLICY_HPP_INCLUDED
|
|
||||||
|
|
@ -43,10 +43,4 @@
|
||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef MOCK_USE_BOOST_TEST
|
|
||||||
# ifdef BOOST_TEST_DECL
|
|
||||||
# define MOCK_USE_BOOST_TEST
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MOCK_CONFIG_HPP_INCLUDED
|
#endif // MOCK_CONFIG_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -1,76 +0,0 @@
|
||||||
// http://turtle.sourceforge.net
|
|
||||||
//
|
|
||||||
// Copyright Mathieu Champlon 2011
|
|
||||||
//
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
#ifndef MOCK_DEFAULT_ERROR_POLICY_HPP_INCLUDED
|
|
||||||
#define MOCK_DEFAULT_ERROR_POLICY_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
namespace mock
|
|
||||||
{
|
|
||||||
struct exception
|
|
||||||
{};
|
|
||||||
|
|
||||||
template< typename Result >
|
|
||||||
struct default_error_policy
|
|
||||||
{
|
|
||||||
static Result abort()
|
|
||||||
{
|
|
||||||
throw exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void checkpoint( const char* /*file*/, int /*line*/ )
|
|
||||||
{}
|
|
||||||
|
|
||||||
template< typename Context >
|
|
||||||
static void fail(
|
|
||||||
const char* message, const Context& context,
|
|
||||||
const char* file = "unknown location", int line = 0 )
|
|
||||||
{
|
|
||||||
std::cerr << file << '(' << line << "): "
|
|
||||||
<< message << ": " << context << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
template< typename Context >
|
|
||||||
static void expected_call( const Context& /*context*/,
|
|
||||||
const char* /*file*/, int /*line*/ )
|
|
||||||
{}
|
|
||||||
|
|
||||||
template< typename Context >
|
|
||||||
static void missing_action( const Context& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
fail( "missing action", context, file, line );
|
|
||||||
}
|
|
||||||
template< typename Context >
|
|
||||||
static void unexpected_call( const Context& context )
|
|
||||||
{
|
|
||||||
fail( "unexpected call", context );
|
|
||||||
}
|
|
||||||
template< typename Context >
|
|
||||||
static void sequence_failed( const Context& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
fail( "sequence failed", context, file, line );
|
|
||||||
}
|
|
||||||
template< typename Context >
|
|
||||||
static void verification_failed( const Context& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
fail( "verification failed", context, file, line );
|
|
||||||
}
|
|
||||||
template< typename Context >
|
|
||||||
static void untriggered_expectation( const Context& context,
|
|
||||||
const char* file, int line )
|
|
||||||
{
|
|
||||||
fail( "untriggered expectation", context, file, line );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif // MOCK_DEFAULT_ERROR_POLICY_HPP_INCLUDED
|
|
||||||
|
|
@ -1,40 +0,0 @@
|
||||||
// http://turtle.sourceforge.net
|
|
||||||
//
|
|
||||||
// Copyright Mathieu Champlon 2011
|
|
||||||
//
|
|
||||||
// Distributed under the Boost Software License, Version 1.0.
|
|
||||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
|
||||||
// http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
|
|
||||||
#ifndef MOCK_CLEANUP_HPP_INCLUDED
|
|
||||||
#define MOCK_CLEANUP_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include "../config.hpp"
|
|
||||||
|
|
||||||
#ifdef MOCK_USE_BOOST_TEST
|
|
||||||
|
|
||||||
#include "root.hpp"
|
|
||||||
#include <boost/test/unit_test_suite.hpp>
|
|
||||||
|
|
||||||
namespace mock
|
|
||||||
{
|
|
||||||
namespace detail
|
|
||||||
{
|
|
||||||
struct cleanup
|
|
||||||
{
|
|
||||||
~cleanup()
|
|
||||||
{
|
|
||||||
// $$$$ MAT : because of a bug in Boost.Test
|
|
||||||
// this will crash if anything needs to be logged
|
|
||||||
// see https://svn.boost.org/trac/boost/ticket/5563
|
|
||||||
//mock::verify();
|
|
||||||
mock::reset();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
BOOST_GLOBAL_FIXTURE( cleanup );
|
|
||||||
}
|
|
||||||
} // mock
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // MOCK_CLEANUP_HPP_INCLUDED
|
|
||||||
|
|
@ -8,6 +8,10 @@
|
||||||
|
|
||||||
#include "expectation_template.hpp"
|
#include "expectation_template.hpp"
|
||||||
|
|
||||||
|
#ifndef MOCK_ERROR_POLICY
|
||||||
|
# error no error policy has been set
|
||||||
|
#endif
|
||||||
|
|
||||||
#define MOCK_FORMAT(z, n, N) \
|
#define MOCK_FORMAT(z, n, N) \
|
||||||
<< ' ' << mock::format( t##n ) \
|
<< ' ' << mock::format( t##n ) \
|
||||||
<< BOOST_PP_IF(BOOST_PP_EQUAL(N,n), ' ', ',')
|
<< BOOST_PP_IF(BOOST_PP_EQUAL(N,n), ' ', ',')
|
||||||
|
|
|
||||||
116
turtle/error.hpp
116
turtle/error.hpp
|
|
@ -9,16 +9,112 @@
|
||||||
#ifndef MOCK_ERROR_HPP_INCLUDED
|
#ifndef MOCK_ERROR_HPP_INCLUDED
|
||||||
#define MOCK_ERROR_HPP_INCLUDED
|
#define MOCK_ERROR_HPP_INCLUDED
|
||||||
|
|
||||||
#include "config.hpp"
|
|
||||||
|
|
||||||
#ifndef MOCK_ERROR_POLICY
|
#ifndef MOCK_ERROR_POLICY
|
||||||
# ifdef MOCK_USE_BOOST_TEST
|
#define MOCK_ERROR_POLICY mock::error
|
||||||
# define MOCK_ERROR_POLICY boost_test_error_policy
|
|
||||||
# include "boost_test_error.hpp"
|
#include <boost/test/framework.hpp>
|
||||||
# else
|
#include <boost/test/test_tools.hpp>
|
||||||
# define MOCK_ERROR_POLICY default_error_policy
|
#include <boost/test/unit_test_suite.hpp>
|
||||||
# include "default_error.hpp"
|
#include <boost/test/execution_monitor.hpp>
|
||||||
# endif
|
#include <boost/exception/enable_current_exception.hpp>
|
||||||
#endif
|
|
||||||
|
namespace mock
|
||||||
|
{
|
||||||
|
struct exception : virtual boost::execution_aborted
|
||||||
|
{};
|
||||||
|
|
||||||
|
template< typename Result >
|
||||||
|
struct error
|
||||||
|
{
|
||||||
|
static Result abort()
|
||||||
|
{
|
||||||
|
boost::unit_test::framework::test_unit_aborted(
|
||||||
|
boost::unit_test::framework::current_test_case() );
|
||||||
|
throw boost::enable_current_exception( exception() );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void checkpoint( const char* file, int line )
|
||||||
|
{
|
||||||
|
boost::unit_test::unit_test_log.set_checkpoint( file,
|
||||||
|
static_cast< std::size_t >( line ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename Context >
|
||||||
|
static void fail(
|
||||||
|
const char* message, const Context& context,
|
||||||
|
const char* file = "unknown location", int line = 0 )
|
||||||
|
{
|
||||||
|
boost::unit_test::framework::assertion_result( false );
|
||||||
|
boost::unit_test::unit_test_log
|
||||||
|
<< boost::unit_test::log::begin( file,
|
||||||
|
static_cast< std::size_t >( line ) )
|
||||||
|
<< boost::unit_test::log_all_errors
|
||||||
|
<< message << ": " << context
|
||||||
|
<< boost::unit_test::log::end();
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename Context >
|
||||||
|
static void expected_call( const Context& context,
|
||||||
|
const char* file, int line )
|
||||||
|
{
|
||||||
|
boost::unit_test::framework::assertion_result( true );
|
||||||
|
boost::unit_test::unit_test_log
|
||||||
|
<< boost::unit_test::log::begin( file,
|
||||||
|
static_cast< std::size_t >( line ) )
|
||||||
|
<< boost::unit_test::log_successful_tests
|
||||||
|
<< "mock expectation fulfilled: " << context
|
||||||
|
<< boost::unit_test::log::end();
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename Context >
|
||||||
|
static void missing_action( const Context& context,
|
||||||
|
const char* file, int line )
|
||||||
|
{
|
||||||
|
fail( "missing action", context, file, line );
|
||||||
|
}
|
||||||
|
template< typename Context >
|
||||||
|
static void unexpected_call( const Context& context )
|
||||||
|
{
|
||||||
|
fail( "unexpected call", context );
|
||||||
|
}
|
||||||
|
template< typename Context >
|
||||||
|
static void sequence_failed( const Context& context,
|
||||||
|
const char* file, int line )
|
||||||
|
{
|
||||||
|
fail( "sequence failed", context, file, line );
|
||||||
|
}
|
||||||
|
template< typename Context >
|
||||||
|
static void verification_failed( const Context& context,
|
||||||
|
const char* file, int line )
|
||||||
|
{
|
||||||
|
fail( "verification failed", context, file, line );
|
||||||
|
}
|
||||||
|
template< typename Context >
|
||||||
|
static void untriggered_expectation( const Context& context,
|
||||||
|
const char* file, int line )
|
||||||
|
{
|
||||||
|
fail( "untriggered expectation", context, file, line );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
bool verify();
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
struct cleanup
|
||||||
|
{
|
||||||
|
~cleanup()
|
||||||
|
{
|
||||||
|
// see https://svn.boost.org/trac/boost/ticket/5563
|
||||||
|
//mock::verify();
|
||||||
|
mock::reset();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
BOOST_GLOBAL_FIXTURE( cleanup );
|
||||||
|
}
|
||||||
|
} // mock
|
||||||
|
|
||||||
|
#endif // MOCK_ERROR_POLICY
|
||||||
|
|
||||||
#endif // MOCK_ERROR_HPP_INCLUDED
|
#endif // MOCK_ERROR_HPP_INCLUDED
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
#include "detail/type_name.hpp"
|
#include "detail/type_name.hpp"
|
||||||
#include "detail/signature.hpp"
|
#include "detail/signature.hpp"
|
||||||
#include "detail/parameter.hpp"
|
#include "detail/parameter.hpp"
|
||||||
#include "detail/cleanup.hpp"
|
|
||||||
#include <boost/preprocessor/repetition/repeat.hpp>
|
#include <boost/preprocessor/repetition/repeat.hpp>
|
||||||
#include <boost/preprocessor/stringize.hpp>
|
#include <boost/preprocessor/stringize.hpp>
|
||||||
#include <boost/mpl/assert.hpp>
|
#include <boost/mpl/assert.hpp>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue