Skip to content

Commit

Permalink
Allow selecting tests to run by base name or specialised name.
Browse files Browse the repository at this point in the history
  • Loading branch information
qris committed Jan 4, 2016
1 parent a89fd31 commit 8a24376
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
16 changes: 12 additions & 4 deletions lib/common/Test.cpp
Expand Up @@ -34,9 +34,17 @@ std::string current_test_name;
std::list<std::string> run_only_named_tests;
std::map<std::string, std::string> s_test_status;

bool setUp(const std::string& function_name)
bool setUp(const std::string& function_name, const std::string& specialisation)
{
current_test_name = function_name;
std::ostringstream specialised_name;
specialised_name << function_name;

if(!specialisation.empty())
{
specialised_name << "(" << specialisation << ")";
}

current_test_name = specialised_name.str();

if (!run_only_named_tests.empty())
{
Expand All @@ -46,7 +54,7 @@ bool setUp(const std::string& function_name)
i = run_only_named_tests.begin();
i != run_only_named_tests.end(); i++)
{
if (*i == current_test_name)
if (*i == function_name || *i == current_test_name)
{
run_this_test = true;
break;
Expand All @@ -60,7 +68,7 @@ bool setUp(const std::string& function_name)
}
}

printf("\n\n== %s ==\n", function_name.c_str());
printf("\n\n== %s ==\n", current_test_name.c_str());
num_tests_selected++;
old_failure_count = num_failures;

Expand Down
13 changes: 4 additions & 9 deletions lib/common/Test.h
Expand Up @@ -44,17 +44,12 @@ extern std::map<std::string, std::string> s_test_status;

//! Simplifies calling setUp() with the current function name in each test.
#define SETUP() \
if (!setUp(__FUNCTION__)) return true; \
if (!setUp(__FUNCTION__, "")) return true; \
try \
{ // left open for TEARDOWN()

#define SETUP_SPECIALISED(name) \
{ \
std::ostringstream full_name; \
full_name << __FUNCTION__ << "(" << name << ")"; \
if (!setUp(full_name.str())) return true; \
} \
\
#define SETUP_SPECIALISED(specialisation) \
if (!setUp(__FUNCTION__, specialisation)) return true; \
try \
{ // left open for TEARDOWN()

Expand Down Expand Up @@ -212,7 +207,7 @@ extern std::map<std::string, std::string> s_test_status;
TEST_EQUAL_LINE(expected, actual.substr(0, std::string(expected).size()), actual);

//! Sets up (cleans up) test environment at the start of every test.
bool setUp(const std::string& function_name);
bool setUp(const std::string& function_name, const std::string& specialisation);

//! Checks account for errors and shuts down daemons at end of every test.
bool tearDown();
Expand Down

0 comments on commit 8a24376

Please sign in to comment.