xapian-core  1.4.26
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
test_driver Class Reference

The test driver. This class takes care of running the tests. More...

#include <testsuite.h>

+ Collaboration diagram for test_driver:

Classes

struct  result
 A structure used to report the summary of tests passed and failed. More...
 

Public Member Functions

 test_driver (const test_desc *tests_)
 The constructor, which sets up the test driver. More...
 
result run_tests ()
 Run all the tests supplied and return the results. More...
 
result run_tests (std::vector< std::string >::const_iterator b, std::vector< std::string >::const_iterator e)
 Run the tests in the list and return the results. More...
 

Static Public Member Functions

static void add_command_line_option (const std::string &l, char s, std::string *arg)
 Add a test-specific command line option. More...
 
static void parse_command_line (int argc, char **argv)
 Parse the command line arguments. More...
 
static void usage ()
 
static int run (const test_desc *tests)
 
static std::string get_srcdir ()
 Read srcdir from environment and if not present, make a valiant attempt to guess a value. More...
 
static void report (const test_driver::result &r, const std::string &desc)
 Print summary of tests passed, failed, and skipped. More...
 

Static Public Attributes

static result subtotal
 
static result total
 

Private Types

enum  test_result {
  XPASS = 3, XFAIL = 2, PASS = 1, FAIL = 0,
  SKIP = -1
}
 

Private Member Functions

void write_and_clear_tout ()
 Write out anything in tout and clear it. More...
 
 test_driver (const test_driver &)
 Prevent copying. More...
 
test_driveroperator= (const test_driver &)
 
test_result runtest (const test_desc *test)
 Runs the test function and returns its result. More...
 
result do_run_tests (std::vector< std::string >::const_iterator b, std::vector< std::string >::const_iterator e)
 The implementation used by run_tests. More...
 

Private Attributes

std::ostream out
 
const test_desctests
 

Static Private Attributes

static std::map< int, std::string * > short_opts
 
static std::string opt_help
 
static std::vector< std::string > test_names
 
static bool abort_on_error = false
 
static int runs = 0
 
static std::string argv0
 
static std::string col_red
 
static std::string col_green
 
static std::string col_yellow
 
static std::string col_reset
 
static bool use_cr = false
 

Detailed Description

The test driver. This class takes care of running the tests.

Definition at line 108 of file testsuite.h.

Member Enumeration Documentation

◆ test_result

Enumerator
XPASS 
XFAIL 
PASS 
FAIL 
SKIP 

Definition at line 212 of file testsuite.h.

Constructor & Destructor Documentation

◆ test_driver() [1/2]

test_driver::test_driver ( const test_desc tests_)

The constructor, which sets up the test driver.

Parameters
testsThe zero-terminated array of tests to run.

Definition at line 170 of file testsuite.cc.

References tout.

◆ test_driver() [2/2]

test_driver::test_driver ( const test_driver )
private

Prevent copying.

Member Function Documentation

◆ add_command_line_option()

void test_driver::add_command_line_option ( const std::string &  l,
char  s,
std::string *  arg 
)
static

Add a test-specific command line option.

The recognised option will be described as:

-<s> <l>

And any value set will be put into arg.

Definition at line 817 of file testsuite.cc.

References opt_help, and short_opts.

Referenced by main(), PerfTestRunner::PerfTestRunner(), TestRunner::run_tests(), and SoakTestRunner::SoakTestRunner().

◆ do_run_tests()

test_driver::result test_driver::do_run_tests ( std::vector< std::string >::const_iterator  b,
std::vector< std::string >::const_iterator  e 
)
private

The implementation used by run_tests.

it runs test(s) (with runtest()), prints out messages for the user, and tracks the successes and failures.

Parameters
b,eIf b != e, a vector of the test(s) to run. If b == e, all tests will be run.

Definition at line 694 of file testsuite.cc.

References abort_on_error, backendmanager, BackendManager::clean_up(), col_green, col_reset, FAIL, test_driver::result::failed, test_desc::name, out, PASS, runtest(), SKIP, test_driver::result::skipped, test_driver::result::succeeded, tests, use_cr, verbose, XFAIL, test_driver::result::xfailed, XPASS, and test_driver::result::xpassed.

Referenced by run_tests().

◆ get_srcdir()

string test_driver::get_srcdir ( )
static

Read srcdir from environment and if not present, make a valiant attempt to guess a value.

Definition at line 129 of file testsuite.cc.

References DIR_SEPS, endswith(), file_exists(), srcdir, and startswith().

Referenced by DEFINE_TESTCASE(), main(), make_tg_db(), and TestRunner::run_tests().

◆ operator=()

test_driver& test_driver::operator= ( const test_driver )
private

◆ parse_command_line()

void test_driver::parse_command_line ( int  argc,
char **  argv 
)
static

Parse the command line arguments.

Parameters
argcThe argument count passed into main()
argvThe argument list passed into main()

