syle: norm
This commit is contained in:
@@ -10,16 +10,16 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libunit.h"
|
||||
#include "libft/libft.h"
|
||||
#include "libunit.h"
|
||||
#include <stdlib.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
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);
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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 <sys/types.h>
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 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);
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* 02_null_test.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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);
|
||||
}
|
||||
19
main.c
19
main.c
@@ -1,19 +0,0 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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();
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
int test_ko(void) {
|
||||
return (0);
|
||||
int test_ko(void)
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
int test_sigsegv(void) {
|
||||
raise(SIGSEGV);
|
||||
return (1);
|
||||
int test_sigsegv(void)
|
||||
{
|
||||
raise(SIGSEGV);
|
||||
return (1);
|
||||
}
|
||||
|
||||
@@ -12,7 +12,8 @@
|
||||
|
||||
#include <signal.h>
|
||||
|
||||
int test_sigbus(void) {
|
||||
raise(SIGBUS);
|
||||
return (1);
|
||||
int test_sigbus(void)
|
||||
{
|
||||
raise(SIGBUS);
|
||||
return (1);
|
||||
}
|
||||
|
||||
17
tests/main.c
17
tests/main.c
@@ -1,5 +1,18 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: elagouch <elagouch@student.42lyon.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* 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();
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user