From 6e652d3b2489a7403ec421f49a71f588587d3e41 Mon Sep 17 00:00:00 2001 From: airone01 <21955960+airone01@users.noreply.github.com> Date: Sat, 24 Jan 2026 16:20:53 +0100 Subject: [PATCH] ca fait bcp la non --- .gitignore | 2 +- Makefile | 8 +++--- {tests => libft}/ft_strlen/00_launcher.c | 23 +++++++++-------- {tests => libft}/ft_strlen/01_basic_test.c | 0 {tests => libft}/ft_strlen/02_null_test.c | 7 +++--- launch_test.c => libunit.c | 7 +++--- util_unit.h => libunit.h | 8 ++++-- util_unit.c => libunit_util.c | 6 ++--- util_unit2.c => libunit_util2.c | 6 ++--- tests/main.c => main.c | 9 ++++--- real_tests/ft_strlen/00_launcher.c | 27 ++++++++++++++++++++ real_tests/ft_strlen/01_basic.c | 18 ++++++++++++++ real_tests/ft_strlen/02_null.c | 17 +++++++++++++ real_tests/tests.h | 22 ++++++++++++++++ tests/libunit/00_launcher.c | 29 ++++++++++++++++++++++ tests/libunit/01_ok.c | 16 ++++++++++++ tests/libunit/02_ko.c | 15 +++++++++++ tests/libunit/03_sigsegv.c | 18 ++++++++++++++ tests/libunit/04_sigbus.c | 18 ++++++++++++++ tests/tests.h | 16 +++++++++--- 20 files changed, 232 insertions(+), 40 deletions(-) rename {tests => libft}/ft_strlen/00_launcher.c (72%) rename {tests => libft}/ft_strlen/01_basic_test.c (100%) rename {tests => libft}/ft_strlen/02_null_test.c (87%) rename launch_test.c => libunit.c (92%) rename util_unit.h => libunit.h (89%) rename util_unit.c => libunit_util.c (93%) rename util_unit2.c => libunit_util2.c (87%) rename tests/main.c => main.c (85%) create mode 100644 real_tests/ft_strlen/00_launcher.c create mode 100644 real_tests/ft_strlen/01_basic.c create mode 100644 real_tests/ft_strlen/02_null.c create mode 100644 real_tests/tests.h create mode 100644 tests/libunit/00_launcher.c create mode 100644 tests/libunit/01_ok.c create mode 100644 tests/libunit/02_ko.c create mode 100644 tests/libunit/03_sigsegv.c create mode 100644 tests/libunit/04_sigbus.c diff --git a/.gitignore b/.gitignore index 6a13e31..db12e57 100644 --- a/.gitignore +++ b/.gitignore @@ -54,5 +54,5 @@ dkms.conf # debug information files *.dwo -libunit +/libunit diff --git a/Makefile b/Makefile index a9643eb..f1e9645 100644 --- a/Makefile +++ b/Makefile @@ -2,14 +2,14 @@ NAME = libunit CXX = cc CXXFLAGS = -Wall -Wextra -Werror -MMD -MP CXXFLAGS += -g3 -CXXFLAGS += -I $(LIBFT_DIR) +CXXFLAGS += -I $(LIBFT_DIR) -I. LDFLAGS = -Llibft -lft LIBFT_DIR = libft LIBFT_A = $(LIBFT_DIR)/libft.a -SRC = util_unit.c util_unit2.c launch_test.c -SRC += tests/main.c -SRC += tests/ft_strlen/00_launcher.c tests/ft_strlen/01_basic_test.c tests/ft_strlen/02_null_test.c +SRC = libunit_util.c libunit_util2.c libunit.c main.c +SRC += real_tests/ft_strlen/00_launcher.c real_tests/ft_strlen/01_basic.c real_tests/ft_strlen/02_null.c +SRC += tests/libunit/00_launcher.c tests/libunit/01_ok.c tests/libunit/02_ko.c tests/libunit/03_sigsegv.c tests/libunit/04_sigbus.c OBJ = $(SRC:.c=.o) all: $(NAME) diff --git a/tests/ft_strlen/00_launcher.c b/libft/ft_strlen/00_launcher.c similarity index 72% rename from tests/ft_strlen/00_launcher.c rename to libft/ft_strlen/00_launcher.c index 3b5be9b..e1ff4fa 100644 --- a/tests/ft_strlen/00_launcher.c +++ b/libft/ft_strlen/00_launcher.c @@ -6,22 +6,23 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */ -/* Updated: 2026/01/24 15:44:00 by elagouch ### ########.fr */ +/* 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; +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); + 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); } diff --git a/tests/ft_strlen/01_basic_test.c b/libft/ft_strlen/01_basic_test.c similarity index 100% rename from tests/ft_strlen/01_basic_test.c rename to libft/ft_strlen/01_basic_test.c diff --git a/tests/ft_strlen/02_null_test.c b/libft/ft_strlen/02_null_test.c similarity index 87% rename from tests/ft_strlen/02_null_test.c rename to libft/ft_strlen/02_null_test.c index 6af63d4..565d235 100644 --- a/tests/ft_strlen/02_null_test.c +++ b/libft/ft_strlen/02_null_test.c @@ -6,13 +6,12 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */ -/* Updated: 2026/01/24 15:40:42 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:01:12 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ #include "libft.h" -int test_null(void) -{ - return (ft_strlen(NULL) == 0); +int test_null(void) { + return (ft_strlen(NULL) == 0); } diff --git a/launch_test.c b/libunit.c similarity index 92% rename from launch_test.c rename to libunit.c index 60d798b..9efa341 100644 --- a/launch_test.c +++ b/libunit.c @@ -1,17 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* launch_test.c :+: :+: :+: */ +/* libunit.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: dgaillet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 12:43:35 by dgaillet #+# #+# */ -/* Updated: 2026/01/24 15:44:35 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:15:02 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ -#include "util_unit.h" -#include "util_unit.h" +#include "libunit.h" #include #include #include diff --git a/util_unit.h b/libunit.h similarity index 89% rename from util_unit.h rename to libunit.h index 6b874d8..17e7d3e 100644 --- a/util_unit.h +++ b/libunit.h @@ -1,12 +1,12 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* util_unit.h :+: :+: :+: */ +/* libunit.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 14:38:40 by elagouch #+# #+# */ -/* Updated: 2026/01/24 15:35:30 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:15:23 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,4 +66,8 @@ void clear_tests(t_unit_test **head_ptr); int launch_tests(t_unit_test *test_list, const char *fn_name); +// LAUNCHERS +int strlen_launcher(void); +int libunit_launcher(void); + #endif // !UTIL_UNIT_H diff --git a/util_unit.c b/libunit_util.c similarity index 93% rename from util_unit.c rename to libunit_util.c index 3534581..1bdb2b3 100644 --- a/util_unit.c +++ b/libunit_util.c @@ -1,16 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* util_unit.c :+: :+: :+: */ +/* libunit_util.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 14:35:57 by elagouch #+# #+# */ -/* Updated: 2026/01/24 15:37:46 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:15:35 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ -#include "util_unit.h" +#include "libunit.h" #include size_t count_tests(t_unit_test *head) diff --git a/util_unit2.c b/libunit_util2.c similarity index 87% rename from util_unit2.c rename to libunit_util2.c index fc9b9b0..f8584e1 100644 --- a/util_unit2.c +++ b/libunit_util2.c @@ -1,16 +1,16 @@ /* ************************************************************************** */ /* */ /* ::: :::::::: */ -/* util_unit2.c :+: :+: :+: */ +/* libunit_util2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:46:43 by elagouch #+# #+# */ -/* Updated: 2026/01/24 15:46:44 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:15:43 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ -#include "util_unit.h" +#include "libunit.h" /* we loop over instead of shifting the pointer to make sure we don't skip unexisting tests and end up in unallocated/invalid memory */ diff --git a/tests/main.c b/main.c similarity index 85% rename from tests/main.c rename to main.c index d7e9509..21ca363 100644 --- a/tests/main.c +++ b/main.c @@ -6,13 +6,14 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:40:58 by elagouch #+# #+# */ -/* Updated: 2026/01/24 15:41:56 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:15:52 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ -#include "tests.h" +#include "libunit.h" -int main(void) +int main(void) { - strlen_launcher(); + libunit_launcher(); + strlen_launcher(); } diff --git a/real_tests/ft_strlen/00_launcher.c b/real_tests/ft_strlen/00_launcher.c new file mode 100644 index 0000000..48d5b7e --- /dev/null +++ b/real_tests/ft_strlen/00_launcher.c @@ -0,0 +1,27 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 00_launcher.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:17:20 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#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); +} diff --git a/real_tests/ft_strlen/01_basic.c b/real_tests/ft_strlen/01_basic.c new file mode 100644 index 0000000..3c5047e --- /dev/null +++ b/real_tests/ft_strlen/01_basic.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 01_basic.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:17:14 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../tests.h" + +int test_basic(void) +{ + return (ft_strlen("hello, world") == 12); +} diff --git a/real_tests/ft_strlen/02_null.c b/real_tests/ft_strlen/02_null.c new file mode 100644 index 0000000..ae665f8 --- /dev/null +++ b/real_tests/ft_strlen/02_null.c @@ -0,0 +1,17 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 02_null.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:17:04 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../tests.h" + +int test_null(void) { + return (ft_strlen(NULL) == 0); +} diff --git a/real_tests/tests.h b/real_tests/tests.h new file mode 100644 index 0000000..33785ba --- /dev/null +++ b/real_tests/tests.h @@ -0,0 +1,22 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* tests.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:16:13 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef TESTS_H +# define TESTS_H + +# include "libunit.h" + +// strlen +int test_basic(void); +int test_null(void); + +#endif // !TESTS_H diff --git a/tests/libunit/00_launcher.c b/tests/libunit/00_launcher.c new file mode 100644 index 0000000..483488e --- /dev/null +++ b/tests/libunit/00_launcher.c @@ -0,0 +1,29 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 00_launcher.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:16:24 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../tests.h" + +int libunit_launcher(void) { + t_unit_test *testlist; + size_t res; + + testlist = NULL; + load_test(&testlist, "successful", &test_ok); + load_test(&testlist, "unsuccessful", &test_ko); + load_test(&testlist, "sigsegv", &test_ko); + load_test(&testlist, "sigbus", &test_ko); + + res = launch_tests(testlist, "libunit"); + clear_tests(&testlist); + + return (res); +} diff --git a/tests/libunit/01_ok.c b/tests/libunit/01_ok.c new file mode 100644 index 0000000..818f7d3 --- /dev/null +++ b/tests/libunit/01_ok.c @@ -0,0 +1,16 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 01_ok.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:16:32 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int test_ok(void) +{ + return (1); +} diff --git a/tests/libunit/02_ko.c b/tests/libunit/02_ko.c new file mode 100644 index 0000000..22cd63c --- /dev/null +++ b/tests/libunit/02_ko.c @@ -0,0 +1,15 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 02_ko.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:16:37 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +int test_ko(void) { + return (0); +} diff --git a/tests/libunit/03_sigsegv.c b/tests/libunit/03_sigsegv.c new file mode 100644 index 0000000..b7cc362 --- /dev/null +++ b/tests/libunit/03_sigsegv.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 03_sigsegv.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:19:43 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int test_sigsegv(void) { + raise(SIGSEGV); + return (1); +} diff --git a/tests/libunit/04_sigbus.c b/tests/libunit/04_sigbus.c new file mode 100644 index 0000000..b8c568a --- /dev/null +++ b/tests/libunit/04_sigbus.c @@ -0,0 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 04_sigbus.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:19:50 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include + +int test_sigbus(void) { + raise(SIGBUS); + return (1); +} diff --git a/tests/tests.h b/tests/tests.h index 15fa308..24a4f2d 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -6,18 +6,26 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */ -/* Updated: 2026/01/24 15:41:32 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:16:20 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef TESTS_H # define TESTS_H +# include "libunit.h" + // LAUNCHERS -int strlen_launcher(void); +int strlen_launcher(void); + +// libunit +int test_ok(void); +int test_ko(void); +int test_sigsegv(void); +int test_sigbus(void); // strlen -int test_basic(void); -int test_null(void); +int test_basic(void); +int test_null(void); #endif // !TESTS_H