diff --git a/libft_test/ft_isalpha_test.c b/libft_test/ft_isalpha_test.c old mode 100644 new mode 100755 index 765c667..ec505e0 --- a/libft_test/ft_isalpha_test.c +++ b/libft_test/ft_isalpha_test.c @@ -1,38 +1,37 @@ -/* ************************************************************************** */ -/* */ -/* ::: :::::::: */ -/* ft_isalpha_test.c :+: :+: :+: */ -/* +:+ +:+ +:+ */ -/* By: tischmid +#+ +:+ +#+ */ -/* +#+#+#+#+#+ +#+ */ -/* Created: 2023/05/02 18:43:57 by tischmid #+# #+# */ -/* Updated: 2023/05/02 21:23:43 by tischmid ### ########.fr */ -/* */ -/* ************************************************************************** */ +#!/usr/bin/env bash +tmp_out="$(mktemp)" + +grep -A9999 -- "[S]TART_OF_C_FILE" "${0}" | cc -Wall -Wextra -Werror -o "${tmp_out}" -xc "${0%_test.c}.c" - + +if [ ! -f "${tmp_out}" ]; then + printf "\e[31m%s\e[m\n" "Could not compile" + exit 1 +fi + +diff --expand-tabs --left-column --width="60" --side-by-side --label="Expected Output" --label=" Test Output" -- <("${tmp_out}" 2>&1 1>/dev/null) <("${tmp_out}" 2>/dev/null) && { printf "\e[102;30m%s\e[m\n" "All tests passed"; exit_status="0"; } || { printf "\e[101;37m%s\e[m\n" "At least one test failed"; exit_status="1"; } +rm -f -- "${tmp_out}" + +exit -- "${exit_status}" +// START_OF_C_FILE #include +#include + +#define test(expected_string, func, ...) \ + do { \ + fprintf(stderr, "%s", expected_string); \ + fflush(stderr); \ + int old_stderr_fd = dup(2); \ + dup2(1, 2); \ + func(__VA_ARGS__); \ + fflush(stdout); \ + dup2(old_stderr_fd, 2); \ + } while(0) int ft_isalpha(int c); -int printf_test(const char *format, ...) -{ - va_list listp; - int return_code; - - var_start(listp, fmt); - fprintf(1, "%s", ""); - return_code = vfprintf(1, format, listp); - fprintf(1, "%s", ""); - va_end(listp); - return (return_code); -} - -int printf_expect(const char *format, ...) -{ -} - -int main(int argc, char **argv) -{ - printf(); - return (0); +int main(){ + test("0\n", printf, "%d\n", ft_isalpha(96)); + test("Nonzero: 2\n", printf, "Nonzero: %d\n", ft_isalpha(97)); + return 0; }