Skip to content

Commit 63f0a6c

Browse files
committed
test(parse-coverage): free the extraction results in the DeusData#1610 tests
LeakSanitizer on CI caught all five new tests leaking their CBMFileResult: Indirect leak of 24 byte(s) ... ts_tree_new cbm_extract_file_ex cbm.c:1256 do_extract test_parse_coverage.c:39 test_dockerfile_missing_final_newline_not_flagged_issue1610:272 SUMMARY: AddressSanitizer: 706504 byte(s) leaked in 189 allocation(s) Every pre-existing test in this suite calls cbm_free_result before PASS; the new ones did not. The local run could not have found it - LeakSanitizer reports "detect_leaks is not supported on this platform" on macOS arm64, so this class of defect is CI-only here. Each test now captures what it asserts, frees, and only then decides, so the early-FAIL paths do not leak either. The cross-grammar loop prints its diagnostic before freeing so the failure message keeps naming the grammar. While correcting the guard, a first attempt left ASSERT_TRUE(flagged || has_ranges || true) in real_error_before_eof_still_flagged - always true, and it would have silently disarmed the guard that stops the EOF suppression from being over-broad. Removed. The guard is re-proven binding: forcing cbm_is_eof_terminator_miss to return true makes EIGHT tests fail, including both guards, and restoring it returns the suite to green. parse_coverage 14 passed. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 8669ba8 commit 63f0a6c

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

‎tests/test_parse_coverage.c‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,10 @@ TEST(dockerfile_missing_final_newline_not_flagged_issue1610) {
272272
CBMFileResult *r = do_extract(src, CBM_LANG_DOCKERFILE, "Dockerfile");
273273
ASSERT_NOT_NULL(r);
274274
bool flagged = r->parse_incomplete;
275-
const char *ranges = r->error_ranges;
275+
cbm_free_result(r);
276276
if (flagged) {
277277
FAIL("a Dockerfile lacking only its final newline must not be parse_partial");
278278
}
279-
(void)ranges;
280279
PASS();
281280
}
282281

@@ -288,7 +287,9 @@ TEST(dockerfile_with_final_newline_still_clean_issue1610) {
288287
"ENTRYPOINT [\"dotnet\", \"App.dll\"]\n";
289288
CBMFileResult *r = do_extract(src, CBM_LANG_DOCKERFILE, "Dockerfile");
290289
ASSERT_NOT_NULL(r);
291-
if (r->parse_incomplete) {
290+
bool flagged = r->parse_incomplete;
291+
cbm_free_result(r);
292+
if (flagged) {
292293
FAIL("a terminated Dockerfile must not be parse_partial");
293294
}
294295
PASS();
@@ -310,9 +311,13 @@ TEST(missing_final_newline_not_flagged_across_grammars_issue1610) {
310311
for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {
311312
CBMFileResult *r = do_extract(cases[i].src, cases[i].lang, cases[i].path);
312313
ASSERT_NOT_NULL(r);
313-
if (r->parse_incomplete) {
314+
bool flagged = r->parse_incomplete;
315+
if (flagged) {
314316
fprintf(stderr, " %s flagged: ranges=%s\n", cases[i].path,
315317
r->error_ranges ? r->error_ranges : "(none)");
318+
}
319+
cbm_free_result(r);
320+
if (flagged) {
316321
FAIL("an unterminated final line must not be parse_partial in any grammar");
317322
}
318323
}
@@ -335,11 +340,11 @@ TEST(real_error_before_eof_still_flagged_without_final_newline_issue1610) {
335340
unterminated[n - 1] = '\0'; /* drop the final newline */
336341

337342
CBMFileResult *r = do_extract(unterminated, CBM_LANG_C, "split.c");
338-
bool flagged = r && r->parse_incomplete;
339-
bool has_ranges = r && r->error_ranges != NULL;
340343
free(unterminated);
341-
342344
ASSERT_NOT_NULL(r);
345+
bool flagged = r->parse_incomplete;
346+
bool has_ranges = r->error_ranges != NULL;
347+
cbm_free_result(r);
343348
if (!flagged) {
344349
FAIL("a real mid-file parse failure must still be reported when the file also lacks its final newline");
345350
}
@@ -356,7 +361,9 @@ TEST(width_bearing_error_at_eof_still_flagged_issue1610) {
356361
const char *src = "all:\n\techo hi"; /* no trailing newline; recipe is lost */
357362
CBMFileResult *r = do_extract(src, CBM_LANG_MAKEFILE, "Makefile");
358363
ASSERT_NOT_NULL(r);
359-
if (!r->parse_incomplete) {
364+
bool flagged = r->parse_incomplete;
365+
cbm_free_result(r);
366+
if (!flagged) {
360367
FAIL("a width-bearing parse failure at EOF must still be reported");
361368
}
362369
PASS();

0 commit comments

Comments
 (0)