libwreport 3.42
wreport::tests Namespace Reference

Utility functions for the unit tests. More...

Data Structures

struct  Actual
 
struct  ActualCString
 
struct  ActualDouble
 
struct  ActualFunction
 
struct  ActualPath
 
struct  ActualStdString
 
struct  ActualVar
 
struct  ActualVarcode
 
struct  ActualVector
 
struct  FilteringTestController
 Test controller that filters tests via a blocklist/allowlist system containing glob patterns on testcase.testmethod names. More...
 
struct  Fixture
 Base class for test fixtures. More...
 
class  FixtureTestCase
 Test case that includes a fixture. More...
 
struct  LocationInfo
 Add information to the test backtrace for the tests run in the current scope. More...
 
struct  SimpleTestController
 Simple default implementation of TestController. More...
 
struct  TestCase
 Test case collecting several test methods, and self-registering with the singleton instance of TestRegistry. More...
 
struct  TestCaseResult
 Result of running a whole test case. More...
 
struct  TestCodec
 
struct  TestController
 Abstract interface for the objects that supervise test execution. More...
 
struct  TestFailed
 Exception thrown when a test assertion fails, normally by Location::fail_test. More...
 
struct  TestMethod
 Test method information. More...
 
struct  TestMethodResult
 Result of running a test method. More...
 
struct  TestRegistry
 Test registry. More...
 
struct  TestResultStats
 
struct  TestSkipped
 Exception thrown when a test or a test case needs to be skipped. More...
 
struct  TestStack
 
struct  TestStackFrame
 Information about one stack frame in the test execution stack. More...
 
struct  VerboseTestController
 Verbose implementation of TestController. More...
 

Functions

std::filesystem::path datafile (const std::filesystem::path &fname)
 Return the pathname of a test file.
 
std::filesystem::path path_from_env (const char *varname, const char *deflt=nullptr)
 Return a path from an envirnment variable.
 
std::string slurpfile (const std::filesystem::path &name)
 Read the entire contents of a test file into a string.
 
std::vector< std::filesystem::path > all_test_files (const std::string &encoding)
 Get a list of all test files for the given encoding.
 
void dump_jsonl (const Bulletin &bulletin, std::stringstream &out)
 Dump a bulletin to a simple but deterministic JSON line.
 
void track_bulletin (Bulletin &b, const char *tag, const std::filesystem::path &fname)
 
template<typename BULLETIN>
std::unique_ptr< BULLETIN > decode_checked (const std::string &buf, const char *name)
 
template<typename BULLETIN>
std::unique_ptr< BULLETIN > decode_checked (const std::string &buf, const char *name, FILE *verbose)
 
void assert_var_equal (const Var &actual, const Var &expected)
 
void assert_var_not_equal (const Var &actual, const Var &expected)
 
template<typename Val>
void assert_var_value_equal (const Var &actual, Val expected)
 
template<typename Val>
void assert_var_value_not_equal (const Var &actual, Val expected)
 
ActualVar actual (const wreport::Var &actual)
 
ActualVarcode actual_varcode (Varcode actual)
 
template<typename A>
void assert_true (const A &actual)
 The following assert_* functions throw TestFailed without capturing file/line numbers, and need to be used inside wassert to give good error messages.
 
void assert_true (std::nullptr_t actual)
 
template<typename A>
void assert_false (const A &actual)
 Test function that ensures that the actual value is false.
 
void assert_false (std::nullptr_t actual)
 
template<typename T>
void assert_equal (const std::vector< T > &actual, const std::vector< T > &expected)
 
template<typename T>
void assert_equal (const std::vector< T > &actual, const std::initializer_list< T > &expected)
 
template<typename A, typename E>
void assert_equal (const A &actual, const E &expected)
 Test function that ensures that the actual value is the same as a reference one.
 
template<typename A, typename E>
void assert_not_equal (const A &actual, const E &expected)
 Test function that ensures that the actual value is different than a reference one.
 
template<typename A, typename E>
void assert_less (const A &actual, const E &expected)
 Ensure that the actual value is less than the reference value.
 
