mirror of
https://github.com/mat007/turtle.git
synced 2026-06-22 12:13:43 +00:00
Merge pull request #32 from mat007/catch-integration
Added Catch integration
This commit is contained in:
commit
6102a8202a
8 changed files with 70 additions and 61 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
#[Turtle](http://turtle.sourceforge.net)
|
#[Turtle](http://turtle.sourceforge.net)
|
||||||
|
|
||||||
Turtle is a C++ mock object library based on Boost with a focus on usability, simplicity and flexibility.
|
Turtle is a C++ mock object library based on Boost with a focus on usability, simplicity and flexibility.
|
||||||
|
|
||||||
### Test results
|
### Test results
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,6 @@
|
||||||
|
|
||||||
[section Acknowledgements]
|
[section Acknowledgements]
|
||||||
|
|
||||||
Many thanks to Adrien Gervaise, Silvin Lubecki and Takatoshi Kondo !
|
Many thanks to Adrien Gervaise, Silvin Lubecki, Takatoshi Kondo and Ovanes Markarian !
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ Not yet released
|
||||||
|
|
||||||
* Fixed mocking of a function returning a reference for gcc 4.1
|
* Fixed mocking of a function returning a reference for gcc 4.1
|
||||||
* Added MOCK_NO_AUTO_PTR to deactivate std::auto_ptr support
|
* Added MOCK_NO_AUTO_PTR to deactivate std::auto_ptr support
|
||||||
|
* Added [@https://github.com/philsquared/Catch Catch] integration
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,6 +148,8 @@ The policy can then be activated by defining MOCK_ERROR_POLICY prior to includin
|
||||||
|
|
||||||
[define_custom_policy]
|
[define_custom_policy]
|
||||||
|
|
||||||
|
A custom policy for [@https://github.com/philsquared/Catch Catch] is provided and can be enabled simply by including catch.hpp instead of turtle.hpp.
|
||||||
|
|
||||||
[endsect]
|
[endsect]
|
||||||
|
|
||||||
[section Thread safety]
|
[section Thread safety]
|
||||||
|
|
|
||||||
|
|
@ -147,21 +147,22 @@ struct custom_policy
|
||||||
{
|
{
|
||||||
static Result abort()
|
static Result abort()
|
||||||
{
|
{
|
||||||
// ...
|
// Notify the test framework that an error occurs which makes it impossible to continue the test.
|
||||||
|
// This should most likely throw an exception of some kind.
|
||||||
}
|
}
|
||||||
template< typename Context >
|
template< typename Context >
|
||||||
static void fail( const char* message, const Context& context, const char* file = "unknown location", int line = 0 )
|
static void fail( const char* message, const Context& context, const char* file = "unknown location", int line = 0 )
|
||||||
{
|
{
|
||||||
// ...
|
// Notify the test framework that an unexpected call has occurred.
|
||||||
}
|
}
|
||||||
template< typename Context >
|
template< typename Context >
|
||||||
static void call( const Context& context, const char* file, int line )
|
static void call( const Context& context, const char* file, int line )
|
||||||
{
|
{
|
||||||
// ...
|
// Notify the test framework that an expectation has been fulfilled.
|
||||||
}
|
}
|
||||||
static void pass( const char* file, int line )
|
static void pass( const char* file, int line )
|
||||||
{
|
{
|
||||||
// ...
|
// Notify the test framework that the test execution merely passed the given code location.
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//]
|
//]
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
#include <boost/test/auto_unit_test.hpp>
|
#include <boost/test/auto_unit_test.hpp>
|
||||||
#include <turtle/mock.hpp>
|
#include <turtle/mock.hpp>
|
||||||
|
|
||||||
namespace limitations_template_base_class_method_problem
|
namespace
|
||||||
{
|
{
|
||||||
//[ limitations_template_base_class_method_problem
|
//[ limitations_template_base_class_method_problem
|
||||||
template< typename T >
|
template< typename T >
|
||||||
|
|
@ -32,47 +32,3 @@ MOCK_BASE_CLASS( mock_base, base< T > )
|
||||||
};
|
};
|
||||||
//]
|
//]
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace limitations_template_base_class_method_problem_2
|
|
||||||
{
|
|
||||||
//[ limitations_template_base_class_method_problem_2
|
|
||||||
class concept
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
template< typename T >
|
|
||||||
T create()
|
|
||||||
{
|
|
||||||
return T();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
template< typename T >
|
|
||||||
void function_under_test( T t ) // T is supposed to model the previous concept
|
|
||||||
{
|
|
||||||
t.template create< int >();
|
|
||||||
t.template create< std::string >();
|
|
||||||
}
|
|
||||||
//]
|
|
||||||
|
|
||||||
//[ limitations_template_base_class_method_solution_2
|
|
||||||
MOCK_CLASS( mock_concept )
|
|
||||||
{
|
|
||||||
template< typename T >
|
|
||||||
T create();
|
|
||||||
|
|
||||||
MOCK_METHOD( create_int, 0, int(), create_int )
|
|
||||||
MOCK_METHOD( create_string, 0, std::string(), create_string )
|
|
||||||
};
|
|
||||||
|
|
||||||
template<>
|
|
||||||
int mock_concept::create< int >()
|
|
||||||
{
|
|
||||||
return create_int();
|
|
||||||
}
|
|
||||||
template<>
|
|
||||||
std::string mock_concept::create< std::string >()
|
|
||||||
{
|
|
||||||
return create_string();
|
|
||||||
}
|
|
||||||
//]
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
[import example/limitations_literal_zero.cpp]
|
[import example/limitations_literal_zero.cpp]
|
||||||
[import example/limitations_throw_specifier.cpp]
|
[import example/limitations_throw_specifier.cpp]
|
||||||
[import example/limitations_non_virtual_method.cpp]
|
[import example/limitations_non_virtual_method.cpp]
|
||||||
|
[import example/limitations_template_base_class_method.cpp]
|
||||||
[import example/limitations_template_method.cpp]
|
[import example/limitations_template_method.cpp]
|
||||||
[import example/limitations_private_method.cpp]
|
[import example/limitations_private_method.cpp]
|
||||||
[import example/limitations_comma_in_macro.cpp]
|
[import example/limitations_comma_in_macro.cpp]
|
||||||
|
|
|
||||||
47
include/turtle/catch.hpp
Normal file
47
include/turtle/catch.hpp
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
// http://turtle.sourceforge.net
|
||||||
|
//
|
||||||
|
// Copyright Mathieu Champlon and Ovanes Markarian 2017
|
||||||
|
//
|
||||||
|
// 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_CATCH_HPP_INCLUDED
|
||||||
|
#define MOCK_CATCH_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include <catch.hpp>
|
||||||
|
|
||||||
|
template< typename Result >
|
||||||
|
struct catch_mock_error_policy
|
||||||
|
{
|
||||||
|
static Result abort()
|
||||||
|
{
|
||||||
|
FAIL( "Aborted" );
|
||||||
|
throw std::runtime_error( "unreachable" );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename Context >
|
||||||
|
static void fail( const char* message, const Context& context,
|
||||||
|
const char* file = "file://unknown-location", line = 0 )
|
||||||
|
{
|
||||||
|
CAPTURE( context );
|
||||||
|
FAIL_CHECK( message << " in: " << file << ":" << line );
|
||||||
|
}
|
||||||
|
|
||||||
|
template< typename Context >
|
||||||
|
static void call( const Context& context, const char* file, int line )
|
||||||
|
{
|
||||||
|
CAPTURE( context );
|
||||||
|
INFO( file << ":" << line );
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pass( const char* file, int line )
|
||||||
|
{
|
||||||
|
INFO( file << ":" << line );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#define MOCK_ERROR_POLICY catch_mock_error_policy
|
||||||
|
#include "mock.hpp"
|
||||||
|
|
||||||
|
#endif // MOCK_CATCH_HPP_INCLUDED
|
||||||
Loading…
Add table
Add a link
Reference in a new issue