5 #include "testcaseparser.h"
6 #include "testcaseio.h"
9 * Read a testcase in from a file.
10 * On error, print a suitable message on stderr and return NULL.
11 * The returned testcase should be freed with testcase_free().
13 Testcase *testcase_parse_file(const char *filename)
16 TestcaseParser *parser;
18 const char *tag,*text;
19 boolean found_tag=FALSE;
20 parser=testcase_parser_new_from_file(filename);
23 if (!*testcase_parser_get_flag(parser))
25 fprintf(stderr,"%s: Not a valid testcase (flag)\n",filename);
26 testcase_parser_free(parser);
29 testcase=mem_new0(Testcase,1);
30 testcase->basename=path_get_basename(filename);
31 s=strrchr(testcase->basename,'.');
34 while(testcase_parser_get_next_tag(parser,&tag,&text))
36 if (!testcase->input && !strcmp(tag,"INPUT"))
37 testcase->input=str_dup(text);
38 else if (!testcase->expected && !strcmp(tag,"EXPECTED"))
39 testcase->expected=str_dup(text);
42 fprintf(stderr,"%s: Not a valid testcase (%s)\n",filename,tag);
43 testcase_free(testcase);
44 testcase_parser_free(parser);
49 if (!testcase_parser_at_eof(parser))
52 fprintf(stderr,"%s: Not a valid testcase (garbage at end)\n",
55 fprintf(stderr,"%s: Not a valid testcase (no valid tags)\n",
57 testcase_free(testcase);
58 testcase_parser_free(parser);
61 testcase_parser_free(parser);