Skip to content

Commit 6c8648d

Browse files
merged anomaly into internal assert
1 parent d51fc14 commit 6c8648d

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

code/logic/testing.c

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -551,39 +551,30 @@ void fossil_test_run_suite(fossil_test_suite_t *suite, fossil_test_env_t *env) {
551551
}
552552
}
553553

554-
// Function to detect assertion anomalies
555-
bool fossil_test_detect_anomaly(const char *message, const char *file, int line, const char *func) {
554+
// Internal function to handle assertions with anomaly detection
555+
void fossil_test_assert_internal(bool condition, const char *message, const char *file, int line, const char *func) {
556556
static const char *last_message = NULL; // Store the last assertion message
557557
static const char *last_file = NULL; // Store the last file name
558558
static int last_line = 0; // Store the last line number
559559
static const char *last_func = NULL; // Store the last function name
560560
static int anomaly_count = 0; // Counter for anomaly detection
561561

562-
// Check if the current assertion is the same or similar to the last one
563-
if (last_message && strstr(message, last_message) != NULL &&
564-
last_file && strcmp(last_file, file) == 0 &&
565-
last_line == line &&
566-
last_func && strcmp(last_func, func) == 0) {
567-
anomaly_count++;
568-
return true;
569-
} else {
570-
anomaly_count = 0; // Reset anomaly count for new assertion
571-
last_message = message;
572-
last_file = file;
573-
last_line = line;
574-
last_func = func;
575-
return false;
576-
}
577-
}
578-
579-
// Internal function to handle assertions with anomaly detection
580-
void fossil_test_assert_internal(bool condition, const char *message, const char *file, int line, const char *func) {
581562
_ASSERT_COUNT++; // Increment the assertion count
582563

583564
if (!condition) {
584-
if (fossil_test_detect_anomaly(message, file, line, func)) {
565+
// Check if the current assertion is the same or similar to the last one
566+
if (last_message && strstr(message, last_message) != NULL &&
567+
last_file && strcmp(last_file, file) == 0 &&
568+
last_line == line &&
569+
last_func && strcmp(last_func, func) == 0) {
570+
anomaly_count++;
585571
printf(FOSSIL_TEST_COLOR_YELLOW "Duplicate or similar assertion detected: %s (%s:%d in %s)\n" FOSSIL_TEST_COLOR_RESET, message, file, line, func);
586572
} else {
573+
anomaly_count = 0; // Reset anomaly count for new assertion
574+
last_message = message;
575+
last_file = file;
576+
last_line = line;
577+
last_func = func;
587578
printf(FOSSIL_TEST_COLOR_RED "Assertion failed: %s (%s:%d in %s)\n" FOSSIL_TEST_COLOR_RESET, message, file, line, func);
588579
}
589580

0 commit comments

Comments
 (0)