42tests-tischmid/libft_test/ft_isalpha_test.c

38 lines
1.1 KiB
C
Executable File

#!/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 <stdio.h>
#include <unistd.h>
#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 main(){
test("0\n", printf, "%d\n", ft_isalpha(96));
test("Nonzero: 2\n", printf, "Nonzero: %d\n", ft_isalpha(97));
return 0;
}