Allow starting a specification at a different case.

This can be used to skip failing test cases with external support from
a test runner like greentea.
It would reset the device and execute the specification again, but start
at the next test case.
Niklas Hauser 2015-12-04 17:38:40 +00:00 committed by Martin Kojtal
parent c2343b223b
commit 4e5996ceea
2 changed files with 15 additions and 2 deletions

View File

@ -52,9 +52,18 @@ static void die() {
} }
void Harness::run(const Specification specification) void Harness::run(const Specification specification)
{
run(specification, 0);
}
void Harness::run(const Specification specification, std::size_t start_case)
{ {
mbed::util::CriticalSectionLock lock; mbed::util::CriticalSectionLock lock;
// ignore any invalid start index
if (start_case >= specification.length)
return;
test_cases = specification.cases; test_cases = specification.cases;
test_length = specification.length; test_length = specification.length;
defaults = specification.defaults; defaults = specification.defaults;
@ -68,7 +77,7 @@ void Harness::run(const Specification specification)
case_passed = 0; case_passed = 0;
case_failed = 0; case_failed = 0;
case_failed_before = 0; case_failed_before = 0;
case_current = test_cases; case_current = &test_cases[start_case];
if (handlers.test_setup && (handlers.test_setup(test_length) != STATUS_CONTINUE)) { if (handlers.test_setup && (handlers.test_setup(test_length) != STATUS_CONTINUE)) {
if (handlers.test_teardown) handlers.test_teardown(0, 0, FAILURE_SETUP); if (handlers.test_teardown) handlers.test_teardown(0, 0, FAILURE_SETUP);

View File

@ -43,9 +43,13 @@ namespace v1 {
class Harness class Harness
{ {
public: public:
/// Starts running a test specification /// Runs a test specification
static void run(const Specification specification); static void run(const Specification specification);
/// Runs a test specification starting at the specified case index
/// @warning if the start index is out of bounds, the call has no effect!
static void run(const Specification specification, size_t start_case);
/// @returns `true` if a test specification is being executed, `false` otherwise /// @returns `true` if a test specification is being executed, `false` otherwise
static bool is_busy(); static bool is_busy();