syle: norm

This commit is contained in:
airone01
2026-01-24 18:56:42 +01:00
parent 932732c1e5
commit 1ee5334149
17 changed files with 108 additions and 160 deletions

View File

@@ -10,16 +10,16 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "libunit.h"
#include "libft/libft.h" #include "libft/libft.h"
#include "libunit.h"
#include <stdlib.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h>
static size_t interpret_status(int status, const char *fn_name static size_t interpret_status(int status, const char *fn_name,
, char *test_name) char *test_name)
{ {
ft_putstr_fd((char *) fn_name, 1); ft_putstr_fd((char *)fn_name, 1);
ft_putstr_fd(" : ", 1); ft_putstr_fd(" : ", 1);
ft_putstr_fd(test_name, 1); ft_putstr_fd(test_name, 1);
ft_putstr_fd(" : ", 1); ft_putstr_fd(" : ", 1);
@@ -45,13 +45,13 @@ static size_t interpret_status(int status, const char *fn_name
static void print_passed_test(size_t ok_tests, t_unit_test *test_list) static void print_passed_test(size_t ok_tests, t_unit_test *test_list)
{ {
size_t total; size_t total;
total = count_tests(test_list); total = count_tests(test_list);
if (ok_tests == total) if (ok_tests == total)
ft_putstr_fd("\x1B[32m", 1); ft_putstr_fd("\x1B[32m", 1);
else else
ft_putstr_fd("\x1B[31m", 1); ft_putstr_fd("\x1B[31m", 1);
ft_putnbr_fd(ok_tests, 1); ft_putnbr_fd(ok_tests, 1);
ft_putchar_fd('/', 1); ft_putchar_fd('/', 1);
ft_putnbr_fd((int)total, 1); ft_putnbr_fd((int)total, 1);
@@ -60,10 +60,10 @@ static void print_passed_test(size_t ok_tests, t_unit_test *test_list)
int launch_tests(t_unit_test *test_list, const char *fn_name) int launch_tests(t_unit_test *test_list, const char *fn_name)
{ {
size_t ok_tests; size_t ok_tests;
pid_t wpid; pid_t wpid;
int status; int status;
int i; int i;
ok_tests = 0; ok_tests = 0;
i = -1; i = -1;
@@ -79,8 +79,8 @@ int launch_tests(t_unit_test *test_list, const char *fn_name)
wpid = wait(&status); wpid = wait(&status);
if (wpid < 0) if (wpid < 0)
return (1); return (1);
ok_tests += interpret_status(status, fn_name, ok_tests += interpret_status(status, fn_name, get_test_at(test_list,
get_test_at(test_list, i)->title); i)->title);
} }
} }
print_passed_test(ok_tests, test_list); print_passed_test(ok_tests, test_list);

View File

@@ -6,12 +6,12 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 14:38:40 by elagouch #+# #+# */ /* Created: 2026/01/24 14:38:40 by elagouch #+# #+# */
/* Updated: 2026/01/24 18:40:36 by elagouch ### ########.fr */ /* Updated: 2026/01/24 18:56:03 by elagouch ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#ifndef UTIL_UNIT_H #ifndef LIBUNIT_H
# define UTIL_UNIT_H # define LIBUNIT_H
# include "libft.h" # include "libft.h"
# include <sys/types.h> # include <sys/types.h>
@@ -66,4 +66,4 @@ void clear_tests(t_unit_test **head_ptr);
int launch_tests(t_unit_test *test_list, int launch_tests(t_unit_test *test_list,
const char *fn_name); const char *fn_name);
#endif // !UTIL_UNIT_H #endif // !LIBUNIT_H

View File

@@ -1,28 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_launcher.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:01:11 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../util_unit.h"
#include "../tests.h"
int strlen_launcher(void) {
t_unit_test *testlist;
size_t res;
testlist = NULL;
load_test(&testlist, "null test", &test_null);
load_test(&testlist, "basic test", &test_basic);
res = launch_tests(testlist, "strlen");
clear_tests(&testlist);
return (res);
}

View File

@@ -1,18 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_basic_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 15:39:06 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int test_basic(void)
{
return (ft_strlen("hello, world") == 12);
}

View File

@@ -1,17 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_null_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:01:12 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int test_null(void) {
return (ft_strlen(NULL) == 0);
}

19
main.c
View File

@@ -1,19 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:40:58 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:15:52 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "libunit.h"
int main(void)
{
libunit_launcher();
strlen_launcher();
}

View File

@@ -12,17 +12,16 @@
#include "../tests.h" #include "../tests.h"
int strlen_launcher(void) { int strlen_launcher(void)
t_unit_test *testlist; {
size_t res; t_unit_test *testlist;
size_t res;
testlist = NULL; testlist = NULL;
load_test(&testlist, "null", &test_null); load_test(&testlist, "null", &test_null);
load_test(&testlist, "basic", &test_basic); load_test(&testlist, "basic", &test_basic);
load_test(&testlist, "large", &test_large); load_test(&testlist, "large", &test_large);
res = launch_tests(testlist, "strlen");
res = launch_tests(testlist, "strlen"); clear_tests(&testlist);
clear_tests(&testlist); return (res);
return (res);
} }

View File

@@ -12,6 +12,7 @@
#include "../tests.h" #include "../tests.h"
int test_null(void) { int test_null(void)
return (ft_strlen(NULL) == 0); {
return (ft_strlen(NULL) == 0);
} }

View File

@@ -12,14 +12,16 @@
#include "../tests.h" #include "../tests.h"
int test_large(void) { int test_large(void)
size_t i; {
char s[10000]; size_t i;
char s[10000];
i = 0; i = 0;
while (i < sizeof(s)) { while (i < sizeof(s))
s[i] = ' '; {
i++; s[i] = ' ';
} i++;
return (ft_strlen(s) == sizeof(s) + 1); }
return (ft_strlen(s) == sizeof(s) + 1);
} }

View File

@@ -1,5 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 18:53:18 by elagouch #+# #+# */
/* Updated: 2026/01/24 18:53:18 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "tests.h" #include "tests.h"
int main(void) { int main(void)
strlen_launcher(); {
strlen_launcher();
} }

View File

@@ -16,11 +16,11 @@
# include "libunit.h" # include "libunit.h"
// LAUNCHERS // LAUNCHERS
int strlen_launcher(void); int strlen_launcher(void);
// strlen // strlen
int test_basic(void); int test_basic(void);
int test_null(void); int test_null(void);
int test_large(void); int test_large(void);
#endif // !TESTS_H #endif // !TESTS_H

View File

@@ -12,18 +12,17 @@
#include "../tests.h" #include "../tests.h"
int libunit_launcher(void) { int libunit_launcher(void)
t_unit_test *testlist; {
size_t res; t_unit_test *testlist;
size_t res;
testlist = NULL; testlist = NULL;
load_test(&testlist, "successful", &test_ok); load_test(&testlist, "successful", &test_ok);
load_test(&testlist, "unsuccessful", &test_ko); load_test(&testlist, "unsuccessful", &test_ko);
load_test(&testlist, "sigsegv", &test_sigsegv); load_test(&testlist, "sigsegv", &test_sigsegv);
load_test(&testlist, "sigbus", &test_sigbus); load_test(&testlist, "sigbus", &test_sigbus);
res = launch_tests(testlist, "libunit");
res = launch_tests(testlist, "libunit"); clear_tests(&testlist);
clear_tests(&testlist); return (res);
return (res);
} }

View File

@@ -10,6 +10,7 @@
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
int test_ko(void) { int test_ko(void)
return (0); {
return (0);
} }

View File

@@ -12,7 +12,8 @@
#include <signal.h> #include <signal.h>
int test_sigsegv(void) { int test_sigsegv(void)
raise(SIGSEGV); {
return (1); raise(SIGSEGV);
return (1);
} }

View File

@@ -12,7 +12,8 @@
#include <signal.h> #include <signal.h>
int test_sigbus(void) { int test_sigbus(void)
raise(SIGBUS); {
return (1); raise(SIGBUS);
return (1);
} }

View File

@@ -1,5 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 18:53:13 by elagouch #+# #+# */
/* Updated: 2026/01/24 18:53:14 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include "tests.h" #include "tests.h"
int main(void) { int main(void)
libunit_launcher(); {
libunit_launcher();
} }

View File

@@ -16,12 +16,12 @@
# include "libunit.h" # include "libunit.h"
// LAUNCHERS // LAUNCHERS
int libunit_launcher(void); int libunit_launcher(void);
// libunit // libunit
int test_ok(void); int test_ok(void);
int test_ko(void); int test_ko(void);
int test_sigsegv(void); int test_sigsegv(void);
int test_sigbus(void); int test_sigbus(void);
#endif // !TESTS_H #endif // !TESTS_H