From 9e90de0981a9c6c12e81f24b9f4d1428a26a090a Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Wed, 29 Nov 2023 10:41:24 -0800 Subject: Refine test runner to account for multiline output --- test-convert-markdown.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/test-convert-markdown.c b/test-convert-markdown.c index 09a3d18..d2eb1a7 100644 --- a/test-convert-markdown.c +++ b/test-convert-markdown.c @@ -36,7 +36,12 @@ static int test_parse_file(const char* testname, const char* input, const char* const int tmp_length = ftell(outstream) + 1; rewind(outstream); - fgets(buffer, length, outstream); + char* result; + size_t len = 0; + do { + result = fgets(buffer + len, length - len, outstream); + len = strlen(buffer); + } while (result); fclose(instream); fclose(outstream); @@ -45,7 +50,7 @@ static int test_parse_file(const char* testname, const char* input, const char* return 0; } else { printf("%s test failed\n", testname); - printf("%s !=\n%s\n", buffer, output); + printf("%s\n !=\n%s\n", buffer, output); return 1; } } @@ -54,8 +59,15 @@ int main(void) { printf("\n=============\nRunning Tests\n=============\n"); int errors = 0; - errors += test_parse_file("1. Header", "# header", "

header

\n"); - errors += test_parse_file("2. Bold", "**bold**", "

bold

\n"); + errors += test_parse_file("1. Header", + "# header", + "

header

\n"); + errors += test_parse_file("2. Bold", + "**bold**", + "

bold

\n"); + errors += test_parse_file("3. Multiline", + "# header\n`code`", + "

header

\n\n

code

\n"); printf("\n============\nTest Summary\n============\n"); -- cgit v1.2.3