Definition at line 828 of file testsuite.cc.

References abort_on_error, argv0, col_green, col_red, col_reset, col_yellow, gnu_getopt_long(), no_argument, O_CLOEXEC, Xapian::InMemory::open(), optarg, optind, opts, short_opts, Xapian::Internal::str(), test_names, usage(), use_cr, and verbose.

Referenced by main(), and TestRunner::run_tests().

◆ report()

void test_driver::report ( const test_driver::result r,
const std::string &  desc 
)
static

◆ run()

int test_driver::run ( const test_desc tests)
static

Definition at line 913 of file testsuite.cc.

References test_driver::result::failed, run_tests(), subtotal, test_names, and test_driver::result::xpassed.

Referenced by if(), and main().

◆ run_tests() [1/2]

test_driver::result test_driver::run_tests ( )

Run all the tests supplied and return the results.

Definition at line 687 of file testsuite.cc.

References do_run_tests().

Referenced by run().

◆ run_tests() [2/2]

test_driver::result test_driver::run_tests ( std::vector< std::string >::const_iterator  b,
std::vector< std::string >::const_iterator  e 
)

Run the tests in the list and return the results.

Definition at line 680 of file testsuite.cc.

References do_run_tests().

◆ runtest()

test_driver::test_result test_driver::runtest ( const test_desc test)
private

Runs the test function and returns its result.

It will also trap exceptions and some memory leaks and force a failure in those cases.

Parameters
testA description of the test to run.

Definition at line 327 of file testsuite.cc.

References SignalRedirector::activate(), backendmanager, FDTracker::check(), BackendManager::clean_up(), col_red, col_reset, col_yellow, dummy, errno_to_string(), expected_exception, expected_failure, FAIL, Xapian::Error::get_description(), Xapian::Error::get_error_string(), FDTracker::get_message(), Xapian::Error::get_type(), FDTracker::init(), jb, name, out, PASS, test_desc::run, sigaddr, signum, SIGSETJMP, SKIP, tout, verbose, write_and_clear_tout(), XFAIL, and XPASS.

Referenced by do_run_tests().

◆ usage()

void test_driver::usage ( )
static

Definition at line 764 of file testsuite.cc.

References argv0, and opt_help.

Referenced by parse_command_line().

◆ write_and_clear_tout()

void test_driver::write_and_clear_tout ( )
private

Write out anything in tout and clear it.

Definition at line 119 of file testsuite.cc.

References tout.

Referenced by runtest().

Member Data Documentation

◆ abort_on_error

bool test_driver::abort_on_error = false
staticprivate

Definition at line 241 of file testsuite.h.

Referenced by do_run_tests(), and parse_command_line().

◆ argv0

string test_driver::argv0
staticprivate

Definition at line 253 of file testsuite.h.

Referenced by parse_command_line(), report(), and usage().

◆ col_green

string test_driver::col_green
staticprivate

Definition at line 256 of file testsuite.h.

Referenced by do_run_tests(), parse_command_line(), and report().

◆ col_red

string test_driver::col_red
staticprivate

Definition at line 256 of file testsuite.h.

Referenced by parse_command_line(), report(), and runtest().

◆ col_reset

string test_driver::col_reset
staticprivate

Definition at line 256 of file testsuite.h.

Referenced by do_run_tests(), parse_command_line(), report(), and runtest().

◆ col_yellow

string test_driver::col_yellow
staticprivate

Definition at line 256 of file testsuite.h.

Referenced by parse_command_line(), report(), and runtest().

◆ opt_help

string test_driver::opt_help
staticprivate

Definition at line 218 of file testsuite.h.

Referenced by add_command_line_option(), and usage().

◆ out

std::ostream test_driver::out
private

Definition at line 244 of file testsuite.h.

Referenced by do_run_tests(), and runtest().

◆ runs

int test_driver::runs = 0
staticprivate

Definition at line 250 of file testsuite.h.

Referenced by report().

◆ short_opts

map< int, string * > test_driver::short_opts
staticprivate

Definition at line 216 of file testsuite.h.

Referenced by add_command_line_option(), and parse_command_line().

◆ subtotal

test_driver::result test_driver::subtotal
static

Definition at line 199 of file testsuite.h.

Referenced by ApiTestRunner::run(), and run().

◆ test_names

vector< string > test_driver::test_names
staticprivate

Definition at line 220 of file testsuite.h.

Referenced by parse_command_line(), and run().

◆ tests

const test_desc* test_driver::tests
private

Definition at line 247 of file testsuite.h.

Referenced by do_run_tests().

◆ total

test_driver::result test_driver::total
static

Definition at line 202 of file testsuite.h.

Referenced by ApiTestRunner::run().

◆ use_cr

bool test_driver::use_cr = false
staticprivate

Definition at line 260 of file testsuite.h.

Referenced by do_run_tests(), and parse_command_line().


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