Skip to content

Commit 910e2b3

Browse files
avargitster
authored andcommitted
run-command tests: use "return", not "exit"
Change the "run-command" test helper to "return" instead of calling "exit", see 338abb0 (builtins + test helpers: use return instead of exit() in cmd_*, 2021-06-08) Because we'd previously gotten past the SANITIZE=leak check by using exit() here we need to move to "goto cleanup" pattern. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7dd5762 commit 910e2b3

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

t/helper/test-run-command.c

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,14 @@ int cmd__run_command(int argc, const char **argv)
381381
{
382382
struct child_process proc = CHILD_PROCESS_INIT;
383383
int jobs;
384+
int ret;
384385

385386
if (argc > 1 && !strcmp(argv[1], "testsuite"))
386-
exit(testsuite(argc - 1, argv + 1));
387+
return testsuite(argc - 1, argv + 1);
387388
if (!strcmp(argv[1], "inherited-handle"))
388-
exit(inherit_handle(argv[0]));
389+
return inherit_handle(argv[0]);
389390
if (!strcmp(argv[1], "inherited-handle-child"))
390-
exit(inherit_handle_child());
391+
return inherit_handle_child();
391392

392393
if (argc >= 2 && !strcmp(argv[1], "quote-stress-test"))
393394
return !!quote_stress_test(argc - 1, argv + 1);
@@ -404,18 +405,24 @@ int cmd__run_command(int argc, const char **argv)
404405
argv += 2;
405406
argc -= 2;
406407
}
407-
if (argc < 3)
408-
return 1;
408+
if (argc < 3) {
409+
ret = 1;
410+
goto cleanup;
411+
}
409412
strvec_pushv(&proc.args, (const char **)argv + 2);
410413

411414
if (!strcmp(argv[1], "start-command-ENOENT")) {
412-
if (start_command(&proc) < 0 && errno == ENOENT)
413-
return 0;
415+
if (start_command(&proc) < 0 && errno == ENOENT) {
416+
ret = 0;
417+
goto cleanup;
418+
}
414419
fprintf(stderr, "FAIL %s\n", argv[1]);
415420
return 1;
416421
}
417-
if (!strcmp(argv[1], "run-command"))
418-
exit(run_command(&proc));
422+
if (!strcmp(argv[1], "run-command")) {
423+
ret = run_command(&proc);
424+
goto cleanup;
425+
}
419426

420427
if (!strcmp(argv[1], "--ungroup")) {
421428
argv += 1;
@@ -436,8 +443,12 @@ int cmd__run_command(int argc, const char **argv)
436443
run_processes_parallel(jobs, no_job, NULL, task_finished,
437444
&proc);
438445
} else {
446+
ret = 1;
439447
fprintf(stderr, "check usage\n");
440-
return 1;
448+
goto cleanup;
441449
}
442-
exit(0);
450+
ret = 0;
451+
cleanup:
452+
child_process_clear(&proc);
453+
return ret;
443454
}

0 commit comments

Comments
 (0)