Skip to content

Fix formatting in quiet mode #116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions clar.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ static struct {

enum cl_output_format output_format;

int report_errors_only;
int exit_on_error;
int verbosity;

Expand Down Expand Up @@ -351,11 +350,7 @@ clar_run_test(
_clar.local_cleanup = NULL;
_clar.local_cleanup_payload = NULL;

if (_clar.report_errors_only) {
clar_report_errors(_clar.last_report);
} else {
clar_print_ontest(suite->name, test->name, _clar.tests_ran, _clar.last_report->status);
}
clar_print_ontest(suite->name, test->name, _clar.tests_ran, _clar.last_report->status);
}

static void
Expand All @@ -372,8 +367,7 @@ clar_run_suite(const struct clar_suite *suite, const char *filter)
if (_clar.exit_on_error && _clar.total_errors)
return;

if (!_clar.report_errors_only)
clar_print_onsuite(suite->name, ++_clar.suites_ran);
clar_print_onsuite(suite->name, ++_clar.suites_ran);

_clar.active_suite = suite->name;
_clar.active_test = NULL;
Expand Down Expand Up @@ -440,7 +434,7 @@ clar_usage(const char *arg)
printf(" -iname Include the suite with `name`\n");
printf(" -xname Exclude the suite with `name`\n");
printf(" -v Increase verbosity (show suite names)\n");
printf(" -q Only report tests that had an error\n");
printf(" -q Decrease verbosity, inverse to -v\n");
printf(" -Q Quit as soon as a test fails\n");
printf(" -t Display results in tap format\n");
printf(" -l Print suite names\n");
Expand Down Expand Up @@ -532,7 +526,7 @@ clar_parse_args(int argc, char **argv)
if (argument[2] != '\0')
clar_usage(argv[0]);

_clar.report_errors_only = 1;
_clar.verbosity--;
break;

case 'Q':
Expand Down
36 changes: 25 additions & 11 deletions clar/print.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
static void clar_print_clap_init(int test_count, int suite_count, const char *suite_names)
{
(void)test_count;

if (_clar.verbosity < 0)
return;

printf("Loaded %d suites: %s\n", (int)suite_count, suite_names);
printf("Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')\n");
}
Expand All @@ -13,7 +17,8 @@ static void clar_print_clap_shutdown(int test_count, int suite_count, int error_
(void)suite_count;
(void)error_count;

printf("\n\n");
if (_clar.verbosity >= 0)
printf("\n\n");
clar_report_all();
}

Expand Down Expand Up @@ -57,6 +62,9 @@ static void clar_print_clap_ontest(const char *suite_name, const char *test_name
(void)test_name;
(void)test_number;

if (_clar.verbosity < 0)
return;

if (_clar.verbosity > 1) {
printf("%s::%s: ", suite_name, test_name);

Expand All @@ -80,6 +88,8 @@ static void clar_print_clap_ontest(const char *suite_name, const char *test_name

static void clar_print_clap_onsuite(const char *suite_name, int suite_index)
{
if (_clar.verbosity < 0)
return;
if (_clar.verbosity == 1)
printf("\n%s", suite_name);

Expand Down Expand Up @@ -143,18 +153,20 @@ static void clar_print_tap_ontest(const char *suite_name, const char *test_name,
case CL_TEST_FAILURE:
printf("not ok %d - %s::%s\n", test_number, suite_name, test_name);

printf(" ---\n");
printf(" reason: |\n");
clar_print_indented(error->error_msg, 6);
if (_clar.verbosity >= 0) {
printf(" ---\n");
printf(" reason: |\n");
clar_print_indented(error->error_msg, 6);

if (error->description)
clar_print_indented(error->description, 6);
if (error->description)
clar_print_indented(error->description, 6);

printf(" at:\n");
printf(" file: '"); print_escaped(error->file); printf("'\n");
printf(" line: %" PRIuMAX "\n", error->line_number);
printf(" function: '%s'\n", error->function);
printf(" ---\n");
printf(" at:\n");
printf(" file: '"); print_escaped(error->file); printf("'\n");
printf(" line: %" PRIuMAX "\n", error->line_number);
printf(" function: '%s'\n", error->function);
printf(" ---\n");
}

break;
case CL_TEST_SKIP:
Expand All @@ -168,6 +180,8 @@ static void clar_print_tap_ontest(const char *suite_name, const char *test_name,

static void clar_print_tap_onsuite(const char *suite_name, int suite_index)
{
if (_clar.verbosity < 0)
return;
printf("# start of suite %d: %s\n", suite_index, suite_name);
}

Expand Down
2 changes: 1 addition & 1 deletion test/expected/help
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Options:
-iname Include the suite with `name`
-xname Exclude the suite with `name`
-v Increase verbosity (show suite names)
-q Only report tests that had an error
-q Decrease verbosity, inverse to -v
-Q Quit as soon as a test fails
-t Display results in tap format
-l Print suite names
Expand Down
53 changes: 0 additions & 53 deletions test/expected/quiet
Original file line number Diff line number Diff line change
@@ -1,56 +1,3 @@
Loaded 1 suites:
Started (test status codes: OK='.' FAILURE='F' SKIPPED='S')
1) Failure:
selftest::suite::1 [file:42]
Function call failed: -1

1) Failure:
selftest::suite::2 [file:42]
Expression is not true: 100 == 101

1) Failure:
selftest::suite::strings [file:42]
String mismatch: "mismatched" != actual ("this one fails")
'mismatched' != 'expected' (at byte 0)

1) Failure:
selftest::suite::strings_with_length [file:42]
String mismatch: "exactly" != actual ("this one fails")
'exa' != 'exp' (at byte 2)

1) Failure:
selftest::suite::int [file:42]
101 != value ("extra note on failing test")
101 != 100

1) Failure:
selftest::suite::int_fmt [file:42]
022 != value
0022 != 0144

1) Failure:
selftest::suite::bool [file:42]
0 != value
0 != 1

1) Failure:
selftest::suite::ptr [file:42]
Pointer mismatch: p1 != p2
0x1 != 0x2

1) Failure:
selftest::suite::multiline_description [file:42]
Function call failed: -1
description line 1
description line 2

1) Failure:
selftest::suite::null_string [file:42]
String mismatch: "expected" != actual ("this one fails")
'expected' != NULL



1) Failure:
selftest::suite::1 [file:42]
Function call failed: -1
Expand Down