From 6da4166469e52d278a63fd94bc6c3e1abed76114 Mon Sep 17 00:00:00 2001 From: Cody Logan Date: Wed, 29 Nov 2023 10:12:53 -0800 Subject: Rewind temp input stream before using it --- test-convert-markdown.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'test-convert-markdown.c') diff --git a/test-convert-markdown.c b/test-convert-markdown.c index 403a68a..09a3d18 100644 --- a/test-convert-markdown.c +++ b/test-convert-markdown.c @@ -20,14 +20,19 @@ static int test_parse_file(const char* testname, const char* input, const char* FILE* instream = tmpfile(); FILE* outstream = tmpfile(); - /* for some reason, input isn't properly written to instream */ - fprintf(instream, "%s\n", input); + if (instream == NULL || outstream == NULL) { + printf("Error opening temporary file(s)"); + return 1; + } + + fprintf(instream, "%s", input); + rewind(instream); const int length = strlen(output) + 1; char buffer[length]; - /* TODO: use instream instead of stdin */ - _parse_file(stdin, outstream); + _parse_file(instream, outstream); + const int tmp_length = ftell(outstream) + 1; rewind(outstream); @@ -46,11 +51,11 @@ static int test_parse_file(const char* testname, const char* input, const char* } int main(void) { - printf("=============\nRunning Tests\n=============\n"); + 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("2. Bold", "**bold**", "

bold

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