From 8fba4d45ad8fc5c2a0b1d209751445909a256da4 Mon Sep 17 00:00:00 2001 From: Timo Schmidt Date: Wed, 3 May 2023 21:38:30 +0200 Subject: [PATCH] New template, named side by side view --- libft_test/ft_isalpha_test.c | 52 +++++++++++++++++---------------- libft_test/ft_isdigit_test.c | 56 +++++++++++++++++++----------------- template_test.c | 27 +++++++++++++---- 3 files changed, 77 insertions(+), 58 deletions(-) diff --git a/libft_test/ft_isalpha_test.c b/libft_test/ft_isalpha_test.c index d47c037..ac62f62 100755 --- a/libft_test/ft_isalpha_test.c +++ b/libft_test/ft_isalpha_test.c @@ -52,29 +52,31 @@ exit -- "${exit_status}" int ft_isalpha(int c); int main(){ - test( "'a'", printf, "%d\n", ft_isalpha('a')); - expect( "'a'", printf, "%d\n", isalpha('a')); - test( "'A'", printf, "%d\n", ft_isalpha('A')); - expect( "'A'", printf, "%d\n", isalpha('A')); - test( "'m'", printf, "%d\n", ft_isalpha('m')); - expect( "'m'", printf, "%d\n", isalpha('m')); - test( "'M'", printf, "%d\n", ft_isalpha('M')); - expect( "'M'", printf, "%d\n", isalpha('M')); - test( "'z'", printf, "%d\n", ft_isalpha('z')); - expect( "'z'", printf, "%d\n", isalpha('z')); - test( "'Z'", printf, "%d\n", ft_isalpha('Z')); - expect( "'Z'", printf, "%d\n", isalpha('Z')); - test( "0", printf, "%d\n", ft_isalpha(0)); - expect( "0", printf, "%d\n", isalpha(0)); - test( "1", printf, "%d\n", ft_isalpha(1)); - expect( "1", printf, "%d\n", isalpha(1)); - test( "'a' - 1", printf, "%d\n", ft_isalpha('a' - 1)); - expect("'a' - 1", printf, "%d\n", isalpha('a' - 1)); - test( "'A' - 1", printf, "%d\n", ft_isalpha('A' - 1)); - expect("'A' - 1", printf, "%d\n", isalpha('A' - 1)); - test( "'z' + 1", printf, "%d\n", ft_isalpha('z' + 1)); - expect("'z' + 1", printf, "%d\n", isalpha('z' + 1)); - test( "'Z' + 1", printf, "%d\n", ft_isalpha('Z' + 1)); - expect("'Z' + 1", printf, "%d\n", isalpha('Z' + 1)); - return 0; + test( "Test output", printf, "\n"); + expect("Expected output", printf, "\n"); + test( "'a'", printf, "%d\n", ft_isalpha('a')); + expect( "'a'", printf, "%d\n", isalpha('a')); + test( "'A'", printf, "%d\n", ft_isalpha('A')); + expect( "'A'", printf, "%d\n", isalpha('A')); + test( "'m'", printf, "%d\n", ft_isalpha('m')); + expect( "'m'", printf, "%d\n", isalpha('m')); + test( "'M'", printf, "%d\n", ft_isalpha('M')); + expect( "'M'", printf, "%d\n", isalpha('M')); + test( "'z'", printf, "%d\n", ft_isalpha('z')); + expect( "'z'", printf, "%d\n", isalpha('z')); + test( "'Z'", printf, "%d\n", ft_isalpha('Z')); + expect( "'Z'", printf, "%d\n", isalpha('Z')); + test( "0", printf, "%d\n", ft_isalpha(0)); + expect( "0", printf, "%d\n", isalpha(0)); + test( "1", printf, "%d\n", ft_isalpha(1)); + expect( "1", printf, "%d\n", isalpha(1)); + test( "'a' - 1", printf, "%d\n", ft_isalpha('a' - 1)); + expect("'a' - 1", printf, "%d\n", isalpha('a' - 1)); + test( "'A' - 1", printf, "%d\n", ft_isalpha('A' - 1)); + expect("'A' - 1", printf, "%d\n", isalpha('A' - 1)); + test( "'z' + 1", printf, "%d\n", ft_isalpha('z' + 1)); + expect("'z' + 1", printf, "%d\n", isalpha('z' + 1)); + test( "'Z' + 1", printf, "%d\n", ft_isalpha('Z' + 1)); + expect("'Z' + 1", printf, "%d\n", isalpha('Z' + 1)); + return 0; } diff --git a/libft_test/ft_isdigit_test.c b/libft_test/ft_isdigit_test.c index 61d50f7..9ab0772 100755 --- a/libft_test/ft_isdigit_test.c +++ b/libft_test/ft_isdigit_test.c @@ -52,31 +52,33 @@ exit -- "${exit_status}" int ft_isdigit(int c); int main(){ - test( "'0'", printf, "%d\n", ft_isdigit('0')); - expect("'0'", printf, "%d\n", isdigit('0')); - test( "'1'", printf, "%d\n", ft_isdigit('1')); - expect("'1'", printf, "%d\n", isdigit('1')); - test( "'2'", printf, "%d\n", ft_isdigit('2')); - expect("'2'", printf, "%d\n", isdigit('2')); - test( "'3'", printf, "%d\n", ft_isdigit('3')); - expect("'3'", printf, "%d\n", isdigit('3')); - test( "'4'", printf, "%d\n", ft_isdigit('4')); - expect("'4'", printf, "%d\n", isdigit('4')); - test( "'5'", printf, "%d\n", ft_isdigit('5')); - expect("'5'", printf, "%d\n", isdigit('5')); - test( "'6'", printf, "%d\n", ft_isdigit('6')); - expect("'6'", printf, "%d\n", isdigit('6')); - test( "'7'", printf, "%d\n", ft_isdigit('7')); - expect("'7'", printf, "%d\n", isdigit('7')); - test( "'8'", printf, "%d\n", ft_isdigit('8')); - expect("'8'", printf, "%d\n", isdigit('8')); - test( "'9'", printf, "%d\n", ft_isdigit('9')); - expect("'9'", printf, "%d\n", isdigit('9')); - test( "0", printf, "%d\n", ft_isdigit(0)); - expect("0", printf, "%d\n", isdigit(0)); - test( "1", printf, "%d\n", ft_isdigit(1)); - expect("1", printf, "%d\n", isdigit(1)); - test( "127", printf, "%d\n", ft_isdigit(127)); - expect("127", printf, "%d\n", isdigit(127)); - return 0; + test( "Test output", printf, "\n"); + expect("Expected output", printf, "\n"); + test( "'0'", printf, "%d\n", ft_isdigit('0')); + expect("'0'", printf, "%d\n", isdigit('0')); + test( "'1'", printf, "%d\n", ft_isdigit('1')); + expect("'1'", printf, "%d\n", isdigit('1')); + test( "'2'", printf, "%d\n", ft_isdigit('2')); + expect("'2'", printf, "%d\n", isdigit('2')); + test( "'3'", printf, "%d\n", ft_isdigit('3')); + expect("'3'", printf, "%d\n", isdigit('3')); + test( "'4'", printf, "%d\n", ft_isdigit('4')); + expect("'4'", printf, "%d\n", isdigit('4')); + test( "'5'", printf, "%d\n", ft_isdigit('5')); + expect("'5'", printf, "%d\n", isdigit('5')); + test( "'6'", printf, "%d\n", ft_isdigit('6')); + expect("'6'", printf, "%d\n", isdigit('6')); + test( "'7'", printf, "%d\n", ft_isdigit('7')); + expect("'7'", printf, "%d\n", isdigit('7')); + test( "'8'", printf, "%d\n", ft_isdigit('8')); + expect("'8'", printf, "%d\n", isdigit('8')); + test( "'9'", printf, "%d\n", ft_isdigit('9')); + expect("'9'", printf, "%d\n", isdigit('9')); + test( "0", printf, "%d\n", ft_isdigit(0)); + expect("0", printf, "%d\n", isdigit(0)); + test( "1", printf, "%d\n", ft_isdigit(1)); + expect("1", printf, "%d\n", isdigit(1)); + test( "127", printf, "%d\n", ft_isdigit(127)); + expect("127", printf, "%d\n", isdigit(127)); + return 0; } diff --git a/template_test.c b/template_test.c index d2969b3..485a8c7 100755 --- a/template_test.c +++ b/template_test.c @@ -22,20 +22,35 @@ exit -- "${exit_status}" #include #include -#define test(out_prefix, expected_string, func, ...) \ +#define test(inp, func, ...) \ do { \ - fprintf(stderr, "Case:%s:%s", out_prefix, expected_string); \ - fflush(stderr); \ int old_stderr_fd = dup(2); \ dup2(1, 2); \ - fprintf(stdout, "Case:%s:", out_prefix); \ + fprintf(stdout, "Case:%s:", inp); \ fflush(stdout); \ func(__VA_ARGS__); \ + fflush(stderr); \ fflush(stdout); \ dup2(old_stderr_fd, 2); \ } while(0) +#define expect(inp, func, ...) \ + do { \ + int old_stdout_fd = dup(1); \ + dup2(2, 1); \ + fprintf(stderr, "Case:%s:", inp); \ + fflush(stderr); \ + func(__VA_ARGS__); \ + fflush(stderr); \ + fflush(stdout); \ + dup2(old_stdout_fd, 1); \ + } while(0) +// Don't delete above this comment + +#include + int main(){ - test("dummy", "true\n", printf, "%s\n", "true"); - return 0; + test( "Test output", printf, "\n"); + expect("Expected output", printf, "\n"); + return 0; }