From 88359c5262d84eee9e617191f77cf3506ea69972 Mon Sep 17 00:00:00 2001 From: airone01 <21955960+airone01@users.noreply.github.com> Date: Sat, 24 Jan 2026 16:28:48 +0100 Subject: [PATCH 1/7] feat: colors --- Makefile | 3 +++ libunit.c | 22 +++++++++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index f1e9645..172ea2b 100644 --- a/Makefile +++ b/Makefile @@ -32,6 +32,9 @@ fclean: clean re: fclean $(MAKE) all +test: all + ./$(NAME) + -include $(SRC:.c=.d) .PHONY: all clean fclean re diff --git a/libunit.c b/libunit.c index 9efa341..fac675f 100644 --- a/libunit.c +++ b/libunit.c @@ -6,11 +6,12 @@ /* By: dgaillet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 12:43:35 by dgaillet #+# #+# */ -/* Updated: 2026/01/24 16:15:02 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:28:06 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ #include "libunit.h" +#include "libft/libft.h" #include #include #include @@ -25,29 +26,36 @@ static size_t interpret_status(int status, const char *fn_name if (WIFEXITED(status)) { if (WEXITSTATUS(status)) - ft_putstr_fd("[KO]\n", 1); + ft_putstr_fd("[\x1B[31m\x1B[1mKO\x1B[0m]\n", 1); else { - ft_putstr_fd("[OK]\n", 1); + ft_putstr_fd("[\x1B[32mOK\x1B[0m]\n", 1); return (1); } } else if (WIFSIGNALED(status)) { if (WTERMSIG(status) == 11) - ft_putstr_fd("[SIGSEGV]\n", 1); + ft_putstr_fd("[\x1B[33mSIGSEGV\x1B[0m]\n", 1); else if (WTERMSIG(status) == 10) - ft_putstr_fd("[SIGBUS]\n", 1); + ft_putstr_fd("[\x1B[33mSIGBUS\x1B[0m]\n", 1); } return (0); } static void print_passed_test(size_t ok_tests, t_unit_test *test_list) { + size_t total; + + total = count_tests(test_list); + if (ok_tests == total) + ft_putstr_fd("\x1B[32m", 1); + else + ft_putstr_fd("\x1B[31m", 1); ft_putnbr_fd(ok_tests, 1); ft_putchar_fd('/', 1); - ft_putnbr_fd((int)count_tests(test_list), 1); - ft_putstr_fd(" tests checked", 1); + ft_putnbr_fd((int)total, 1); + ft_putstr_fd("\x1B[0m tests succeeded\n\n", 1); } int launch_tests(t_unit_test *test_list, const char *fn_name) From 803127f57c0d01394f686fb4dfb0f9a5163aae11 Mon Sep 17 00:00:00 2001 From: airone01 <21955960+airone01@users.noreply.github.com> Date: Sat, 24 Jan 2026 16:51:06 +0100 Subject: [PATCH 2/7] fix: patch a libunit bug --- Makefile | 2 +- README | 5 +++++ libunit.c | 4 ++-- real_tests/ft_strlen/00_launcher.c | 7 ++++--- real_tests/ft_strlen/03_large.c | 25 +++++++++++++++++++++++++ real_tests/tests.h | 3 ++- tests/libunit/00_launcher.c | 6 +++--- 7 files changed, 42 insertions(+), 10 deletions(-) create mode 100644 README create mode 100644 real_tests/ft_strlen/03_large.c diff --git a/Makefile b/Makefile index 172ea2b..0e0557c 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ LIBFT_DIR = libft LIBFT_A = $(LIBFT_DIR)/libft.a 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 += real_tests/ft_strlen/00_launcher.c real_tests/ft_strlen/01_basic.c real_tests/ft_strlen/02_null.c real_tests/ft_strlen/03_large.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) diff --git a/README b/README new file mode 100644 index 0000000..cfd792a --- /dev/null +++ b/README @@ -0,0 +1,5 @@ +libunit +======= + +This is an implementation of the `libunit` 42 Rush project. + diff --git a/libunit.c b/libunit.c index fac675f..d38c83d 100644 --- a/libunit.c +++ b/libunit.c @@ -6,7 +6,7 @@ /* By: dgaillet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 12:43:35 by dgaillet #+# #+# */ -/* Updated: 2026/01/24 16:28:06 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:50:51 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ @@ -37,7 +37,7 @@ static size_t interpret_status(int status, const char *fn_name { if (WTERMSIG(status) == 11) ft_putstr_fd("[\x1B[33mSIGSEGV\x1B[0m]\n", 1); - else if (WTERMSIG(status) == 10) + else if (WTERMSIG(status) == 7) ft_putstr_fd("[\x1B[33mSIGBUS\x1B[0m]\n", 1); } return (0); diff --git a/real_tests/ft_strlen/00_launcher.c b/real_tests/ft_strlen/00_launcher.c index 48d5b7e..b2f93a7 100644 --- a/real_tests/ft_strlen/00_launcher.c +++ b/real_tests/ft_strlen/00_launcher.c @@ -6,7 +6,7 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */ -/* Updated: 2026/01/24 16:17:20 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:34:12 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,8 +17,9 @@ int strlen_launcher(void) { size_t res; testlist = NULL; - load_test(&testlist, "null test", &test_null); - load_test(&testlist, "basic test", &test_basic); + load_test(&testlist, "null", &test_null); + load_test(&testlist, "basic", &test_basic); + load_test(&testlist, "large", &test_large); res = launch_tests(testlist, "strlen"); clear_tests(&testlist); diff --git a/real_tests/ft_strlen/03_large.c b/real_tests/ft_strlen/03_large.c new file mode 100644 index 0000000..492270a --- /dev/null +++ b/real_tests/ft_strlen/03_large.c @@ -0,0 +1,25 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* 03_large.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */ +/* Updated: 2026/01/24 16:36:42 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "../tests.h" + +int test_large(void) { + size_t i; + char s[10000]; + + i = 0; + while (i < sizeof(s)) { + s[i] = ' '; + i++; + } + return (ft_strlen(s) == sizeof(s) + 1); +} diff --git a/real_tests/tests.h b/real_tests/tests.h index 33785ba..f9298e0 100644 --- a/real_tests/tests.h +++ b/real_tests/tests.h @@ -6,7 +6,7 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */ -/* Updated: 2026/01/24 16:16:13 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:33:14 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ @@ -18,5 +18,6 @@ // strlen int test_basic(void); int test_null(void); +int test_large(void); #endif // !TESTS_H diff --git a/tests/libunit/00_launcher.c b/tests/libunit/00_launcher.c index 483488e..9c2bdc3 100644 --- a/tests/libunit/00_launcher.c +++ b/tests/libunit/00_launcher.c @@ -6,7 +6,7 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */ -/* Updated: 2026/01/24 16:16:24 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 16:47:43 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,8 +19,8 @@ int libunit_launcher(void) { 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); + load_test(&testlist, "sigsegv", &test_sigsegv); + load_test(&testlist, "sigbus", &test_sigbus); res = launch_tests(testlist, "libunit"); clear_tests(&testlist); From 22de4eb11ac490753bc0fec96b09b978cc37715e Mon Sep 17 00:00:00 2001 From: airone01 <21955960+airone01@users.noreply.github.com> Date: Sat, 24 Jan 2026 17:12:11 +0100 Subject: [PATCH 3/7] refactor: move to framework dit --- Makefile | 31 ++++++++++++-------- libunit.c => framework/libunit.c | 0 libunit.h => framework/libunit.h | 0 libunit_util.c => framework/libunit_util.c | 0 libunit_util2.c => framework/libunit_util2.c | 0 5 files changed, 19 insertions(+), 12 deletions(-) rename libunit.c => framework/libunit.c (100%) rename libunit.h => framework/libunit.h (100%) rename libunit_util.c => framework/libunit_util.c (100%) rename libunit_util2.c => framework/libunit_util2.c (100%) diff --git a/Makefile b/Makefile index 0e0557c..a4d146f 100644 --- a/Makefile +++ b/Makefile @@ -1,21 +1,27 @@ -NAME = libunit +NAME = libunit.a +TNAME = libunit +AR = ar rcs CXX = cc CXXFLAGS = -Wall -Wextra -Werror -MMD -MP CXXFLAGS += -g3 -CXXFLAGS += -I $(LIBFT_DIR) -I. -LDFLAGS = -Llibft -lft +CXXFLAGS += -I$(LIBFT_DIR) -I. -Iframework +LDFLAGS = -Llibft -lunit -lft -L. LIBFT_DIR = libft LIBFT_A = $(LIBFT_DIR)/libft.a -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 real_tests/ft_strlen/03_large.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 +SRC = framework/libunit_util.c framework/libunit_util2.c framework/libunit.c +TSRC = main.c real_tests/ft_strlen/00_launcher.c real_tests/ft_strlen/01_basic.c real_tests/ft_strlen/02_null.c real_tests/ft_strlen/03_large.c +TSRC += 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) +TOBJ = $(TSRC:.c=.o) all: $(NAME) $(NAME): $(OBJ) | $(LIBFT_A) - $(CXX) $(CXXFLAGS) $(OBJ) $(LDFLAGS) -o $(NAME) + $(AR) $(NAME) $(OBJ) + +$(TNAME): $(NAME) $(TOBJ) | $(LIBFT_A) $(NAME) + $(CXX) $(CXXFLAGS) $(TOBJ) $(LDFLAGS) -o $(TNAME) %.o: %.c Makefile $(CXX) $(CXXFLAGS) -c $< -o $@ @@ -24,18 +30,19 @@ $(LIBFT_A): $(MAKE) -C $(LIBFT_DIR) clean: - $(RM) $(OBJ) $(SRC:.c=.d) + $(MAKE) -C $(LIBFT_DIR) fclean + $(RM) $(OBJ) $(TOBJ) $(SRC:.c=.d) $(TSRC:.c=.d) fclean: clean - $(RM) $(NAME) + $(RM) $(NAME) $(TNAME) re: fclean $(MAKE) all -test: all - ./$(NAME) +test: $(TNAME) + ./$(TNAME) --include $(SRC:.c=.d) +-include $(SRC:.c=.d) $(TSRC:.c=.d) .PHONY: all clean fclean re diff --git a/libunit.c b/framework/libunit.c similarity index 100% rename from libunit.c rename to framework/libunit.c diff --git a/libunit.h b/framework/libunit.h similarity index 100% rename from libunit.h rename to framework/libunit.h diff --git a/libunit_util.c b/framework/libunit_util.c similarity index 100% rename from libunit_util.c rename to framework/libunit_util.c diff --git a/libunit_util2.c b/framework/libunit_util2.c similarity index 100% rename from libunit_util2.c rename to framework/libunit_util2.c From 856739af67c22505052533ac4586f40db308d5b5 Mon Sep 17 00:00:00 2001 From: airone01 <21955960+airone01@users.noreply.github.com> Date: Sat, 24 Jan 2026 18:46:05 +0100 Subject: [PATCH 4/7] refactor: fix the makefile problems --- .gitignore | 2 ++ Makefile | 45 +++++++++++++++++++++++++++------------------ framework/libunit.h | 8 ++------ real_tests/Makefile | 36 ++++++++++++++++++++++++++++++++++++ real_tests/main.c | 5 +++++ real_tests/tests.h | 5 ++++- tests/Makefile | 36 ++++++++++++++++++++++++++++++++++++ tests/main.c | 5 +++++ tests/tests.h | 8 ++------ 9 files changed, 119 insertions(+), 31 deletions(-) create mode 100644 real_tests/Makefile create mode 100644 real_tests/main.c create mode 100644 tests/Makefile create mode 100644 tests/main.c diff --git a/.gitignore b/.gitignore index db12e57..32dd980 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,6 @@ dkms.conf *.dwo /libunit +/real_tests/real_tests +/tests/tests diff --git a/Makefile b/Makefile index a4d146f..7df0dd0 100644 --- a/Makefile +++ b/Makefile @@ -1,48 +1,57 @@ NAME = libunit.a -TNAME = libunit AR = ar rcs -CXX = cc -CXXFLAGS = -Wall -Wextra -Werror -MMD -MP -CXXFLAGS += -g3 -CXXFLAGS += -I$(LIBFT_DIR) -I. -Iframework +CC = cc +CCFLAGS = -Wall -Wextra -Werror -MMD -MP +CCFLAGS += -I$(LIBFT_DIR) -I. -Iframework LDFLAGS = -Llibft -lunit -lft -L. LIBFT_DIR = libft LIBFT_A = $(LIBFT_DIR)/libft.a SRC = framework/libunit_util.c framework/libunit_util2.c framework/libunit.c -TSRC = main.c real_tests/ft_strlen/00_launcher.c real_tests/ft_strlen/01_basic.c real_tests/ft_strlen/02_null.c real_tests/ft_strlen/03_large.c -TSRC += 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) -TOBJ = $(TSRC:.c=.o) + +TESTD = tests +TESTB = $(TESTD)/tests +TESTM = $(TESTD)/Makefile +RTESTD = real_tests +RTESTB = $(RTESTD)/real_tests +RTESTM = $(RTESTD)/Makefile all: $(NAME) $(NAME): $(OBJ) | $(LIBFT_A) $(AR) $(NAME) $(OBJ) -$(TNAME): $(NAME) $(TOBJ) | $(LIBFT_A) $(NAME) - $(CXX) $(CXXFLAGS) $(TOBJ) $(LDFLAGS) -o $(TNAME) - %.o: %.c Makefile - $(CXX) $(CXXFLAGS) -c $< -o $@ + $(CC) $(CCFLAGS) -c $< -o $@ $(LIBFT_A): $(MAKE) -C $(LIBFT_DIR) clean: - $(MAKE) -C $(LIBFT_DIR) fclean - $(RM) $(OBJ) $(TOBJ) $(SRC:.c=.d) $(TSRC:.c=.d) + $(RM) $(OBJ) $(SRC:.c=.d) + $(MAKE) -C $(TESTD) clean + $(MAKE) -C $(RTESTD) clean fclean: clean - $(RM) $(NAME) $(TNAME) + $(RM) $(NAME) + $(MAKE) -C $(TESTD) fclean + $(MAKE) -C $(RTESTD) fclean re: fclean $(MAKE) all -test: $(TNAME) - ./$(TNAME) +$(TESTB): + $(MAKE) -C $(TESTD) --include $(SRC:.c=.d) $(TSRC:.c=.d) +$(RTESTB): + $(MAKE) -C $(RTESTD) + +test: $(TESTB) $(RTESTB) + $(TESTB) + $(RTESTB) + +-include $(SRC:.c=.d) .PHONY: all clean fclean re diff --git a/framework/libunit.h b/framework/libunit.h index 17e7d3e..5e859c6 100644 --- a/framework/libunit.h +++ b/framework/libunit.h @@ -6,14 +6,14 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 14:38:40 by elagouch #+# #+# */ -/* Updated: 2026/01/24 16:15:23 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 18:40:36 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef UTIL_UNIT_H # define UTIL_UNIT_H -# include "libft/libft.h" +# include "libft.h" # include # include @@ -66,8 +66,4 @@ 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/real_tests/Makefile b/real_tests/Makefile new file mode 100644 index 0000000..4bfae62 --- /dev/null +++ b/real_tests/Makefile @@ -0,0 +1,36 @@ +NAME = real_tests +CC = cc +CCFLAGS = -Wall -Wextra -Werror -MMD -MP + +SRC = main.c +SRC += ft_strlen/00_launcher.c ft_strlen/01_basic.c ft_strlen/02_null.c ft_strlen/03_large.c +OBJ = $(SRC:.c=.o) + +LIBS = -L.. -lunit -L../libft -lft +INC = -I. -I../framework -I../libft + +all: $(NAME) + +test: $(NAME) + ./$(NAME) + +%.o: %.c Makefile + $(CC) $(CCFLAGS) $(INC) -c $< -o $@ + +$(NAME): $(OBJ) | libunit + $(CC) $(CCFLAGS) $(INC) $(OBJ) $(LIBS) -o $(NAME) + +libunit: + $(MAKE) -C .. + +clean: + $(RM) $(OBJ) $(SRC:.c=.d) + +fclean: clean + $(RM) $(NAME) + +re: fclean all + +-include $(SRC:.c=.d) + +.PHONY: all clean fclean re libunit diff --git a/real_tests/main.c b/real_tests/main.c new file mode 100644 index 0000000..ac63287 --- /dev/null +++ b/real_tests/main.c @@ -0,0 +1,5 @@ +#include "tests.h" + +int main(void) { + strlen_launcher(); +} diff --git a/real_tests/tests.h b/real_tests/tests.h index f9298e0..a9ec790 100644 --- a/real_tests/tests.h +++ b/real_tests/tests.h @@ -6,7 +6,7 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */ -/* Updated: 2026/01/24 16:33:14 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 18:40:48 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,6 +15,9 @@ # include "libunit.h" +// LAUNCHERS +int strlen_launcher(void); + // strlen int test_basic(void); int test_null(void); diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..9d930f5 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,36 @@ +NAME = tests +CC = cc +CCFLAGS = -Wall -Wextra -Werror -MMD -MP + +SRC = main.c +SRC += libunit/00_launcher.c libunit/01_ok.c libunit/02_ko.c libunit/03_sigsegv.c libunit/04_sigbus.c +OBJ = $(SRC:.c=.o) + +LIBS = -L.. -lunit -L../libft -lft +INC = -I. -I../framework -I../libft + +all: $(NAME) + +test: $(NAME) + ./$(NAME) + +%.o: %.c Makefile + $(CC) $(CCFLAGS) $(INC) -c $< -o $@ + +$(NAME): $(OBJ) | libunit + $(CC) $(CCFLAGS) $(INC) $(OBJ) $(LIBS) -o $(NAME) + +libunit: + $(MAKE) -C .. + +clean: + $(RM) $(OBJ) $(SRC:.c=.d) + +fclean: clean + $(RM) $(NAME) + +re: fclean all + +-include $(SRC:.c=.d) + +.PHONY: all clean fclean re libunit diff --git a/tests/main.c b/tests/main.c new file mode 100644 index 0000000..3f9c5f9 --- /dev/null +++ b/tests/main.c @@ -0,0 +1,5 @@ +#include "tests.h" + +int main(void) { + libunit_launcher(); +} diff --git a/tests/tests.h b/tests/tests.h index 24a4f2d..bc413c6 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -6,7 +6,7 @@ /* By: elagouch +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */ -/* Updated: 2026/01/24 16:16:20 by elagouch ### ########.fr */ +/* Updated: 2026/01/24 18:41:02 by elagouch ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,7 +16,7 @@ # include "libunit.h" // LAUNCHERS -int strlen_launcher(void); +int libunit_launcher(void); // libunit int test_ok(void); @@ -24,8 +24,4 @@ int test_ko(void); int test_sigsegv(void); int test_sigbus(void); -// strlen -int test_basic(void); -int test_null(void); - #endif // !TESTS_H From 932732c1e52fccf0852682362386843536bb5f3d Mon Sep 17 00:00:00 2001 From: airone01 <21955960+airone01@users.noreply.github.com> Date: Sat, 24 Jan 2026 18:52:13 +0100 Subject: [PATCH 5/7] ci(make): force some targets --- Makefile | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 7df0dd0..19facd9 100644 --- a/Makefile +++ b/Makefile @@ -25,7 +25,7 @@ $(NAME): $(OBJ) | $(LIBFT_A) %.o: %.c Makefile $(CC) $(CCFLAGS) -c $< -o $@ -$(LIBFT_A): +$(LIBFT_A): FORCE $(MAKE) -C $(LIBFT_DIR) clean: @@ -41,16 +41,18 @@ fclean: clean re: fclean $(MAKE) all -$(TESTB): +$(TESTB): FORCE $(MAKE) -C $(TESTD) -$(RTESTB): +$(RTESTB): FORCE $(MAKE) -C $(RTESTD) test: $(TESTB) $(RTESTB) $(TESTB) $(RTESTB) +FORCE: ; + -include $(SRC:.c=.d) .PHONY: all clean fclean re From 1ee5334149a9418316a34bf36a93172b4ff05261 Mon Sep 17 00:00:00 2001 From: airone01 <21955960+airone01@users.noreply.github.com> Date: Sat, 24 Jan 2026 18:56:42 +0100 Subject: [PATCH 6/7] syle: norm --- framework/libunit.c | 34 +++++++++++++++--------------- framework/libunit.h | 8 +++---- libft/ft_strlen/00_launcher.c | 28 ------------------------ libft/ft_strlen/01_basic_test.c | 18 ---------------- libft/ft_strlen/02_null_test.c | 17 --------------- main.c | 19 ----------------- real_tests/ft_strlen/00_launcher.c | 23 ++++++++++---------- real_tests/ft_strlen/02_null.c | 5 +++-- real_tests/ft_strlen/03_large.c | 20 ++++++++++-------- real_tests/main.c | 17 +++++++++++++-- real_tests/tests.h | 8 +++---- tests/libunit/00_launcher.c | 25 +++++++++++----------- tests/libunit/02_ko.c | 5 +++-- tests/libunit/03_sigsegv.c | 7 +++--- tests/libunit/04_sigbus.c | 7 +++--- tests/main.c | 17 +++++++++++++-- tests/tests.h | 10 ++++----- 17 files changed, 108 insertions(+), 160 deletions(-) delete mode 100644 libft/ft_strlen/00_launcher.c delete mode 100644 libft/ft_strlen/01_basic_test.c delete mode 100644 libft/ft_strlen/02_null_test.c delete mode 100644 main.c diff --git a/framework/libunit.c b/framework/libunit.c index d38c83d..f98e249 100644 --- a/framework/libunit.c +++ b/framework/libunit.c @@ -10,16 +10,16 @@ /* */ /* ************************************************************************** */ -#include "libunit.h" #include "libft/libft.h" +#include "libunit.h" +#include #include #include -#include -static size_t interpret_status(int status, const char *fn_name - , char *test_name) +static size_t interpret_status(int status, const char *fn_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(test_name, 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) { - size_t total; + size_t total; - total = count_tests(test_list); - if (ok_tests == total) - ft_putstr_fd("\x1B[32m", 1); - else - ft_putstr_fd("\x1B[31m", 1); + total = count_tests(test_list); + if (ok_tests == total) + ft_putstr_fd("\x1B[32m", 1); + else + ft_putstr_fd("\x1B[31m", 1); ft_putnbr_fd(ok_tests, 1); ft_putchar_fd('/', 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) { - size_t ok_tests; - pid_t wpid; - int status; - int i; + size_t ok_tests; + pid_t wpid; + int status; + int i; ok_tests = 0; i = -1; @@ -79,8 +79,8 @@ int launch_tests(t_unit_test *test_list, const char *fn_name) wpid = wait(&status); if (wpid < 0) return (1); - ok_tests += interpret_status(status, fn_name, - get_test_at(test_list, i)->title); + ok_tests += interpret_status(status, fn_name, get_test_at(test_list, + i)->title); } } print_passed_test(ok_tests, test_list); diff --git a/framework/libunit.h b/framework/libunit.h index 5e859c6..f68a14c 100644 --- a/framework/libunit.h +++ b/framework/libunit.h @@ -6,12 +6,12 @@ /* 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 -# define UTIL_UNIT_H +#ifndef LIBUNIT_H +# define LIBUNIT_H # include "libft.h" # include @@ -66,4 +66,4 @@ void clear_tests(t_unit_test **head_ptr); int launch_tests(t_unit_test *test_list, const char *fn_name); -#endif // !UTIL_UNIT_H +#endif // !LIBUNIT_H diff --git a/libft/ft_strlen/00_launcher.c b/libft/ft_strlen/00_launcher.c deleted file mode 100644 index e1ff4fa..0000000 --- a/libft/ft_strlen/00_launcher.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 00_launcher.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: elagouch +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/ft_strlen/01_basic_test.c b/libft/ft_strlen/01_basic_test.c deleted file mode 100644 index 9ffa4c5..0000000 --- a/libft/ft_strlen/01_basic_test.c +++ /dev/null @@ -1,18 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 01_basic_test.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: elagouch +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/libft/ft_strlen/02_null_test.c b/libft/ft_strlen/02_null_test.c deleted file mode 100644 index 565d235..0000000 --- a/libft/ft_strlen/02_null_test.c +++ /dev/null @@ -1,17 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* 02_null_test.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: elagouch +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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); -} diff --git a/main.c b/main.c deleted file mode 100644 index 21ca363..0000000 --- a/main.c +++ /dev/null @@ -1,19 +0,0 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* main.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: elagouch +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* 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(); -} diff --git a/real_tests/ft_strlen/00_launcher.c b/real_tests/ft_strlen/00_launcher.c index b2f93a7..10d6ad5 100644 --- a/real_tests/ft_strlen/00_launcher.c +++ b/real_tests/ft_strlen/00_launcher.c @@ -12,17 +12,16 @@ #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_null); - load_test(&testlist, "basic", &test_basic); - load_test(&testlist, "large", &test_large); - - res = launch_tests(testlist, "strlen"); - clear_tests(&testlist); - - return (res); + testlist = NULL; + load_test(&testlist, "null", &test_null); + load_test(&testlist, "basic", &test_basic); + load_test(&testlist, "large", &test_large); + res = launch_tests(testlist, "strlen"); + clear_tests(&testlist); + return (res); } diff --git a/real_tests/ft_strlen/02_null.c b/real_tests/ft_strlen/02_null.c index ae665f8..fbf978f 100644 --- a/real_tests/ft_strlen/02_null.c +++ b/real_tests/ft_strlen/02_null.c @@ -12,6 +12,7 @@ #include "../tests.h" -int test_null(void) { - return (ft_strlen(NULL) == 0); +int test_null(void) +{ + return (ft_strlen(NULL) == 0); } diff --git a/real_tests/ft_strlen/03_large.c b/real_tests/ft_strlen/03_large.c index 492270a..f471b2e 100644 --- a/real_tests/ft_strlen/03_large.c +++ b/real_tests/ft_strlen/03_large.c @@ -12,14 +12,16 @@ #include "../tests.h" -int test_large(void) { - size_t i; - char s[10000]; +int test_large(void) +{ + size_t i; + char s[10000]; - i = 0; - while (i < sizeof(s)) { - s[i] = ' '; - i++; - } - return (ft_strlen(s) == sizeof(s) + 1); + i = 0; + while (i < sizeof(s)) + { + s[i] = ' '; + i++; + } + return (ft_strlen(s) == sizeof(s) + 1); } diff --git a/real_tests/main.c b/real_tests/main.c index ac63287..2be44c8 100644 --- a/real_tests/main.c +++ b/real_tests/main.c @@ -1,5 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 18:53:18 by elagouch #+# #+# */ +/* Updated: 2026/01/24 18:53:18 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "tests.h" -int main(void) { - strlen_launcher(); +int main(void) +{ + strlen_launcher(); } diff --git a/real_tests/tests.h b/real_tests/tests.h index a9ec790..7b7d3f9 100644 --- a/real_tests/tests.h +++ b/real_tests/tests.h @@ -16,11 +16,11 @@ # include "libunit.h" // LAUNCHERS -int strlen_launcher(void); +int strlen_launcher(void); // strlen -int test_basic(void); -int test_null(void); -int test_large(void); +int test_basic(void); +int test_null(void); +int test_large(void); #endif // !TESTS_H diff --git a/tests/libunit/00_launcher.c b/tests/libunit/00_launcher.c index 9c2bdc3..4f9aa3e 100644 --- a/tests/libunit/00_launcher.c +++ b/tests/libunit/00_launcher.c @@ -12,18 +12,17 @@ #include "../tests.h" -int libunit_launcher(void) { - t_unit_test *testlist; - size_t res; +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_sigsegv); - load_test(&testlist, "sigbus", &test_sigbus); - - res = launch_tests(testlist, "libunit"); - clear_tests(&testlist); - - return (res); + testlist = NULL; + load_test(&testlist, "successful", &test_ok); + load_test(&testlist, "unsuccessful", &test_ko); + load_test(&testlist, "sigsegv", &test_sigsegv); + load_test(&testlist, "sigbus", &test_sigbus); + res = launch_tests(testlist, "libunit"); + clear_tests(&testlist); + return (res); } diff --git a/tests/libunit/02_ko.c b/tests/libunit/02_ko.c index 22cd63c..f8cf1a2 100644 --- a/tests/libunit/02_ko.c +++ b/tests/libunit/02_ko.c @@ -10,6 +10,7 @@ /* */ /* ************************************************************************** */ -int test_ko(void) { - return (0); +int test_ko(void) +{ + return (0); } diff --git a/tests/libunit/03_sigsegv.c b/tests/libunit/03_sigsegv.c index b7cc362..b92429e 100644 --- a/tests/libunit/03_sigsegv.c +++ b/tests/libunit/03_sigsegv.c @@ -12,7 +12,8 @@ #include -int test_sigsegv(void) { - raise(SIGSEGV); - return (1); +int test_sigsegv(void) +{ + raise(SIGSEGV); + return (1); } diff --git a/tests/libunit/04_sigbus.c b/tests/libunit/04_sigbus.c index b8c568a..06aca74 100644 --- a/tests/libunit/04_sigbus.c +++ b/tests/libunit/04_sigbus.c @@ -12,7 +12,8 @@ #include -int test_sigbus(void) { - raise(SIGBUS); - return (1); +int test_sigbus(void) +{ + raise(SIGBUS); + return (1); } diff --git a/tests/main.c b/tests/main.c index 3f9c5f9..11bf0f7 100644 --- a/tests/main.c +++ b/tests/main.c @@ -1,5 +1,18 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: elagouch +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2026/01/24 18:53:13 by elagouch #+# #+# */ +/* Updated: 2026/01/24 18:53:14 by elagouch ### ########.fr */ +/* */ +/* ************************************************************************** */ + #include "tests.h" -int main(void) { - libunit_launcher(); +int main(void) +{ + libunit_launcher(); } diff --git a/tests/tests.h b/tests/tests.h index bc413c6..0fc03ff 100644 --- a/tests/tests.h +++ b/tests/tests.h @@ -16,12 +16,12 @@ # include "libunit.h" // LAUNCHERS -int libunit_launcher(void); +int libunit_launcher(void); // libunit -int test_ok(void); -int test_ko(void); -int test_sigsegv(void); -int test_sigbus(void); +int test_ok(void); +int test_ko(void); +int test_sigsegv(void); +int test_sigbus(void); #endif // !TESTS_H From c5109131892bc0117d58792760335a0b6e61b355 Mon Sep 17 00:00:00 2001 From: airone01 <21955960+airone01@users.noreply.github.com> Date: Sat, 24 Jan 2026 19:05:21 +0100 Subject: [PATCH 7/7] chore: small make changes --- Makefile | 16 ++++++++-------- real_tests/Makefile | 2 +- tests/Makefile | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 19facd9..26f548c 100644 --- a/Makefile +++ b/Makefile @@ -26,26 +26,26 @@ $(NAME): $(OBJ) | $(LIBFT_A) $(CC) $(CCFLAGS) -c $< -o $@ $(LIBFT_A): FORCE - $(MAKE) -C $(LIBFT_DIR) + @$(MAKE) -C $(LIBFT_DIR) clean: $(RM) $(OBJ) $(SRC:.c=.d) - $(MAKE) -C $(TESTD) clean - $(MAKE) -C $(RTESTD) clean + @$(MAKE) -C $(TESTD) clean + @$(MAKE) -C $(RTESTD) clean fclean: clean $(RM) $(NAME) - $(MAKE) -C $(TESTD) fclean - $(MAKE) -C $(RTESTD) fclean + @$(MAKE) -C $(TESTD) fclean + @$(MAKE) -C $(RTESTD) fclean re: fclean - $(MAKE) all + @$(MAKE) all $(TESTB): FORCE - $(MAKE) -C $(TESTD) + @$(MAKE) -C $(TESTD) $(RTESTB): FORCE - $(MAKE) -C $(RTESTD) + @$(MAKE) -C $(RTESTD) test: $(TESTB) $(RTESTB) $(TESTB) diff --git a/real_tests/Makefile b/real_tests/Makefile index 4bfae62..1f8ac65 100644 --- a/real_tests/Makefile +++ b/real_tests/Makefile @@ -21,7 +21,7 @@ $(NAME): $(OBJ) | libunit $(CC) $(CCFLAGS) $(INC) $(OBJ) $(LIBS) -o $(NAME) libunit: - $(MAKE) -C .. + @$(MAKE) -C .. clean: $(RM) $(OBJ) $(SRC:.c=.d) diff --git a/tests/Makefile b/tests/Makefile index 9d930f5..f78f9b0 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -21,7 +21,7 @@ $(NAME): $(OBJ) | libunit $(CC) $(CCFLAGS) $(INC) $(OBJ) $(LIBS) -o $(NAME) libunit: - $(MAKE) -C .. + @$(MAKE) -C .. clean: $(RM) $(OBJ) $(SRC:.c=.d)