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:
Erwann Lagouche
2026-01-25 18:20:20 +01:00
committed by GitHub
parent d8824f7890
commit 677028dcbb
29 changed files with 225 additions and 166 deletions

View File

@@ -6,63 +6,88 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/25 14:26:54 by elagouch #+# #+# */
/* Updated: 2026/01/25 14:56:06 by elagouch ### ########.fr */
/* Updated: 2026/01/25 17:35:53 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libunit.h"
#include <stdio.h>
static void print_tabbed(int fd1, int fd2, char *s, size_t expected_len)
{
size_t i;
size_t l;
l = ft_strlen(s);
ft_putstr_fd(s, fd1);
ft_putstr_fd(s, fd2);
i = 0;
while (l <= expected_len && i < (expected_len - l))
{
ft_putchar_fd(' ', fd1);
ft_putchar_fd(' ', fd2);
i++;
}
}
static void print_wtermsig(int ffd, int signal)
{
static char *sigs[15];
char *msg;
char *msg;
sigs[4] = "SIGKILL";
sigs[6] = "SIGABRT";
sigs[7] = "SIGBUS";
sigs[8] = "SIGFPE";
sigs[9] = "SIGKILL";
sigs[11] = "SIGSEGV";
sigs[13] = "SIGPIPE";
sigs[14] = "TIMEOUT";
ft_putstr_fd("[\x1B[33m", 1);
ft_putstr_fd("[", ffd);
if ((signal >= 6 && signal <=8) || signal == 4 || signal == 11 || (signal >= 13 && signal <= 14))
msg = sigs[signal];
else
msg = "UNKNOWN";
if ((signal >= 6 && signal <= 9) || signal == 11 || (signal >= 13
&& signal <= 14))
msg = sigs[signal];
else
msg = "UNKNOWN";
ft_putstr_fd(msg, 1);
ft_putstr_fd(msg, ffd);
ft_putstr_fd("\x1B[0m]\n", 1);
ft_putstr_fd("]\n", ffd);
}
size_t interpret_status(int ffd, int status, const char *fn_name,
char *test_name)
static void interpret_status_print(const char *fn_name, int ffd,
char *test_name, size_t max_len)
{
ft_putstr_fd("\x1B[94m", 1);
ft_putstr_fd((char *)fn_name, 1);
ft_putstr_fd((char *)fn_name, ffd);
ft_putstr_fd(" : ", 1);
ft_putstr_fd("\x1B[90m : \x1B[0m", 1);
ft_putstr_fd(" : ", ffd);
ft_putstr_fd(test_name, 1);
ft_putstr_fd(test_name, ffd);
ft_putstr_fd(" : ", 1);
ft_putstr_fd(" : ", ffd);
if (WIFEXITED(status))
print_tabbed(1, ffd, test_name, max_len);
ft_putstr_fd("\x1B[90m : \x1B[0m", 1);
ft_putstr_fd(": ", ffd);
}
size_t interpret_status(int ffdst[2], const char *fn_name, char *test_name,
size_t max_len)
{
interpret_status_print(fn_name, ffdst[0], test_name, max_len);
if (WIFEXITED(ffdst[1]))
{
if (WEXITSTATUS(status))
if (WEXITSTATUS(ffdst[1]))
{
ft_putstr_fd("[\x1B[31m\x1B[1mKO\x1B[0m]\n", 1);
ft_putstr_fd("[KO]\n", ffd);
ft_putstr_fd("[KO]\n", ffdst[0]);
}
else
{
ft_putstr_fd("[\x1B[32mOK\x1B[0m]\n", 1);
ft_putstr_fd("[OK]\n", ffd);
ft_putstr_fd("[OK]\n", ffdst[0]);
return (1);
}
}
else if (WIFSIGNALED(status))
print_wtermsig(ffd, WTERMSIG(status));
else if (WIFSIGNALED(ffdst[1]))
print_wtermsig(ffdst[0], WTERMSIG(ffdst[1]));
return (0);
}
@@ -81,6 +106,6 @@ void print_passed_test(int ffd, size_t ok_tests, t_unit_test *test_list)
ft_putchar_fd('/', ffd);
ft_putnbr_fd((int)total, 1);
ft_putnbr_fd((int)total, ffd);
ft_putstr_fd("\x1B[0m tests succeeded\n\n", 1);
ft_putstr_fd(" tests succeeded\n\n", ffd);
ft_putstr_fd("\x1B[0m tests passed\n\n", 1);
ft_putstr_fd(" tests passed\n\n", ffd);
}