template<typename A, typename E>
void assert_less_equal (const A &actual, const E &expected)
 Ensure that the actual value is less or equal than the reference value.
 
template<typename A, typename E>
void assert_greater (const A &actual, const E &expected)
 Ensure that the actual value is greater than the reference value.
 
template<typename A, typename E>
void assert_greater_equal (const A &actual, const E &expected)
 Ensure that the actual value is greather or equal than the reference value.
 
void assert_startswith (const std::string &actual, const std::string &expected)
 Ensure that the string actual starts with expected.
 
void assert_endswith (const std::string &actual, const std::string &expected)
 Ensure that the string actual ends with expected.
 
void assert_contains (const std::string &actual, const std::string &expected)
 Ensure that the string actual contains expected.
 
void assert_not_contains (const std::string &actual, const std::string &expected)
 Ensure that the string actual does not contain expected.
 
void assert_re_matches (const std::string &actual, const std::string &expected)
 Ensure that the string actual matches the extended regular expression expected.
 
void assert_not_re_matches (const std::string &actual, const std::string &expected)
 Ensure that the string actual does not match the extended regular expression expected.
 
template<typename T>
Actual< int > actual_int (const T &value)
 
template<typename T>
Actual< unsigned > actual_unsigned (const T &value)
 
template<typename T>
Actual< double > actual_double (const T &value)
 
template<typename A>
Actual< A > actual (const A &actual)
 
ActualCString actual (const char *actual)
 
ActualCString actual (char *actual)
 
ActualStdString actual (const std::string &actual)
 
ActualStdString actual (const std::vector< uint8_t > &actual)
 
ActualPath actual (const std::filesystem::path &actual)
 
ActualDouble actual (double actual)
 
ActualFunction actual_function (std::function< void()> actual)
 
ActualPath actual_path (const char *pathname)
 
ActualPath actual_path (const std::string &pathname)
 
ActualPath actual_file (const char *pathname)
 
ActualPath actual_file (const std::string &pathname)
 
template<typename T>
ActualVector< T > actual (const std::vector< T > &actual)
 

Detailed Description

Utility functions for the unit tests.

Author
Enrico Zini enric.nosp@m.o@en.nosp@m.ricoz.nosp@m.ini..nosp@m.org, Peter Rockai (mornfall) me@mo.nosp@m.rnfa.nosp@m.ll.ne.nosp@m.t

Copyright (C) 2006–2007 Peter Rockai (mornfall) me@mo.nosp@m.rnfa.nosp@m.ll.ne.nosp@m.t Copyright (C) 2003–2025 Enrico Zini enric.nosp@m.o@de.nosp@m.bian..nosp@m.org

Function Documentation

◆ assert_not_re_matches()

void wreport::tests::assert_not_re_matches ( const std::string & actual,
const std::string & expected )

Ensure that the string actual does not match the extended regular expression expected.

The syntax is that of extended regular expression (see man regex(7) ).

◆ assert_re_matches()

void wreport::tests::assert_re_matches ( const std::string & actual,
const std::string & expected )

Ensure that the string actual matches the extended regular expression expected.

The syntax is that of extended regular expression (see man regex(7) ).

◆ assert_true()

template<typename A>
void wreport::tests::assert_true ( const A & actual)

The following assert_* functions throw TestFailed without capturing file/line numbers, and need to be used inside wassert to give good error messages.

Do not use them in actual test cases, but you can use them to implement test assertions. Test function that ensures that the actual value is true

◆ dump_jsonl()

void wreport::tests::dump_jsonl ( const Bulletin & bulletin,
std::stringstream & out )

Dump a bulletin to a simple but deterministic JSON line.

This can be used to detect if the decoder has changed behaviour from previously known output.

◆ path_from_env()

std::filesystem::path wreport::tests::path_from_env ( const char * varname,
const char * deflt = nullptr )

Return a path from an envirnment variable.

Returns deflt if the variable is not defined.

Returns the current path the variable is not defined and if deflt is nullptr.

◆ slurpfile()

std::string wreport::tests::slurpfile ( const std::filesystem::path & name)

Read the entire contents of a test file into a string.

The file name will be resolved through datafile