Skip to content

Commit

Permalink
Skip unfocused tests in suites with focused tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cegonse committed Oct 6, 2024
1 parent ac628d8 commit 78f9ebc
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/focus-test-suite.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "globals.hpp"

namespace cest
{
void configureFocusedTestSuite(cest::TestSuite *test_suite)
{
int focused_test_idx = -1;

for (int i = 0; i < (int)test_suite->test_cases.size(); i++)
{
cest::TestCase *test_case = test_suite->test_cases[i];
if (test_case->condition == cest::TestCaseCondition::Fitted)
{
focused_test_idx = i;
break;
}
}

if (focused_test_idx != -1)
{
for (int i = 0; i < (int)test_suite->test_cases.size(); i++)
{
cest::TestCase *test_case = test_suite->test_cases[i];

if (i != focused_test_idx)
test_case->condition = cest::TestCaseCondition::Skipped;
}
}

for (auto &pair : test_suite->test_suites)
configureFocusedTestSuite(pair.second);
}
}
2 changes: 2 additions & 0 deletions src/main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "expect.hpp"
#include "randomized-tests.hpp"
#include "signal-handler.hpp"
#include "focus-test-suite.hpp"

int main(int argc, const char *argv[])
{
Expand All @@ -30,6 +31,7 @@ int main(int argc, const char *argv[])
cest::randomizeTests(root_suite, seed, cest::defaultRandomFn);
}

cest::configureFocusedTestSuite(root_suite);
cest::runTestSuite(root_suite, root_suite->name);
cest::printTestSuiteResult(root_suite);

Expand Down
3 changes: 3 additions & 0 deletions src/suite-runner.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ namespace cest

for (cest::TestCase *test_case : suite->test_cases)
{
if (test_case->condition == cest::TestCaseCondition::Skipped)
continue;

__cest_globals.current_test_case = test_case;

if (suite->before_each.fn)
Expand Down

0 comments on commit 78f9ebc

Please sign in to comment.