In verbose mode each instance of a questionable word is queried so don't give a count
6 #include "testcaseparser.h"
7 #include "testcaseinput.h"
8 #include "testcaseio.h"
9 #include "warningsparser.h"
12 * Read a testcase in from a file.
13 * On error, print a suitable message using g_printerr and return NULL.
14 * The returned testcase should be freed with testcase_free().
16 Testcase *testcase_parse_file(const char *filename)
19 TestcaseParser *parser;
20 TestcaseInput *input=NULL;
21 GMarkupParseContext *context;
24 const char *tag,*text;
25 gboolean found_tag=FALSE;
26 parser=testcase_parser_new_from_file(filename);
29 if (!*testcase_parser_get_flag(parser))
31 g_printerr("%s: Not a valid testcase (flag)\n",filename);
32 testcase_parser_free(parser);
35 testcase=g_new0(Testcase,1);
36 testcase->basename=g_path_get_basename(filename);
37 s=strrchr(testcase->basename,'.');
40 while(testcase_parser_get_next_tag(parser,&tag,&text))
42 if (!input && !strcmp(tag,"INPUT"))
43 input=testcase_input_new("TEST-XXXXXX",text);
44 else if (g_str_has_prefix(tag,"INPUT(") && tag[strlen(tag)-1]==')')
46 arg=g_strndup(tag+6,strlen(tag)-7);
47 s=g_path_get_dirname(arg);
51 * Otherwise it would be possible to overwrite an arbitary
52 * file on somebody's computer by getting them to run a
56 "%s: Input files may not have a directory component\n",arg);
59 testcase_free(testcase);
60 testcase_parser_free(parser);
64 testcase->inputs=g_slist_prepend(testcase->inputs,
65 testcase_input_new(arg,text));
66 if (!strstr(arg,"XXXXXX"))
67 testcase->flags|=TESTCASE_TMP_DIR;
70 else if (!testcase->expected && !testcase->warnings &&
71 !strcmp(tag,"EXPECTED"))
72 testcase->expected=g_strdup(text);
73 else if (!testcase->expected && !testcase->warnings &&
74 !strcmp(tag,"WARNINGS"))
76 context=warnings_parse_context_new(testcase);
77 if (!g_markup_parse_context_parse(context,text,-1,&err) ||
78 !g_markup_parse_context_end_parse(context,&err))
80 g_markup_parse_context_free(context);
81 g_printerr("%s\n",err->message);
83 testcase_free(testcase);
84 testcase_parser_free(parser);
87 g_markup_parse_context_free(context);
89 else if (!testcase->encoding && !strcmp(tag,"ENCODING"))
90 testcase->encoding=g_strchomp(g_strdup(text));
91 else if (!testcase->encoding && !strcmp(tag,"OPTIONS"))
93 testcase->options=g_strsplit(text,"\n",0);
94 g_free(testcase->options[g_strv_length(testcase->options)-1]);
95 testcase->options[g_strv_length(testcase->options)-1]=NULL;
99 g_printerr("%s: Not a valid testcase (%s)\n",filename,tag);
100 testcase_free(testcase);
101 testcase_parser_free(parser);
106 if (!testcase_parser_at_eof(parser))
109 g_printerr("%s: Not a valid testcase (garbage at end)\n",
112 g_printerr("%s: Not a valid testcase (no valid tags)\n",
114 testcase_free(testcase);
115 testcase_parser_free(parser);
119 input=testcase_input_new("TEST-XXXXXX",NULL);
120 testcase->inputs=g_slist_prepend(testcase->inputs,input);
121 testcase_parser_free(parser);