aboutsummaryrefslogtreecommitdiff
path: root/test-convert-markdown.c
diff options
context:
space:
mode:
authorCody Logan <cody@lokken.dev>2023-11-29 10:12:08 -0800
committerCody Logan <cody@lokken.dev>2023-11-29 10:12:08 -0800
commit8268ded04a20963f8e527b6106c6c0df388afde9 (patch)
tree0bbb08e2cd795126e275da6b155942816e6b1ff6 /test-convert-markdown.c
parentaeed943e126bbc670250408a0f0db6df4445573c (diff)
downloadconvert-markdown-8268ded04a20963f8e527b6106c6c0df388afde9.tar.gz
convert-markdown-8268ded04a20963f8e527b6106c6c0df388afde9.zip
Revert "Use data files to test input and output"
This reverts commit aeed943e126bbc670250408a0f0db6df4445573c.
Diffstat (limited to 'test-convert-markdown.c')
-rw-r--r--test-convert-markdown.c41
1 files changed, 11 insertions, 30 deletions
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");