Working PoC
This commit is contained in:
parent
3e14067060
commit
1f78947c38
|
@ -1,38 +1,37 @@
|
||||||
/* ************************************************************************** */
|
#!/usr/bin/env bash
|
||||||
/* */
|
|
||||||
/* ::: :::::::: */
|
|
||||||
/* 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 */
|
|
||||||
/* */
|
|
||||||
/* ************************************************************************** */
|
|
||||||
|
|
||||||
|
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 <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 ft_isalpha(int c);
|
||||||
|
|
||||||
int printf_test(const char *format, ...)
|
int main(){
|
||||||
{
|
test("0\n", printf, "%d\n", ft_isalpha(96));
|
||||||
va_list listp;
|
test("Nonzero: 2\n", printf, "Nonzero: %d\n", ft_isalpha(97));
|
||||||
int return_code;
|
return 0;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue