Working PoC

This commit is contained in:
cubernetes 2023-05-03 14:11:08 +02:00
parent 3e14067060
commit 1f78947c38
1 changed files with 31 additions and 32 deletions

63
libft_test/ft_isalpha_test.c Normal file → Executable file
View File

@ -1,38 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_isalpha_test.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tischmid <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <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 printf_test(const char *format, ...)
{
va_list listp;
int return_code;
var_start(listp, fmt);
fprintf(1, "%s", "<TEST>");
return_code = vfprintf(1, format, listp);
fprintf(1, "%s", "</TEST>");
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;
}