atria::testing Namespace Reference

Testing tools, like spies, for modern C++ development. More...

Classes

class  benchmark_runner
 A class to run multiple suites of benchmarks. More...
 
struct  benchmark_runner_error
 Error thrown by the benchmark_runner when it should not execute. More...
 
struct  benchmark_settings
 Settings to configure a benchmark run. More...
 
class  benchmark_suite
 A suite of benchmarks. More...
 
class  benchmark_suite< void >
 
struct  copy_spy
 Utility for testing how many times an object is copied. More...
 
class  spy_fn
 Functor that counts the number of times it was called. More...
 
class  variant_spy
 Class for spying on functions that take a variant as a parameter. More...
 

Functions

void unoptimize (const void *)
 Utility to prevent calls to code the could be inlineable by the compiler being removed completely if the compiler can find this is a no-op. More...
 
template<typename T >
void unoptimize (const T &x)
 
template<typename FnT >
auto timeit (FnT &&fn) -> std::chrono::duration< double, std::milli >
 In the spirit of Python's timeit(), takes a nullary function and evaluates it, calculating how long it takes to execute. More...
 
template<typename FnT >
int benchmark_main (int argc, char const *const *argv, FnT &&fn)
 Creates a benchmark_runner and passes it to fn, returning a zero (success) code. More...
 
template<typename Fn >
auto spy (const Fn &fn) -> spy_fn< Fn >
 Returns a spy object that uses fn as mock implementation. More...
 
auto spy () -> spy_fn<>
 Returns a spy object with a no-op mock implementation. More...
 
template<typename MockT >
auto spy_on (MockT &mock) -> spy_fn< detail::scoped_intruder< MockT > >
 Given a functor object mock of a general functor with type erasure (e.g. More...
 
template<typename MockT , typename FnT >
auto spy_on (MockT &mock, const FnT &replacement) -> spy_fn< detail::scoped_intruder< MockT > >
 Like spy_on(), but it installs the replacement function instead of keeping the original one. More...
 

Detailed Description

Testing tools, like spies, for modern C++ development.

Function Documentation

int atria::testing::benchmark_main ( int  argc,
char const *const *  argv,
FnT &&  fn 
)

Creates a benchmark_runner and passes it to fn, returning a zero (success) code.

If there is an error, prints it to the command line and returns a non-zero (failure) value.

Definition at line 291 of file benchmark.hpp.

auto atria::testing::spy ( const Fn &  fn) -> spy_fn<Fn>
inline

Returns a spy object that uses fn as mock implementation.

Definition at line 171 of file spies.hpp.

auto atria::testing::spy ( ) -> spy_fn<>
inline

Returns a spy object with a no-op mock implementation.

Definition at line 180 of file spies.hpp.

auto atria::testing::spy_on ( MockT &  mock) -> spy_fn<detail::scoped_intruder<MockT> >
inline

Given a functor object mock of a general functor with type erasure (e.g.

std::function or boost::function) installs a spy that counts the calls and returns such a spy.

Definition at line 250 of file spies.hpp.

auto atria::testing::spy_on ( MockT &  mock,
const FnT &  replacement 
) -> spy_fn<detail::scoped_intruder<MockT> >
inline

Like spy_on(), but it installs the replacement function instead of keeping the original one.

The spy is uninstalled on destruction, and it is not copyable.

Definition at line 263 of file spies.hpp.

auto atria::testing::timeit ( FnT &&  fn) -> std::chrono::duration<double, std::milli>

In the spirit of Python's timeit(), takes a nullary function and evaluates it, calculating how long it takes to execute.

Definition at line 69 of file benchmark.hpp.

void atria::testing::unoptimize ( const void *  )

Utility to prevent calls to code the could be inlineable by the compiler being removed completely if the compiler can find this is a no-op.

Just make sure the code returns something that is derived from the work you are interested in benchmarking and passed to this function.

Fork me on GitHub