Merge branch 'feat/r1'
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -55,4 +55,6 @@ dkms.conf
|
|||||||
*.dwo
|
*.dwo
|
||||||
|
|
||||||
/libunit
|
/libunit
|
||||||
|
/real_tests/real_tests
|
||||||
|
/tests/tests
|
||||||
|
|
||||||
|
|||||||
50
Makefile
50
Makefile
@@ -1,37 +1,57 @@
|
|||||||
NAME = libunit
|
NAME = libunit.a
|
||||||
CXX = cc
|
AR = ar rcs
|
||||||
CXXFLAGS = -Wall -Wextra -Werror -MMD -MP
|
CC = cc
|
||||||
CXXFLAGS += -g3
|
CCFLAGS = -Wall -Wextra -Werror -MMD -MP
|
||||||
CXXFLAGS += -I $(LIBFT_DIR) -I.
|
CCFLAGS += -I$(LIBFT_DIR) -I. -Iframework
|
||||||
LDFLAGS = -Llibft -lft
|
LDFLAGS = -Llibft -lunit -lft -L.
|
||||||
LIBFT_DIR = libft
|
LIBFT_DIR = libft
|
||||||
LIBFT_A = $(LIBFT_DIR)/libft.a
|
LIBFT_A = $(LIBFT_DIR)/libft.a
|
||||||
|
|
||||||
SRC = libunit_util.c libunit_util2.c libunit.c main.c
|
SRC = framework/libunit_util.c framework/libunit_util2.c framework/libunit.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_atoi/00_launcher.c real_tests/ft_atoi/01_ok.c real_tests/ft_atoi/02_ko.c real_tests/ft_atoi/03_sigsegv.c real_tests/ft_atoi/04_sigbus.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)
|
||||||
|
|
||||||
|
TESTD = tests
|
||||||
|
TESTB = $(TESTD)/tests
|
||||||
|
TESTM = $(TESTD)/Makefile
|
||||||
|
RTESTD = real_tests
|
||||||
|
RTESTB = $(RTESTD)/real_tests
|
||||||
|
RTESTM = $(RTESTD)/Makefile
|
||||||
|
|
||||||
all: $(NAME)
|
all: $(NAME)
|
||||||
|
|
||||||
$(NAME): $(OBJ) | $(LIBFT_A)
|
$(NAME): $(OBJ) | $(LIBFT_A)
|
||||||
$(CXX) $(CXXFLAGS) $(OBJ) $(LDFLAGS) -o $(NAME)
|
$(AR) $(NAME) $(OBJ)
|
||||||
|
|
||||||
%.o: %.c Makefile
|
%.o: %.c Makefile
|
||||||
$(CXX) $(CXXFLAGS) -c $< -o $@
|
$(CC) $(CCFLAGS) -c $< -o $@
|
||||||
|
|
||||||
$(LIBFT_A):
|
$(LIBFT_A): FORCE
|
||||||
$(MAKE) -C $(LIBFT_DIR)
|
@$(MAKE) -C $(LIBFT_DIR)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) $(OBJ) $(SRC:.c=.d)
|
$(RM) $(OBJ) $(SRC:.c=.d)
|
||||||
|
@$(MAKE) -C $(TESTD) clean
|
||||||
|
@$(MAKE) -C $(RTESTD) clean
|
||||||
|
|
||||||
fclean: clean
|
fclean: clean
|
||||||
$(RM) $(NAME)
|
$(RM) $(NAME)
|
||||||
|
@$(MAKE) -C $(TESTD) fclean
|
||||||
|
@$(MAKE) -C $(RTESTD) fclean
|
||||||
|
|
||||||
re: fclean
|
re: fclean
|
||||||
$(MAKE) all
|
@$(MAKE) all
|
||||||
|
|
||||||
|
$(TESTB): FORCE
|
||||||
|
@$(MAKE) -C $(TESTD)
|
||||||
|
|
||||||
|
$(RTESTB): FORCE
|
||||||
|
@$(MAKE) -C $(RTESTD)
|
||||||
|
|
||||||
|
test: $(TESTB) $(RTESTB)
|
||||||
|
$(TESTB)
|
||||||
|
$(RTESTB)
|
||||||
|
|
||||||
|
FORCE: ;
|
||||||
|
|
||||||
-include $(SRC:.c=.d)
|
-include $(SRC:.c=.d)
|
||||||
|
|
||||||
|
|||||||
5
README
Normal file
5
README
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
libunit
|
||||||
|
=======
|
||||||
|
|
||||||
|
This is an implementation of the `libunit` 42 Rush project.
|
||||||
|
|
||||||
@@ -6,56 +6,64 @@
|
|||||||
/* 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 16:15:02 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 16:50:51 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "libft/libft.h"
|
||||||
#include "libunit.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);
|
||||||
if (WIFSIGNALED(status))
|
if (WIFEXITED(status))
|
||||||
{
|
|
||||||
if (WTERMSIG(status) == 11)
|
|
||||||
ft_putstr_fd("[SIGSEGV]\n", 1);
|
|
||||||
else if (WTERMSIG(status) == 10)
|
|
||||||
ft_putstr_fd("[SIGBUS]\n", 1);
|
|
||||||
}
|
|
||||||
else if (WIFEXITED(status))
|
|
||||||
{
|
{
|
||||||
if (WEXITSTATUS(status))
|
if (WEXITSTATUS(status))
|
||||||
ft_putstr_fd("[KO]\n", 1);
|
ft_putstr_fd("[\x1B[31m\x1B[1mKO\x1B[0m]\n", 1);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ft_putstr_fd("[OK]\n", 1);
|
ft_putstr_fd("[\x1B[32mOK\x1B[0m]\n", 1);
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (WIFSIGNALED(status))
|
||||||
|
{
|
||||||
|
if (WTERMSIG(status) == 11)
|
||||||
|
ft_putstr_fd("[\x1B[33mSIGSEGV\x1B[0m]\n", 1);
|
||||||
|
else if (WTERMSIG(status) == 7)
|
||||||
|
ft_putstr_fd("[\x1B[33mSIGBUS\x1B[0m]\n", 1);
|
||||||
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
|
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_putnbr_fd(ok_tests, 1);
|
||||||
ft_putchar_fd('/', 1);
|
ft_putchar_fd('/', 1);
|
||||||
ft_putnbr_fd((int)count_tests(test_list), 1);
|
ft_putnbr_fd((int)total, 1);
|
||||||
ft_putstr_fd(" tests checked\n", 1);
|
ft_putstr_fd("\x1B[0m tests succeeded\n\n", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@@ -71,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);
|
||||||
@@ -6,14 +6,14 @@
|
|||||||
/* 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 16:15:23 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/libft.h"
|
# include "libft.h"
|
||||||
# include <sys/types.h>
|
# include <sys/types.h>
|
||||||
# include <unistd.h>
|
# include <unistd.h>
|
||||||
|
|
||||||
@@ -66,9 +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);
|
||||||
|
|
||||||
// LAUNCHERS
|
#endif // !LIBUNIT_H
|
||||||
int strlen_launcher(void);
|
|
||||||
int libunit_launcher(void);
|
|
||||||
int atoi_launcher(void);
|
|
||||||
|
|
||||||
#endif // !UTIL_UNIT_H
|
|
||||||
@@ -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);
|
|
||||||
}
|
|
||||||
38
real_tests/Makefile
Normal file
38
real_tests/Makefile
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
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
|
||||||
|
SRC += ft_atoi/00_launcher.c ft_atoi/01_ok.c ft_atoi/02_ko.c ft_atoi/03_sigsegv.c ft_atoi/04_sigbus.c
|
||||||
|
SRC += ft_strncmp/00_launcher.c ft_strncmp/01_ok.c ft_strncmp/02_ko.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
|
||||||
@@ -6,22 +6,22 @@
|
|||||||
/* 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 16:17:20 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 16:34:12 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#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", &test_null);
|
load_test(&testlist, "null", &test_null);
|
||||||
load_test(&testlist, "basic test", &test_basic);
|
load_test(&testlist, "basic", &test_basic);
|
||||||
|
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,27 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* 01_basic_test.c :+: :+: :+: */
|
/* 03_large.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* 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:39:06 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 16:36:42 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "../tests.h"
|
||||||
|
|
||||||
int test_basic(void)
|
int test_large(void)
|
||||||
{
|
{
|
||||||
return (ft_strlen("hello, world") == 12);
|
size_t i;
|
||||||
|
char s[10000];
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (i < sizeof(s))
|
||||||
|
{
|
||||||
|
s[i] = ' ';
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (ft_strlen(s) == sizeof(s) + 1);
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ int strncmp_launcher(void)
|
|||||||
|
|
||||||
testlist = NULL;
|
testlist = NULL;
|
||||||
load_test(&testlist, "OK test", &strncmp_ok_test);
|
load_test(&testlist, "OK test", &strncmp_ok_test);
|
||||||
|
load_test(&testlist, "KO test", &strncmp_ko_test);
|
||||||
res = launch_tests(testlist, "ft_strncmp");
|
res = launch_tests(testlist, "ft_strncmp");
|
||||||
clear_tests(&testlist);
|
clear_tests(&testlist);
|
||||||
return (res);
|
return (res);
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
int strncmp_ok_test(void)
|
int strncmp_ok_test(void)
|
||||||
{
|
{
|
||||||
return (ft_strncmp("test", "test", 4));
|
return (!ft_strncmp("test", "test", 4));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,5 +2,5 @@
|
|||||||
|
|
||||||
int strncmp_ko_test(void)
|
int strncmp_ko_test(void)
|
||||||
{
|
{
|
||||||
return (ft_strncmp("blabla", "test", 4));
|
return (!ft_strncmp("blabla", "test", 4));
|
||||||
}
|
}
|
||||||
@@ -5,16 +5,16 @@
|
|||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* 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 18:53:18 by elagouch #+# #+# */
|
||||||
/* Updated: 2026/01/24 16:15:52 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 18:53:18 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libunit.h"
|
#include "tests.h"
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
libunit_launcher();
|
|
||||||
strlen_launcher();
|
strlen_launcher();
|
||||||
atoi_launcher();
|
atoi_launcher();
|
||||||
|
strncmp_launcher();
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* 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 16:16:13 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 18:40:48 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,9 +15,15 @@
|
|||||||
|
|
||||||
# include "libunit.h"
|
# include "libunit.h"
|
||||||
|
|
||||||
|
// LAUNCHERS
|
||||||
|
int strlen_launcher(void);
|
||||||
|
int atoi_launcher(void);
|
||||||
|
int strncmp_launcher(void);
|
||||||
|
|
||||||
// strlen
|
// strlen
|
||||||
int test_basic(void);
|
int test_basic(void);
|
||||||
int test_null(void);
|
int test_null(void);
|
||||||
|
int test_large(void);
|
||||||
|
|
||||||
// atoi
|
// atoi
|
||||||
int atoi_ok_test(void);
|
int atoi_ok_test(void);
|
||||||
@@ -27,6 +33,7 @@ int atoi_sigbus_test(void);
|
|||||||
|
|
||||||
//strncmp
|
//strncmp
|
||||||
int strncmp_ok_test(void);
|
int strncmp_ok_test(void);
|
||||||
|
int strncmp_ko_test(void);
|
||||||
|
|
||||||
|
|
||||||
#endif // !TESTS_H
|
#endif // !TESTS_H
|
||||||
|
|||||||
36
tests/Makefile
Normal file
36
tests/Makefile
Normal file
@@ -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
|
||||||
@@ -6,24 +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 16:16:24 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 16:47:43 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#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_ko);
|
load_test(&testlist, "sigsegv", &test_sigsegv);
|
||||||
load_test(&testlist, "sigbus", &test_ko);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
int test_ko(void) {
|
int test_ko(void)
|
||||||
return (0);
|
{
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
/* */
|
/* */
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* 02_null_test.c :+: :+: :+: */
|
/* main.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* 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 18:53:13 by elagouch #+# #+# */
|
||||||
/* Updated: 2026/01/24 16:01:12 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 18:53:14 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "libft.h"
|
#include "tests.h"
|
||||||
|
|
||||||
int test_null(void) {
|
int main(void)
|
||||||
return (ft_strlen(NULL) == 0);
|
{
|
||||||
|
libunit_launcher();
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
/* 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 16:16:20 by elagouch ### ########.fr */
|
/* Updated: 2026/01/24 18:41:02 by elagouch ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -16,16 +16,12 @@
|
|||||||
# include "libunit.h"
|
# include "libunit.h"
|
||||||
|
|
||||||
// LAUNCHERS
|
// LAUNCHERS
|
||||||
int strlen_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);
|
||||||
|
|
||||||
// strlen
|
|
||||||
int test_basic(void);
|
|
||||||
int test_null(void);
|
|
||||||
|
|
||||||
#endif // !TESTS_H
|
#endif // !TESTS_H
|
||||||
|
|||||||
Reference in New Issue
Block a user