diff options
| author | Cody Logan <cody@lokken.dev> | 2023-11-29 10:12:08 -0800 |
|---|---|---|
| committer | Cody Logan <cody@lokken.dev> | 2023-11-29 10:12:08 -0800 |
| commit | 8268ded04a20963f8e527b6106c6c0df388afde9 (patch) | |
| tree | 0bbb08e2cd795126e275da6b155942816e6b1ff6 | |
| parent | aeed943e126bbc670250408a0f0db6df4445573c (diff) | |
| download | convert-markdown-8268ded04a20963f8e527b6106c6c0df388afde9.tar.gz convert-markdown-8268ded04a20963f8e527b6106c6c0df388afde9.zip | |
Revert "Use data files to test input and output"
This reverts commit aeed943e126bbc670250408a0f0db6df4445573c.
| -rw-r--r-- | Makefile | 4 | ||||
| -rw-r--r-- | test-1-input.txt | 1 | ||||
| -rw-r--r-- | test-1-output.txt | 1 | ||||
| -rw-r--r-- | test-2-input.txt | 1 | ||||
| -rw-r--r-- | test-2-output.txt | 1 | ||||
| -rw-r--r-- | test-convert-markdown.c | 41 |
6 files changed, 13 insertions, 36 deletions
@@ -13,13 +13,13 @@ convert-markdown: $(OBJS) $(OBJS): config.h clean: - rm -f convert-markdown $(OBJS) test-convert-markdown $(TESTOBJS) + rm -f convert-markdown $(OBJS) test-convert-markdown distclean: clean rm -f Makefile.configure config.h config.log config.h.old config.log.old check: tests - @./test-convert-markdown + @echo "# header" | ./test-convert-markdown tests: test-convert-markdown diff --git a/test-1-input.txt b/test-1-input.txt deleted file mode 100644 index 6f83f34..0000000 --- a/test-1-input.txt +++ /dev/null @@ -1 +0,0 @@ -# header diff --git a/test-1-output.txt b/test-1-output.txt deleted file mode 100644 index 5b47623..0000000 --- a/test-1-output.txt +++ /dev/null @@ -1 +0,0 @@ -<h1 id="header">header</h1> diff --git a/test-2-input.txt b/test-2-input.txt deleted file mode 100644 index 1c2717d..0000000 --- a/test-2-input.txt +++ /dev/null @@ -1 +0,0 @@ -*italic* diff --git a/test-2-output.txt b/test-2-output.txt deleted file mode 100644 index 73a5a0c..0000000 --- a/test-2-output.txt +++ /dev/null @@ -1 +0,0 @@ -<p><em>italic</em></p> diff --git a/test-convert-markdown.c b/test-convert-markdown.c index 4ef2e16..403a68a 100644 --- a/test-convert-markdown.c +++ b/test-convert-markdown.c @@ -16,60 +16,41 @@ #include "parse-file.h" -static int test_parse_file(const char* testname, const char* infile, const char* outfile) { +static int test_parse_file(const char* testname, const char* input, const char* output) { + FILE* instream = tmpfile(); FILE* outstream = tmpfile(); - FILE* outptr = fopen(outfile, "r"); - if (outptr == NULL) { - printf("ERROR: could not read test data file\n"); - return 1; - } - - // find length of expected output - fseek(outptr, 0L, SEEK_END); - const int length = ftell(outptr) + 1; - rewind(outptr); + /* for some reason, input isn't properly written to instream */ + fprintf(instream, "%s\n", input); + const int length = strlen(output) + 1; char buffer[length]; - char output[length]; - - // read expected output from outfile - fgets(output, length, outptr); - fclose(outptr); - // read expected input from infile and redirect to stdin - if (freopen(infile, "r", stdin) != NULL) { - _parse_file(stdin, outstream); - } else { - printf("ERROR: could not read test data file\n"); - return 1; - } + /* TODO: use instream instead of stdin */ + _parse_file(stdin, outstream); const int tmp_length = ftell(outstream) + 1; rewind(outstream); - // grab program output fgets(buffer, length, outstream); + fclose(instream); fclose(outstream); - // compare actual output to expected output if (strcmp(buffer, output) == 0 && tmp_length == length) { printf("%s test succeeded\n", testname); return 0; } else { printf("%s test failed\n", testname); - printf("%s\n!=\n%s\n", buffer, output); + printf("%s !=\n%s\n", buffer, output); return 1; } } int main(void) { - printf("\n=============\nRunning Tests\n=============\n"); + printf("=============\nRunning Tests\n=============\n"); int errors = 0; - //errors += test_parse_file("1. Header", "# header", "<h1 id=\"header\">header</h1>\n"); + errors += test_parse_file("1. Header", "# header", "<h1 id=\"header\">header</h1>\n"); //errors += test_parse_file("2. Bold", "*bold*", "<strong>bold</strong>\n"); - errors += test_parse_file("1. Header", "test-1-input.txt", "test-1-output.txt"); - errors += test_parse_file("2. Emphasis", "test-2-input.txt", "test-2-output.txt"); printf("\n============\nTest Summary\n============\n"); |
