Skip to content

Commit 157fa68

Browse files
authored
Merge pull request #12 from antithesishq/feature-reg-tracker
Feature reg tracker
2 parents dd70a87 + 2279d61 commit 157fa68

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

antithesis_sdk.h

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@
88
#include <random>
99
#include <string>
1010
#include <map>
11+
#include <set>
1112
#include <variant>
1213
#include <vector>
1314

1415
namespace antithesis {
15-
inline const char* SDK_VERSION = "0.3.0";
16+
inline const char* SDK_VERSION = "0.3.1";
1617
inline const char* PROTOCOL_VERSION = "1.0.0";
1718

1819
struct LocalRandom {
@@ -436,6 +437,13 @@ namespace antithesis {
436437
assert_impl(cond, message, details, location_info, hit, must_hit, assert_type, display_type, id);
437438
}
438439

440+
typedef std::set<std::string> CatalogEntryTracker;
441+
442+
inline CatalogEntryTracker& get_catalog_entry_tracker() {
443+
static CatalogEntryTracker catalog_entry_tracker;
444+
return catalog_entry_tracker;
445+
}
446+
439447
struct Assertion {
440448
AssertionState state;
441449
AssertionType type;
@@ -448,13 +456,17 @@ namespace antithesis {
448456
}
449457

450458
void add_to_catalog() const {
451-
const bool condition = (type == REACHABLE_ASSERTION ? true : false);
452-
const bool hit = false;
453-
const char* assert_type = get_assert_type_string(type);
454-
const bool must_hit = get_must_hit(type);
455-
const char* display_type = get_display_type_string(type);
456459
std::string id = make_key(message, location);
457-
assert_impl(condition, message, {}, location, hit, must_hit, assert_type, display_type, id.c_str());
460+
CatalogEntryTracker& tracker = get_catalog_entry_tracker();
461+
if (!tracker.contains(id)) {
462+
tracker.insert(id);
463+
const bool condition = (type == REACHABLE_ASSERTION ? true : false);
464+
const bool hit = false;
465+
const char* assert_type = get_assert_type_string(type);
466+
const bool must_hit = get_must_hit(type);
467+
const char* display_type = get_display_type_string(type);
468+
assert_impl(condition, message, {}, location, hit, must_hit, assert_type, display_type, id.c_str());
469+
}
458470
}
459471

460472
[[clang::always_inline]] inline void check_assertion(bool cond, const JSON& details) {
@@ -478,7 +490,7 @@ namespace antithesis {
478490
emit = true;
479491
state.true_not_seen = false; // TODO: is the race OK?
480492
}
481-
493+
482494
if (emit) {
483495
const bool hit = true;
484496
const char* assert_type = get_assert_type_string(type);

0 commit comments

Comments
 (0)