feat: finally tests
This commit is contained in:
7
Makefile
7
Makefile
@@ -4,11 +4,14 @@ CXXFLAGS = -Wall -Wextra -Werror -MMD -MP
|
|||||||
CXXFLAGS += -g3
|
CXXFLAGS += -g3
|
||||||
CXXFLAGS += -I $(LIBFT_DIR)
|
CXXFLAGS += -I $(LIBFT_DIR)
|
||||||
LDFLAGS = -Llibft -lft
|
LDFLAGS = -Llibft -lft
|
||||||
SRC = util_unit.c util_unit2.c
|
|
||||||
OBJ = $(SRC:.cpp=.o)
|
|
||||||
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 += tests/main.c
|
||||||
|
SRC += tests/ft_strlen/00_launcher.c tests/ft_strlen/01_basic_test.c tests/ft_strlen/02_null_test.c
|
||||||
|
OBJ = $(SRC:.cpp=.o)
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
$(NAME): $(OBJ) | $(LIBFT_A)
|
$(NAME): $(OBJ) | $(LIBFT_A)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* 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 12:43:37 by dgaillet ### ########lyon.fr */
|
/* Updated: 2026/01/24 15:44:35 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ int launch_tests(t_unit_test *test_list, const char *fn_name)
|
|||||||
|
|
||||||
ok_tests = 0;
|
ok_tests = 0;
|
||||||
i = -1;
|
i = -1;
|
||||||
while (i++ < (int)count_tests(test_list))
|
while (++i < (int)count_tests(test_list))
|
||||||
{
|
{
|
||||||
wpid = fork();
|
wpid = fork();
|
||||||
if (wpid < 0)
|
if (wpid < 0)
|
||||||
|
|||||||
28
tests/ft_strlen/00_launcher.c
Normal file
28
tests/ft_strlen/00_launcher.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 00_launcher.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/24 15:32:32 by elagouch #+# #+# */
|
||||||
|
/* Updated: 2026/01/24 15:44:00 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);
|
||||||
|
}
|
||||||
17
tests/ft_strlen/01_basic_test.c
Normal file
17
tests/ft_strlen/01_basic_test.c
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 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);
|
||||||
|
}
|
||||||
17
tests/ft_strlen/02_null_test.c
Normal file
17
tests/ft_strlen/02_null_test.c
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* 02_null_test.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/24 15:38:17 by elagouch #+# #+# */
|
||||||
|
/* Updated: 2026/01/24 15:40:42 by elagouch ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft.h"
|
||||||
|
|
||||||
|
int test_null(void) {
|
||||||
|
return (ft_strlen(NULL) == 0);
|
||||||
|
}
|
||||||
18
tests/main.c
Normal file
18
tests/main.c
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* main.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/24 15:40:58 by elagouch #+# #+# */
|
||||||
|
/* Updated: 2026/01/24 15:41:56 by elagouch ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "tests.h"
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
strlen_launcher();
|
||||||
|
}
|
||||||
23
tests/tests.h
Normal file
23
tests/tests.h
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* tests.h :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2026/01/24 15:32:30 by elagouch #+# #+# */
|
||||||
|
/* Updated: 2026/01/24 15:41:32 by elagouch ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#ifndef TESTS_H
|
||||||
|
# define TESTS_H
|
||||||
|
|
||||||
|
// LAUNCHERS
|
||||||
|
int strlen_launcher(void);
|
||||||
|
|
||||||
|
// strlen
|
||||||
|
int test_basic(void);
|
||||||
|
int test_null(void);
|
||||||
|
|
||||||
|
#endif // !TESTS_H
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* 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 14:38:20 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 15:37:46 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -90,4 +90,5 @@ void clear_tests(t_unit_test **head_ptr)
|
|||||||
head->func = NULL;
|
head->func = NULL;
|
||||||
head = next;
|
head = next;
|
||||||
}
|
}
|
||||||
|
*head_ptr = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* 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 14:38:41 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 15:35:30 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -60,4 +60,10 @@ size_t load_test(t_unit_test **head_ptr, const char *title,
|
|||||||
*/
|
*/
|
||||||
void clear_tests(t_unit_test **head_ptr);
|
void clear_tests(t_unit_test **head_ptr);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief launches the tests and returns the reported status
|
||||||
|
*/
|
||||||
|
int launch_tests(t_unit_test *test_list,
|
||||||
|
const char *fn_name);
|
||||||
|
|
||||||
#endif // !UTIL_UNIT_H
|
#endif // !UTIL_UNIT_H
|
||||||
|
|||||||
Reference in New Issue
Block a user