@@ -16,6 +16,20 @@ Organization: Fossil Logic
1616#include "fossil/unittest/commands.h"
1717#include <stdarg.h>
1818
19+ #define MAX_ASSERT_HISTORY 100
20+
21+ typedef struct {
22+ bool expression ;
23+ xassert_type_t behavior ;
24+ char * message ;
25+ char * file ;
26+ int line ;
27+ char * func ;
28+ } assert_history_t ;
29+
30+ static assert_history_t assert_history [MAX_ASSERT_HISTORY ];
31+ static int assert_history_count = 0 ;
32+
1933fossil_env_t _TEST_ENV ;
2034xassert_info _ASSERT_INFO ;
2135
@@ -392,6 +406,7 @@ void fossil_test_run_testcase(fossil_test_t *test) {
392406 _ASSERT_INFO .should_fail = false;
393407 _ASSERT_INFO .shoudl_timeout = false;
394408 _ASSERT_INFO .num_asserts = 0 ;
409+ _ASSERT_INFO .same_assert = false;
395410
396411 if (_TEST_ENV .rule .skipped && strcmp (test -> marks , "skip" ) == 0 ) {
397412 return ;
@@ -708,19 +723,51 @@ void fossil_test_assert_impl_expect(bool expression, xassert_info *assume) {
708723 }
709724} // end of func
710725
711- void _fossil_test_assert_class (bool expression , xassert_type_t behavor , char * message , char * file , int line , char * func ) {
726+ bool is_assert_in_history (bool expression , xassert_type_t behavior , char * message , char * file , int line , char * func ) {
727+ for (int i = 0 ; i < assert_history_count ; i ++ ) {
728+ if (assert_history [i ].expression == expression &&
729+ assert_history [i ].behavior == behavior &&
730+ strcmp (assert_history [i ].message , message ) == 0 &&
731+ strcmp (assert_history [i ].file , file ) == 0 &&
732+ assert_history [i ].line == line &&
733+ strcmp (assert_history [i ].func , func ) == 0 ) {
734+ return true;
735+ }
736+ }
737+ return false;
738+ }
739+
740+ void _fossil_test_assert_class (bool expression , xassert_type_t behavior , char * message , char * file , int line , char * func ) {
741+ if (is_assert_in_history (expression , behavior , message , file , line , func )) {
742+ // Skip the assertion as it has already been executed
743+ _ASSERT_INFO .same_assert = true;
744+ return ;
745+ }
746+
712747 _ASSERT_INFO .func = func ;
713748 _ASSERT_INFO .file = file ;
714749 _ASSERT_INFO .line = line ;
715750 _ASSERT_INFO .message = message ;
716751
717- if (behavor == TEST_ASSERT_AS_CLASS_ASSUME ) {
752+ if (behavior == TEST_ASSERT_AS_CLASS_ASSUME ) {
718753 fossil_test_assert_impl_assume (expression , & _ASSERT_INFO );
719- } else if (behavor == TEST_ASSERT_AS_CLASS_ASSERT ) {
754+ } else if (behavior == TEST_ASSERT_AS_CLASS_ASSERT ) {
720755 fossil_test_assert_impl_assert (expression , & _ASSERT_INFO );
721- } else if (behavor == TEST_ASSERT_AS_CLASS_EXPECT ) {
756+ } else if (behavior == TEST_ASSERT_AS_CLASS_EXPECT ) {
722757 fossil_test_assert_impl_expect (expression , & _ASSERT_INFO );
723758 }
759+
724760 _ASSERT_INFO .num_asserts ++ ; // increment the number of asserts
725761 _ASSERT_INFO .has_assert = true; // Make note of an assert being added in a given test case
762+
763+ // Add the assertion to the history
764+ if (assert_history_count < MAX_ASSERT_HISTORY ) {
765+ assert_history [assert_history_count ].expression = expression ;
766+ assert_history [assert_history_count ].behavior = behavior ;
767+ assert_history [assert_history_count ].message = message ;
768+ assert_history [assert_history_count ].file = file ;
769+ assert_history [assert_history_count ].line = line ;
770+ assert_history [assert_history_count ].func = func ;
771+ assert_history_count ++ ;
772+ }
726773}
0 commit comments