Chebyshev
Unit testing for scientific software
Loading...
Searching...
No Matches
chebyshev::err::err_context Class Reference

Error checking context, for assertions and exception checking. More...

#include <err.h>

Public Member Functions

void setup (const std::string &moduleName, int argc=0, const char **argv=nullptr)
 Setup error checking module.
 
void terminate (bool exit=false)
 Terminate the error testing environment.
 
 err_context (std::string moduleName, int argc=0, const char **argv=nullptr)
 Setup the error checking module.
 
 ~err_context ()
 Terminate the error checking module.
 
void assert (const std::string &name, bool exp, std::string description="", bool quiet=false)
 Assert that an expression is true.
 
template<typename Function , typename InputType >
void errno_value (const std::string &name, Function f, InputType x, int expected_errno, bool quiet=false)
 Check errno value after function call.
 
template<typename Function , typename InputType >
void errno_value (const std::string &name, Function f, std::function< InputType()> generator, int expected_errno, bool quiet=false)
 Check errno value after function call.
 
template<typename Function , typename InputType >
void errno_flags (const std::string &name, Function f, InputType x, std::vector< int > &expected_flags, bool quiet=false)
 Check the value of errno after a function call, comparing to multiple expected flags which should all be set.
 
template<typename Function , typename InputType >
void errno_flags (const std::string &name, Function f, std::function< InputType()> generator, std::vector< int > &expected_flags, bool quiet=false)
 Check the value of errno after a function call, comparing to multiple expected flags which should all be set.
 
template<typename Function , typename InputType >
void throws (const std::string &name, Function f, InputType x, bool quiet=false)
 Check that an exception of any type is thrown during a function call with the given input.
 
template<typename Function , typename InputType >
void throws (const std::string &name, Function f, std::function< InputType()> generator, bool quiet=false)
 Check that an exception of any type is thrown during a function call with a generated input.
 
template<typename ExceptionType , typename Function , typename InputType >
void throws (const std::string &name, Function f, InputType x, bool quiet=false)
 Check that an exception is thrown during a function call and that the type of the exception is correct.
 
template<typename ExceptionType , typename Function , typename InputType >
void throws (const std::string &name, Function f, std::function< InputType()> generator, bool quiet=false)
 Check that an exception is thrown during a function call and that the type of the exception is correct.
 
std::vector< assert_resultget_assertion (const std::string &name)
 Get the results of an assertion by name or label.
 
assert_result get_assertion (const std::string &name, unsigned int i)
 Get a single result of an assertion by label and index.
 
std::vector< errno_resultget_errno (const std::string &name)
 Get the results of errno checking by name or label.
 
errno_result get_errno (const std::string &name, unsigned int i)
 Get a single result of errno checking by label and index.
 
std::vector< exception_resultget_exception (const std::string &name)
 Get the results of exception checking by name or label.
 
exception_result get_exception (const std::string &name, unsigned int i)
 Get a single result of exception checking by label and index.
 

Public Attributes

err_settings settings
 Settings for the benchmark context.
 
std::shared_ptr< output::output_contextoutput
 Output module settings for the context, dynamically allocated and possibly shared between multiple contexts.
 
std::shared_ptr< random::random_contextrandom
 Random module settings for the context, dynamically allocated and possibly shared between multiple contexts.
 

Detailed Description

Error checking context, for assertions and exception checking.

Member Function Documentation

◆ assert()

void chebyshev::err::err_context::assert ( const std::string &  name,
bool  exp,
std::string  description = "",
bool  quiet = false 
)
inline

Assert that an expression is true.

Parameters
nameName of the check (function name or test case name).
expExpression to test for truth.
descriptionDescription of the assertion.

◆ errno_flags() [1/2]

void chebyshev::err::err_context::errno_flags ( const std::string &  name,
Function  f,
InputType  x,
std::vector< int > &  expected_flags,
bool  quiet = false 
)
inline

Check the value of errno after a function call, comparing to multiple expected flags which should all be set.

Parameters
nameThe name of the function or test case
fThe function to test
xThe input value to evaluate the function at
expected_flagsA list of the expected errno flags

◆ errno_flags() [2/2]

void chebyshev::err::err_context::errno_flags ( const std::string &  name,
Function  f,
std::function< InputType()>  generator,
std::vector< int > &  expected_flags,
bool  quiet = false 
)
inline

Check the value of errno after a function call, comparing to multiple expected flags which should all be set.

Parameters
nameThe name of the function or test case
fThe function to test
generatorA function which returns the input value
expected_flagsA list of the expected errno flags

◆ errno_value() [1/2]

void chebyshev::err::err_context::errno_value ( const std::string &  name,
Function  f,
InputType  x,
int  expected_errno,
bool  quiet = false 
)
inline

Check errno value after function call.

Parameters
nameThe name of the function or test case
fThe function to test
xThe input value to evaluate the function at
expected_errnoThe expected value of errno

◆ errno_value() [2/2]

void chebyshev::err::err_context::errno_value ( const std::string &  name,
Function  f,
std::function< InputType()>  generator,
int  expected_errno,
bool  quiet = false 
)
inline

Check errno value after function call.

Parameters
nameThe name of the function or test case
fThe function to test
generatorA function which returns an input value
expected_errnoThe expected value of errno

◆ setup()

void chebyshev::err::err_context::setup ( const std::string &  moduleName,
int  argc = 0,
const char **  argv = nullptr 
)
inline

Setup error checking module.

Parameters
moduleNameName of the module under test.
argcThe number of command line arguments
argvA list of C-style strings containing the command line arguments.

◆ terminate()

void chebyshev::err::err_context::terminate ( bool  exit = false)
inline

Terminate the error testing environment.

If test cases have been run, their results will be printed.

Parameters
exitWhether to exit after terminating the module.

◆ throws() [1/4]

void chebyshev::err::err_context::throws ( const std::string &  name,
Function  f,
InputType  x,
bool  quiet = false 
)
inline

Check that an exception of any type is thrown during a function call with the given input.

Parameters
nameThe name of the function or test case
fThe function to test
xThe input value to use

◆ throws() [2/4]

void chebyshev::err::err_context::throws ( const std::string &  name,
Function  f,
InputType  x,
bool  quiet = false 
)
inline

Check that an exception is thrown during a function call and that the type of the exception is correct.

Parameters
nameThe name of the function or test case
fThe function to test
xThe input value to use

◆ throws() [3/4]

void chebyshev::err::err_context::throws ( const std::string &  name,
Function  f,
std::function< InputType()>  generator,
bool  quiet = false 
)
inline

Check that an exception of any type is thrown during a function call with a generated input.

Parameters
nameThe name of the function or test case
fThe function to test
generatorA function which returns the input value

◆ throws() [4/4]

void chebyshev::err::err_context::throws ( const std::string &  name,
Function  f,
std::function< InputType()>  generator,
bool  quiet = false 
)
inline

Check that an exception is thrown during a function call and that the type of the exception is correct.

Parameters
nameThe name of the function or test case
fThe function to test
generatorA function which takes in an index and returns a (potentially random) input value

The documentation for this class was generated from the following file: