Prettier output and some fixes (#4)
* feat: tab results * feat: more colors * style: norm * fix: patch a spacing bug * fix: patch a small issue * fix: patch some leaks * style: norm
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2026/01/24 12:43:35 by dgaillet #+# #+# */
|
||||
/* Updated: 2026/01/25 15:15:05 by elagouch ### ########.fr */
|
||||
/* Updated: 2026/01/25 18:15:25 by elagouch ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -16,39 +16,49 @@
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int parent_helper(int ffd, struct s_helper *h, const char *fn_name,
|
||||
static int parent_helper(int ffd, struct s_helper *h, const char *fn_name,
|
||||
t_unit_test *test_list)
|
||||
{
|
||||
int status;
|
||||
int status;
|
||||
int ffdst[2];
|
||||
pid_t caught_pid;
|
||||
|
||||
h->wpid = waitpid(h->wpid, &status, WCONTINUED);
|
||||
if (h->wpid < 0)
|
||||
return (-1);
|
||||
h->ok_tests += interpret_status(ffd, status, fn_name, get_test_at(test_list,
|
||||
h->i)->title);
|
||||
caught_pid = 0;
|
||||
while (caught_pid != h->wpid)
|
||||
{
|
||||
caught_pid = wait(&status);
|
||||
if (caught_pid < 0)
|
||||
return (-1);
|
||||
}
|
||||
ffdst[0] = ffd;
|
||||
ffdst[1] = status;
|
||||
h->ok_tests += interpret_status(ffdst, fn_name, get_test_at(test_list,
|
||||
h->i)->title, test_list->max_len);
|
||||
return (0);
|
||||
}
|
||||
|
||||
int child_helper(t_unit_test *test_list, t_h h)
|
||||
static int child_helper(t_unit_test *test_list, t_h h, int ffd)
|
||||
{
|
||||
int fd;
|
||||
int res;
|
||||
t_unit_test *test;
|
||||
int fd;
|
||||
int res;
|
||||
t_unit_test *test;
|
||||
|
||||
fd = open("/dev/null", O_WRONLY);
|
||||
if (!fd)
|
||||
return (-1);
|
||||
fd = open("/dev/null", O_WRONLY);
|
||||
if (!fd)
|
||||
return (-1);
|
||||
if (dup2(fd, STDOUT_FILENO) < 0)
|
||||
return (-1);
|
||||
test = get_test_at(test_list, h.i);
|
||||
if (test->timeout)
|
||||
alarm(test->timeout);
|
||||
return (-1);
|
||||
test = get_test_at(test_list, h.i);
|
||||
if (test->timeout)
|
||||
alarm(test->timeout);
|
||||
res = test->func();
|
||||
close(fd);
|
||||
exit(res);
|
||||
close(fd);
|
||||
close(ffd);
|
||||
clear_tests(&test_list);
|
||||
exit(res);
|
||||
}
|
||||
|
||||
int handle_out(const char *fn_name)
|
||||
static int handle_out(const char *fn_name)
|
||||
{
|
||||
char *tmp;
|
||||
int fd;
|
||||
@@ -70,18 +80,20 @@ int launch_tests(t_unit_test *test_list, const char *fn_name)
|
||||
h.i = -1;
|
||||
ffd = handle_out(fn_name);
|
||||
if (ffd < 0)
|
||||
return (1);
|
||||
return (-1);
|
||||
while (++h.i < (int)count_tests(test_list))
|
||||
{
|
||||
h.wpid = fork();
|
||||
if (h.wpid < 0)
|
||||
return (1);
|
||||
else if (h.wpid == 0 && child_helper(test_list, h) < 0)
|
||||
return (1);
|
||||
return (-1);
|
||||
else if (h.wpid == 0 && child_helper(test_list, h, ffd) < 0)
|
||||
return (-1);
|
||||
else if (parent_helper(ffd, &h, fn_name, test_list))
|
||||
return (1);
|
||||
return (-1);
|
||||
}
|
||||
print_passed_test(ffd, h.ok_tests, test_list);
|
||||
close(ffd);
|
||||
if (h.ok_tests != count_tests(test_list))
|
||||
return (-1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user