Skip to content

Commit 51686ea

Browse files
add assert count to introspect
1 parent 7ef43eb commit 51686ea

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

code/include/fossil/unittest/internal.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ typedef struct {
224224
bool shoudl_timeout; /**< Flag indicating whether the test case should timeout (1 for true, 0 for false). */
225225
bool should_fail; /**< Flag indicating whether the test case should fail (1 for true, 0 for false). */
226226
bool has_assert; /**< Flag indicating if an assertion occurred (1 for true, 0 for false). */
227+
int32_t num_asserts; /**< Number of assertions that occurred. */
227228
int32_t line; /**< Line number where the assertion occurred. */
228229
char *func; /**< Function name where the assertion occurred. */
229230
char *file; /**< File name where the assertion occurred. */

code/source/unittest/console.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,15 @@ void fossil_test_io_unittest_then(char *description) {
402402

403403
void fossil_test_io_unittest_step(xassert_info *assume) {
404404
if (_CLI.verbose_level == 2) {
405-
fossil_test_cout("blue", "has assert: ");
405+
fossil_test_cout("blue", "has assert : ");
406406
fossil_test_cout("cyan", " -> %s\n", assume->has_assert ? COLOR_GREEN "has assertions" COLOR_RESET : COLOR_RED "missing assertions" COLOR_RESET);
407+
fossil_test_cout("blue", "asserts used: ");
408+
fossil_test_cout("cyan", COLOR_GREEN "%3i\n" COLOR_RESET , assume->num_asserts);
407409
} else if (_CLI.verbose_level == 1) {
408-
fossil_test_cout("blue", "[intro] has_assert: ");
410+
fossil_test_cout("blue", "[intro] has_assert : ");
409411
fossil_test_cout("cyan", "%s\n", assume->has_assert ? COLOR_GREEN "yes" COLOR_RESET : COLOR_RED "no" COLOR_RESET);
412+
fossil_test_cout("blue", "[intro] num_asserts: ");
413+
fossil_test_cout("cyan", COLOR_GREEN "%3i\n" COLOR_RESET , assume->num_asserts);
410414
}
411415
}
412416

code/source/unittest/unittest.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,7 @@ void fossil_test_run_testcase(fossil_test_t *test) {
391391
_ASSERT_INFO.has_assert = false;
392392
_ASSERT_INFO.should_fail = false;
393393
_ASSERT_INFO.shoudl_timeout = false;
394+
_ASSERT_INFO.num_asserts = 0;
394395

395396
if (_TEST_ENV.rule.skipped && strcmp(test->marks, "skip") == 0) {
396397
return;
@@ -720,5 +721,6 @@ void _fossil_test_assert_class(bool expression, xassert_type_t behavor, char* me
720721
} else if (behavor == TEST_ASSERT_AS_CLASS_EXPECT) {
721722
fossil_test_assert_impl_expect(expression, &_ASSERT_INFO);
722723
}
724+
_ASSERT_INFO.num_asserts++; // increment the number of asserts
723725
_ASSERT_INFO.has_assert = true; // Make note of an assert being added in a given test case
724726
}

0 commit comments

Comments
 (0)