ca fait bcp la non

This commit is contained in:
airone01
2026-01-24 16:20:53 +01:00
parent 1b48b0bb13
commit 6e652d3b24
20 changed files with 232 additions and 40 deletions

2
.gitignore vendored
View File

@@ -54,5 +54,5 @@ dkms.conf
# debug information files # debug information files
*.dwo *.dwo
libunit /libunit

View File

@@ -2,14 +2,14 @@ NAME = libunit
CXX = cc CXX = cc
CXXFLAGS = -Wall -Wextra -Werror -MMD -MP CXXFLAGS = -Wall -Wextra -Werror -MMD -MP
CXXFLAGS += -g3 CXXFLAGS += -g3
CXXFLAGS += -I $(LIBFT_DIR) CXXFLAGS += -I $(LIBFT_DIR) -I.
LDFLAGS = -Llibft -lft LDFLAGS = -Llibft -lft
LIBFT_DIR = libft LIBFT_DIR = libft
LIBFT_A = $(LIBFT_DIR)/libft.a LIBFT_A = $(LIBFT_DIR)/libft.a
SRC = util_unit.c util_unit2.c launch_test.c SRC = libunit_util.c libunit_util2.c libunit.c main.c
SRC += tests/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/ft_strlen/00_launcher.c tests/ft_strlen/01_basic_test.c tests/ft_strlen/02_null_test.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) OBJ = $(SRC:.c=.o)
all: $(NAME) all: $(NAME)

View File

@@ -6,22 +6,23 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:32 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 "../../util_unit.h"
#include "../tests.h" #include "../tests.h"
int strlen_launcher(void) int strlen_launcher(void) {
{ t_unit_test *testlist;
t_unit_test *testlist; size_t res;
size_t res;
testlist = NULL; testlist = NULL;
load_test(&testlist, "null test", &test_null); load_test(&testlist, "null test", &test_null);
load_test(&testlist, "basic test", &test_basic); load_test(&testlist, "basic test", &test_basic);
res = launch_tests(testlist, "strlen");
clear_tests(&testlist); res = launch_tests(testlist, "strlen");
return (res); clear_tests(&testlist);
return (res);
} }

View File

@@ -6,13 +6,12 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 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" #include "libft.h"
int test_null(void) int test_null(void) {
{ return (ft_strlen(NULL) == 0);
return (ft_strlen(NULL) == 0);
} }

View File

@@ -1,17 +1,16 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* launch_test.c :+: :+: :+: */ /* libunit.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */ /* By: dgaillet <dgaillet@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 12:43:35 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 "libunit.h"
#include "util_unit.h"
#include <sys/wait.h> #include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>

View File

@@ -1,12 +1,12 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* util_unit.h :+: :+: :+: */ /* libunit.h :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* 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 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, int launch_tests(t_unit_test *test_list,
const char *fn_name); const char *fn_name);
// LAUNCHERS
int strlen_launcher(void);
int libunit_launcher(void);
#endif // !UTIL_UNIT_H #endif // !UTIL_UNIT_H

View File

@@ -1,16 +1,16 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* util_unit.c :+: :+: :+: */ /* libunit_util.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 14:35:57 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 <stdlib.h> #include <stdlib.h>
size_t count_tests(t_unit_test *head) size_t count_tests(t_unit_test *head)

View File

@@ -1,16 +1,16 @@
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
/* ::: :::::::: */ /* ::: :::::::: */
/* util_unit2.c :+: :+: :+: */ /* libunit_util2.c :+: :+: :+: */
/* +:+ +:+ +:+ */ /* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:46:43 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 /* we loop over instead of shifting the pointer to make sure we don't skip
unexisting tests and end up in unallocated/invalid memory */ unexisting tests and end up in unallocated/invalid memory */

View File

@@ -6,13 +6,14 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:40:58 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();
} }

View File

@@ -0,0 +1,27 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_launcher.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_basic.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@@ -0,0 +1,17 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_null.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

22
real_tests/tests.h Normal file
View File

@@ -0,0 +1,22 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tests.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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

View File

@@ -0,0 +1,29 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 00_launcher.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

16
tests/libunit/01_ok.c Normal file
View File

@@ -0,0 +1,16 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 01_ok.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

15
tests/libunit/02_ko.c Normal file
View File

@@ -0,0 +1,15 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 02_ko.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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);
}

View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 03_sigsegv.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:19:43 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigsegv(void) {
raise(SIGSEGV);
return (1);
}

18
tests/libunit/04_sigbus.c Normal file
View File

@@ -0,0 +1,18 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 04_sigbus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
/* Updated: 2026/01/24 16:19:50 by elagouch ### ########.fr */
/* */
/* ************************************************************************** */
#include <signal.h>
int test_sigbus(void) {
raise(SIGBUS);
return (1);
}

View File

@@ -6,18 +6,26 @@
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */ /* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2026/01/24 15:32:30 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 #ifndef TESTS_H
# define TESTS_H # define TESTS_H
# include "libunit.h"
// LAUNCHERS // 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 // strlen
int test_basic(void); int test_basic(void);
int test_null(void); int test_null(void);
#endif // !TESTS_H #endif // !TESTS_H