The reftable library comes with self tests, which are exercised as part of the usual end-to-end tests and are designed to observe the end-user visible effects of Git commands. What it exercises, however, is a better match for the unit-testing framework, merged at 8bf6fbd0 (Merge branch 'js/doc-unit-tests', 2023-12-09), which is designed to observe how low level implementation details, at the level of sequences of individual function calls, behave. Hence, port reftable/stack_test.c to the unit testing framework and improve upon the ported test. The first patch in the series moves the test to the unit testing framework, and the rest of the patches improve upon the ported test. Mentored-by: Patrick Steinhardt <ps@xxxxxx> Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx> Signed-off-by: Chandra Pratap <chandrapratap3519@xxxxxxxxx> --- Changes in v5: - Edit the commit messages in patches 3 and 4 to reflect the changes and the motivation behind those changes better. - Add newlines after variable declarations in patch 6. - Introduce patch 7 which removes leftover cruft from the previous reftable testing scheme. CI/PR: https://github.com/gitgitgadget/git/pull/1762 Chandra Pratap(7): t: move reftable/stack_test.c to the unit testing framework t: harmonize t-reftable-stack.c with coding guidelines t-reftable-stack: use Git's tempfile API instead of mkstemp() t-reftable-stack: use reftable_ref_record_equal() to compare ref records t-reftable-stack: add test for non-default compaction factor t-reftable-stack: add test for stack iterators t: clean up leftover reftable test cruft Makefile | 4 +- reftable/reftable-tests.h | 14 - reftable/test_framework.c | 27 - reftable/test_framework.h | 61 -- t/helper/test-reftable.c | 8 - t/helper/test-tool.c | 3 +- t/helper/test-tool.h | 1 - t/t0032-reftable-unittest.sh | 16 - .../unit-tests/t-reftable-stack.c | 665 ++++++++++++--------- 9 files changed, 390 insertions(+), 409 deletions(-) Range-diff against v4: 1: eae681f53d ! 1: ca4b00feef t-reftable-stack: use Git's tempfile API instead of mkstemp() @@ Commit message like mkstemp(), make the ported stack test strictly use Git's tempfile API as well. + A bigger benefit is the fact that we know to clean up the tempfile + in case the test fails because it gets registered and pruned via a + signal handler. + Mentored-by: Patrick Steinhardt <ps@xxxxxx> Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx> Signed-off-by: Chandra Pratap <chandrapratap3519@xxxxxxxxx> 2: 19b2f41003 ! 2: 3e723667dd t-reftable-stack: use reftable_ref_record_equal() to compare ref records @@ Commit message reftable_ref_record_equal(), and sometimes by explicity comparing contents of the ref records. - Replace the latter instances of ref-record comparison with the - former to maintain uniformity throughout the test file. + The latter method is undesired because there can exist unequal ref + records with the some of the contents being equal. Replace the latter + instances of ref-record comparison with the former. This has the + added benefit of preserving uniformity throughout the test file. Mentored-by: Patrick Steinhardt <ps@xxxxxx> Mentored-by: Christian Couder <chriscool@xxxxxxxxxxxxx> 3: ffdfba6b98 = 3: 7526550c92 t-reftable-stack: add test for non-default compaction factor 4: ca447664e7 ! 4: 05e4b7e715 t-reftable-stack: add test for stack iterators @@ t/unit-tests/t-reftable-stack.c: static void t_reftable_stack_add(void) + .log = &logs[i], + .update_index = reftable_stack_next_update_index(st), + }; ++ + err = reftable_stack_add(st, write_test_log, &arg); + check(!err); + } @@ t/unit-tests/t-reftable-stack.c: static void t_reftable_stack_add(void) + reftable_iterator_seek_ref(&it, refs[0].refname); + for (i = 0; ; i++) { + struct reftable_ref_record ref = { 0 }; ++ + err = reftable_iterator_next_ref(&it, &ref); + if (err > 0) + break; @@ t/unit-tests/t-reftable-stack.c: static void t_reftable_stack_add(void) + reftable_iterator_seek_log(&it, logs[0].refname); + for (i = 0; ; i++) { + struct reftable_log_record log = { 0 }; ++ + err = reftable_iterator_next_log(&it, &log); + if (err > 0) + break; -: ---------- > 5: 43c1a522fb t: clean up leftover reftable test cruft