⚙️ Conversion & Character Utilities Update #3
🛡️ Robustness Buffs (Conversion Functions) • 🧩 ft_atoi and ft_atoll gained a safety shield: they now return 0 when passed a null pointer, preventing accidental crashes. • This change improves stability across the board, ensuring safer handling of unexpected input. 🧪 Test Suite Expansions New & Expanded Conversion Trials • 📝 Added extensive test coverage for ft_atoi, ft_atoll, and ft_itoa, including edge cases and null pointer handling. • These tests live in test/convert/ and ensure your conversion toolkit is battle-ready for any scenario. Character Function Test Output Polish • ✨ Updated all character test files (test_isalnum.c, test_isalpha.c, test_isascii.c, test_isprint.c, test_tolower.c, test_toupper.c) with better output formatting. • Each result now ends with a newline → improved readability during long test runs. 🔨 Build & Test Process • 🧹 The Makefile has been optimized: • test target now depends on fclean + $(NAME) → always runs on a clean build. • The test runner loop has been reformatted for cleaner output. 📦 Minor Updates • 📅 File headers refreshed to reflect the latest modification dates, keeping the codebase neat and consistent. ⚡ Impact • Stronger crash resistance for conversion functions. • More comprehensive and reliable test suite. • Cleaner, more professional build & test pipeline. • Better dev experience thanks to polished test outputs.
This commit is contained in:
commit
78c37163f2
12 changed files with 147 additions and 12 deletions
8
Makefile
8
Makefile
|
|
@ -6,7 +6,7 @@
|
|||
# By: rparodi <marvin@42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/11/12 11:05:05 by rparodi #+# #+# #
|
||||
# Updated: 2025/09/04 18:48:57 by rparodi ### ########.fr #
|
||||
# Updated: 2025/09/05 15:10:23 by rparodi ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
|
|
@ -163,15 +163,15 @@ TEST_SRCS := $(shell find test -type f -name '*.c' 2>/dev/null)
|
|||
|
||||
TEST_BINS := $(patsubst test/%.c,.test/%,$(TEST_SRCS))
|
||||
|
||||
test: all $(LIB_NAME) $(TEST_BINS) test-run footer
|
||||
test: fclean $(NAME) $(TEST_BINS) test-run footer
|
||||
|
||||
.test/%: test/%.c $(LIB_NAME)
|
||||
@mkdir -p $(dir $@)
|
||||
@$(CC) $(CFLAGS) $(CPPFLAGS) $< -L. -lft $(LDFLAGS) -o $@
|
||||
|
||||
test-run:
|
||||
@set -e; \
|
||||
for t in $(TEST_BINS); do \
|
||||
@set -e
|
||||
@for t in $(TEST_BINS); do \
|
||||
printf "\n\n$(GREY)>> Running $(GOLD)$$t$(END)\n"; \
|
||||
TERM=xterm $$t; \
|
||||
done; \
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <marvin@42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/11/08 17:22:41 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/04 11:39:58 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 14:34:51 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -43,6 +43,8 @@ int ft_atoi(const char *nptr)
|
|||
int sign;
|
||||
int number;
|
||||
|
||||
if (!nptr)
|
||||
return (0);
|
||||
i = 0;
|
||||
sign = ft_check_sign(nptr, &i);
|
||||
number = 0;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2024/10/31 15:12:07 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/01 16:32:11 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 14:54:50 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -45,6 +45,8 @@ long long int ft_atoll(const char *nptr)
|
|||
int sign;
|
||||
long long int number;
|
||||
|
||||
if (!nptr)
|
||||
return (0);
|
||||
i = 0;
|
||||
sign = ft_check_sign(nptr, &i);
|
||||
number = 0;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/04 18:50:17 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 11:24:26 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,4 +33,5 @@ int main(void)
|
|||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
puts("\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 18:41:04 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/04 18:49:58 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 11:23:32 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,4 +33,5 @@ int main(void)
|
|||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
puts("\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 10:40:18 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 11:24:19 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,4 +33,5 @@ int main(void)
|
|||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
puts("\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 10:43:55 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 11:23:32 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,4 +33,5 @@ int main(void)
|
|||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
puts("\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 10:35:53 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 11:23:53 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,4 +33,5 @@ int main(void)
|
|||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
puts("\n");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 10:37:26 by rparodi ### ########.fr */
|
||||
/* Updated: 2025/09/05 11:23:46 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
|
@ -33,4 +33,5 @@ int main(void)
|
|||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
c++;
|
||||
}
|
||||
puts("\n");
|
||||
}
|
||||
|
|
|
|||
41
test/convert/test_atoi.c
Normal file
41
test/convert/test_atoi.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_atoi.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 15:05:21 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "color.h"
|
||||
#include "convert.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *str[] = {"", "0", "42", "-42", "+-42", "-2147483648",
|
||||
"2147483647"};
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < 7)
|
||||
{
|
||||
if (ft_atoi(str[i]) != atoi(str[i]))
|
||||
{
|
||||
dprintf(2, "%s✘ Found %i, expected %i%s\n", CLR_RED,
|
||||
ft_atoi(str[i]), atoi(str[i]), RESET);
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
i++;
|
||||
}
|
||||
ft_atoi(NULL);
|
||||
printf("%s✔%s", CLR_GREEN, RESET);
|
||||
puts("\n");
|
||||
}
|
||||
41
test/convert/test_atoll.c
Normal file
41
test/convert/test_atoll.c
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_atoll.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 15:05:31 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "color.h"
|
||||
#include "convert.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *str[] = {"", "0", "42", "-42", "+-42", "-2147483648",
|
||||
"2147483647", "9223372036854775807", "-9223372036854775808"};
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < 7)
|
||||
{
|
||||
if (ft_atoll(str[i]) != atoll(str[i]))
|
||||
{
|
||||
dprintf(2, "%s✘ Found %lli, expected %lli%s\n", CLR_RED,
|
||||
ft_atoll(str[i]), atoll(str[i]), RESET);
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
i++;
|
||||
}
|
||||
ft_atoll(NULL);
|
||||
printf("%s✔%s", CLR_GREEN, RESET);
|
||||
puts("\n");
|
||||
}
|
||||
43
test/convert/test_itoa.c
Normal file
43
test/convert/test_itoa.c
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* test_itoa.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2025/09/04 16:54:42 by rparodi #+# #+# */
|
||||
/* Updated: 2025/09/05 15:08:52 by rparodi ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "color.h"
|
||||
#include "convert.h"
|
||||
#include <ctype.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const int integer[] = {0, 42, -42, +-42, -2147483648, 2147483647};
|
||||
char result[1024];
|
||||
size_t i;
|
||||
|
||||
i = 0;
|
||||
while (i < 7)
|
||||
{
|
||||
sprintf(result, "%d", integer[i]);
|
||||
if (strcmp(ft_itoa(integer[i]), result))
|
||||
{
|
||||
dprintf(2, "%s✘ Found %s, expected %s%s\n", CLR_RED,
|
||||
ft_itoa(integer[i]), result, RESET);
|
||||
exit(1);
|
||||
}
|
||||
else
|
||||
printf("%s✔%s ", CLR_GREEN, RESET);
|
||||
i++;
|
||||
}
|
||||
ft_atoi(NULL);
|
||||
printf("%s✔%s", CLR_GREEN, RESET);
|
||||
puts("\n");
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue