Files
libakstdlib/tests/test_list_append_chain.c

60 lines
1.6 KiB
C
Raw Normal View History

Build a real test harness (TODO.md section 1.0) The suite could not fail and did not run. test_linkedlist.c asserted nothing at all -- it printed node names and returned 0 -- so every confirmed list defect passed it. test_tree.c was red on every run because parms.steps was never reset between its three searches, and four libakerror tests registered but never built, reporting Not Run. CI, meanwhile, was not fetching the submodule, so configure failed before reaching any of it. - tests/aksl_capture.h: AKSL_CHECK (NDEBUG-proof), AKSL_CHECK_STATUS/_OK to run an akerror-returning call, assert its status and release the context, a capturing akerr_log_method, aksl_slots_in_use(), and an AKSL_RUN driver that fails any test leaking an error-pool slot. - test_linkedlist.c: rewritten as 15 assertion cases over the append, iterate and pop behaviour that is correct today. - test_tree.c: each search builds its own tree and params. - Registration driven by AKSL_TESTS, plus AKSL_WILL_FAIL_TESTS (aborts by design) and AKSL_KNOWN_FAILING_TESTS, which marks WILL_FAIL the three new tests asserting correct behaviour for the confirmed defects in TODO.md 2.1.1-2.1.3. Fixing a defect flips its test to "unexpectedly passed", which is the cue to promote it into AKSL_TESTS. - add_test/set_tests_properties are shadowed across the libakerror add_subdirectory call: CMake cannot un-register a test and set_tests_properties cannot cross directory scopes. The dependency has its own CI. - AKSL_SANITIZE=ON builds library, tests and dependency with ASan+UBSan. - scripts/mutation_test.py ported and retargeted at src/stdlib.c; wired to a manual `mutation` target, not a CI gate until 1.1-1.9 exist. - CI: checkout with submodules: recursive, and ctest --output-on-failure. ctest is now 5/5 green in both the default and sanitizer builds. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-28 12:39:54 -04:00
/*
* KNOWN FAILING -- TODO.md section 2.1.1
*
* aksl_list_append conflates Floyd cycle detection with finding the tail: the
* `tail` cursor is assigned from `slow` *before* `slow` advances, so it tracks
* the node behind the list midpoint rather than the last node. Appending to any
* list of two or more nodes therefore overwrites an interior link and silently
* drops every node after it.
*
* Appending n1..n4 to n0 produces the chain "n0 -> n4"; this test asserts the
* correct "n0 -> n1 -> n2 -> n3 -> n4" and so fails until append is fixed.
* It is registered in AKSL_KNOWN_FAILING_TESTS, which marks it WILL_FAIL; when
* the fix lands, CTest will report it as unexpectedly passing, which is the
* signal to move it into AKSL_TESTS.
*/
#include "aksl_capture.h"
#define CHAIN_LEN 5
static int test_append_builds_full_chain(void)
{
aksl_ListNode node[CHAIN_LEN];
aksl_ListNode *walk = NULL;
int i = 0;
memset((void *)node, 0x00, sizeof(node));
for ( i = 1; i < CHAIN_LEN; i++ ) {
AKSL_CHECK_OK(aksl_list_append(&node[0], &node[i]));
}
/* Forward links, head to tail. */
walk = &node[0];
for ( i = 0; i < CHAIN_LEN; i++ ) {
AKSL_CHECK(walk == &node[i]);
walk = walk->next;
}
AKSL_CHECK(walk == NULL);
/* Back links, tail to head. */
walk = &node[CHAIN_LEN - 1];
for ( i = CHAIN_LEN - 1; i >= 0; i-- ) {
AKSL_CHECK(walk == &node[i]);
walk = walk->prev;
}
AKSL_CHECK(walk == NULL);
return 0;
}
int main(void)
{
int failures = 0;
akerr_init();
AKSL_RUN(failures, test_append_builds_full_chain);
AKSL_REPORT(failures);
}