Skip to content

Commit

Permalink
Refactor and add TEST_SKIP() macro.
Browse files Browse the repository at this point in the history
We also rename cmdline option --skip to --exclude, as using the option
actually exclude the test from the report completely, whereas the macro
TEST_SKIP() makes it explicitly marked as SKIPPED.

(Though the --skip is silently accepted as a synonym of --exclude for
compatibility reasons.)

Closes mity#66.
  • Loading branch information
mity committed Dec 28, 2023
1 parent a2a6f4b commit 5ec4780
Show file tree
Hide file tree
Showing 3 changed files with 298 additions and 155 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,9 @@ tests. It can also run only subset of the unit tests as specified on the
command line:

```sh
$ ./test_example # Runs all tests in the suite
$ ./test_example test1 test2 # Runs only tests specified
$ ./test_example --skip test3 # Runs all tests but those specified
$ ./test_example # Runs all tests in the suite
$ ./test_example test1 test2 # Runs only tests specified
$ ./test_example --exclude test3 # Runs all tests but those specified
```

Note that a single command line argument can select a whole group of test units
Expand All @@ -394,8 +394,8 @@ matching at least one test unit is used):
selected.

By adopting an appropriate test naming strategy, this allows user to run (or
to skip if `--skip` is used) easily whole family of related tests with a single
command line argument.
to skip if `--exclude` is used) easily whole family of related tests with a
single command line argument.

For example consider test suite `test_example` which implements tests `foo-1`,
`foo-2`, `foomatic`, `bar-1` and `bar-10`:
Expand Down
16 changes: 16 additions & 0 deletions examples/c-example.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,20 @@ test_fail(void)
TEST_MSG("b: %d", b);
}

void
test_skip(void)
{
TEST_SKIP("Decided to skip.");
TEST_CHECK(1 == 0); /* ignored check. */
}

void
test_bad_skip(void)
{
TEST_CHECK(1 == 1);
TEST_SKIP("Decided to skip."); /* Cannot skip after any TEST_CHECK */
}

static void
helper(void)
{
Expand Down Expand Up @@ -75,6 +89,8 @@ test_crash(void)
TEST_LIST = {
{ "tutorial", test_tutorial },
{ "fail", test_fail },
{ "skip", test_skip },
{ "bad-skip", test_bad_skip },
{ "abort", test_abort },
{ "crash", test_crash },
{ NULL, NULL }
Expand Down
Loading

0 comments on commit 5ec4780

Please sign in to comment.