Skip to content

Commit

Permalink
Merge 6ab615f into 928a12d
Browse files Browse the repository at this point in the history
  • Loading branch information
EtienneBarbier committed Feb 4, 2020
2 parents 928a12d + 6ab615f commit 118c887
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
48 changes: 47 additions & 1 deletion docs/CookBook.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ sample adaptations are:
- [lest](#adapt_lest)
- [boost Unit Test Framework](#adapt_boost_unit_test_framework)
- [MSTest](#adapt_mstest)
- [Criterion](#adapt_criterion)

There are two mechanisms for adapting to a testing frame work. The compile time
adapter and the run time adapter. The compile time adapter is easier to use,
Expand Down Expand Up @@ -179,7 +180,7 @@ are no expectations. In these cases `file` will be `""` string and
It is possible to make an adaption to the reporter that will be called if
a positive expectation is met. This can be useful for correct counting and reporting
from the testing framework. Negative expectations like `FORBID_CALL` and
`.TIMES(0)` are not counted.
`.TIMES(0)` are not counted.
Provide an inline specialization of the
`trompeloeil::reporter<trompeloeil::specialized>::sendOk()` function.
Expand Down Expand Up @@ -563,6 +564,51 @@ Place the below code snippet in, for example, your `TEST_CLASS_INITIALIZE(...)`
});
```
### <A name="adapt_criterion"/>Use *Trompeloeil* with [Criterion](https://github.com/Snaipe/Criterion)
The easiest way to use *Trompeloeil* with *Criterion* is to
`#include <criterion/trompeloeil.hpp>` in your test .cpp files. Note that the
inclusion order is important. `<criterion/criterion.hpp>` must be included before
`<criterion/trompeloeil.hpp>`.
Like this:
```Cpp
#include <criterion/criterion.hpp>
#include <criterion/trompeloeil.hpp>
Test(...
```
If you instead prefer a runtime adapter, make sure to call


```Cpp
trompeloeil::set_reporter([](
trompeloeil::severity s,
const char* file,
unsigned long line,
std::string const& msg)
{
struct criterion_assert_stats cr_stat__;
cr_stat__.passed = false;
cr_stat__.file = file;
cr_stat__.line = line;
cr_stat__.message = msg;
if (s == severity::fatal)
{
criterion_send_assert(&cr_stat__);
CR_FAIL_ABORT_();
}
else
{
criterion_send_assert(&cr_stat__);
CR_FAIL_CONTINUES_();
}
});
```
before running any tests.
## <A name="creating_mock_classes"/> Creating Mock Classes
A Mock class is any class that [mocks](reference.md/#mock_function) member
Expand Down
61 changes: 61 additions & 0 deletions include/criterion/tromploeil.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Trompeloeil C++ mocking framework
*
* Copyright Björn Fahller 2014-2019
* Copyright Etienne Barbier 2020
*
* Use, modification and distribution is subject to 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)
*
* Project home: https://github.com/rollbear/trompeloeil
*/


#ifndef TROMPELOEIL_CRITERION_HPP_
#define TROMPELOEIL_CRITERION_HPP_

#ifndef CRITERION_H_
#error "<criterion.h> must be included before <criterion/trompeloeil.hpp>"
#endif

#include "../trompeloeil.hpp"

namespace trompeloeil
{
template <>
inline void reporter<specialized>::send(
severity s,
char const *file,
unsigned long line,
const char* msg)
{
struct criterion_assert_stats cr_stat__;
cr_stat__.passed = false;
cr_stat__.file = file;
cr_stat__.line = line;
cr_stat__.message = msg;
if (s == severity::fatal)
{
criterion_send_assert(&cr_stat__);
CR_FAIL_ABORT_();
}
else
{
criterion_send_assert(&cr_stat__);
CR_FAIL_CONTINUES_();
}
}

template <>
inline void reporter<specialized>::sendOk(
const char* trompeloeil_mock_calls_done_correctly)
{
cri_asserts_passed_incr();
}
}



#endif //TROMPELOEIL_CRITERION_HPP_

0 comments on commit 118c887

Please sign in to comment.