logoalt Hacker News

cb32112/09/20241 replyview on HN

If you are in a tribe not hating on pp-macros, you might find this approach for testing/debugging data structures (or even the surrounding pp-based "CTL"-like C templating idea or abstract ways of dealing with the BST zoo) interesting:

    https://github.com/c-blake/bst/blob/main/test/bst-interact.c
Essentially, you just write a very simple (some might say trivial) interactive command-shell that can include an auto-checking upon edit of (in that case tree) invariants keyed-off an environment variable. The only missing piece is some little tool to generate random inserts/deletes/etc.

If the micro-shell has a pretty printer then it is easy to "replay" any failed series of edits with some "p" commands before & after invariant failures.


Replies

eqvinox12/09/2024

This is incredibly funny to me, because that's (almost) exactly how some of our other tests work :D

(Almost: we have a full-featured command shell and just use that for testing)

Shell bindings: https://github.com/FRRouting/frr/blob/master/tests/ospf6d/te...

Input: https://github.com/FRRouting/frr/blob/master/tests/ospf6d/te...

Expected output: https://github.com/FRRouting/frr/blob/master/tests/ospf6d/te...

Absolutely agree this is a great option to have for some kinds of tests.

show 1 reply