test_driver Class Reference

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

#include <testsuite.h>

Collaboration diagram for test_driver:

Collaboration graph
[legend]

List of all members.

Classes

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

Public Member Functions

 XAPIAN_NORETURN (static void usage())
 test_driver (const test_desc *tests_)
 The constructor, which sets up the test driver.
result run_tests ()
 Run all the tests supplied and return the results.
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.

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.
static void parse_command_line (int argc, char **argv)
 Parse the command line arguments.
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.
static void report (const test_driver::result &r, const std::string &desc)
 Print summary of tests passed, failed, and skipped.

Static Public Attributes

static result subtotal
static result total

Private Types

enum  test_result { PASS = 1, FAIL = 0, SKIP = -1 }

Private Member Functions

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

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 94 of file testsuite.h.


Member Enumeration Documentation

enum test_driver::test_result [private]

Enumerator:
PASS 
FAIL 
SKIP 

Definition at line 184 of file testsuite.h.


Constructor & Destructor Documentation

test_driver::test_driver ( const test_desc tests_  ) 

The constructor, which sets up the test driver.

Parameters:
tests The zero-terminated array of tests to run.

Definition at line 165 of file testsuite.cc.

test_driver::test_driver ( const test_driver  )  [private]

Prevent copying.


Member Function Documentation

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 678 of file testsuite.cc.

References opt_help, and short_opts.

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

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,e If b != e, a vector of the test(s) to run. If b == e, all tests will be run.

Definition at line 576 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, and verbose.

Referenced by run_tests().

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 118 of file testsuite.cc.

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

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

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

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

Parse the command line arguments.

Parameters:
argc The argument count passed into main()
argv The argument list passed into main()

Definition at line 689 of file testsuite.cc.

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

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

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

Print summary of tests passed, failed, and skipped.

Definition at line 652 of file testsuite.cc.

References argv0, col_green, col_red, col_reset, col_yellow, test_driver::result::failed, report_totals(), runs, test_driver::result::skipped, and test_driver::result::succeeded.

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

int test_driver::run ( const test_desc tests  )  [static]

Definition at line 771 of file testsuite.cc.

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

Referenced by if(), and main().

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 562 of file testsuite.cc.

References do_run_tests().

test_driver::result test_driver::run_tests (  ) 

Run all the tests supplied and return the results.

Definition at line 569 of file testsuite.cc.

References do_run_tests().

Referenced by run().

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:
test A description of the test to run.

Definition at line 300 of file testsuite.cc.

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

Referenced by do_run_tests().

void test_driver::write_and_clear_tout (  )  [private]

Write out anything in tout and clear it.

Definition at line 108 of file testsuite.cc.

References out, and tout.

Referenced by runtest().

test_driver::XAPIAN_NORETURN ( static void   usage()  ) 


Member Data Documentation

bool test_driver::abort_on_error = false [static, private]

Definition at line 211 of file testsuite.h.

Referenced by do_run_tests(), and parse_command_line().

string test_driver::argv0 [static, private]

Definition at line 223 of file testsuite.h.

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

string test_driver::col_green [static, private]

Definition at line 226 of file testsuite.h.

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

string test_driver::col_red [static, private]

Definition at line 226 of file testsuite.h.

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

string test_driver::col_reset [static, private]

Definition at line 226 of file testsuite.h.

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

string test_driver::col_yellow [static, private]

Definition at line 226 of file testsuite.h.

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

string test_driver::opt_help [static, private]

Definition at line 188 of file testsuite.h.

Referenced by add_command_line_option().

std::ostream test_driver::out [private]

Definition at line 214 of file testsuite.h.

Referenced by do_run_tests(), runtest(), and write_and_clear_tout().

int test_driver::runs = 0 [static, private]

Definition at line 220 of file testsuite.h.

Referenced by report().

map< int, string * > test_driver::short_opts [static, private]

Definition at line 186 of file testsuite.h.

Referenced by add_command_line_option(), and parse_command_line().

Definition at line 171 of file testsuite.h.

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

vector< string > test_driver::test_names [static, private]

Definition at line 190 of file testsuite.h.

Referenced by parse_command_line(), and run().

const test_desc* test_driver::tests [private]

Definition at line 217 of file testsuite.h.

Referenced by do_run_tests().

Definition at line 174 of file testsuite.h.

Referenced by ApiTestRunner::run().

bool test_driver::use_cr = false [static, private]

Definition at line 230 of file testsuite.h.

Referenced by do_run_tests(), and parse_command_line().


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

Documentation for Xapian (version 1.2.8).
Generated on 14 Dec 2011 by Doxygen 1.5.9.