7 #define NELEMENTS(a) (sizeof (a)/sizeof *(a))
25 void (*test
)(line_category
&);
30 deft(line_category
&l
)
36 pass_fail(line_category
&l
)
38 if(FAIL
!=l
.test_result
)
39 l
.test_result
= strnstr(l
.line
, "FAIL", 4)? FAIL
: PASS
;
43 stderr_output(line_category
&l
)
45 if(FAIL
==l
.test_result
)
53 exit_test(line_category
&l
)
56 DBG("exit_test(%s)==%d\n", l
.line
, atoi(l
.line
));
61 #define STDOUT "stdout: "
62 #define STDERR "stderr: "
65 #define SEXIT "exit: "
66 line_category line_categories
[] = {
67 { CWD
, "" , deft
, NO_RESULT
}, /* must be first */
68 { CMD
, "", deft
, NO_RESULT
},
69 { STDOUT
, "", pass_fail
, NO_RESULT
},
70 { STDERR
, "", stderr_output
, NO_RESULT
},
71 { SEXIT
, "", exit_test
, NO_RESULT
},
74 static line_category no_line_category
= { "none", "no test", deft
, NO_RESULT
};
77 retrieve(line_category
&l
, const char *s
)
80 line_category
*lp
= &l
;
81 //int final_result = PASS;
83 for(j
=0; j
<NELEMENTS(line_categories
); ++j
,++lp
) {//TODO: remove NELEMENTS
84 if(!strcmp(lp
->key
, s
)) {
87 for(p
=(char *)lp
->line
; *p
; ++p
) {
99 DBG("FOUND line_categories[j].line==%s\n", lp
->line
);
100 return line_categories
[j
];
104 return no_line_category
;
108 xml_string_print(FILE *strm
, const char *s
)
116 fputs("&", strm
);
128 // FAIL if stderr non-zero
129 // FAIL if stdout=="FAIL"
130 // UNRESOLVED if make exit non-zero
139 int final_result
= PASS
;
141 for(j
=0; j
<NELEMENTS(line_categories
); ++j
) {
142 if(line_categories
[j
].line
[0]) {
143 line_categories
[j
].line
[strlen(line_categories
[j
].line
)-1] = '\0';
144 DBG("%s%s RESULT %d\n"
145 , line_categories
[j
].key
146 , line_categories
[j
].line
147 , line_categories
[j
].test_result
150 if(PASS
==final_result
) {
151 final_result
= line_categories
[j
].test_result
;
152 if(NO_RESULT
==line_categories
[j
].test_result
) {
153 final_result
= NO_RESULT
;
154 } else if(FAIL
==line_categories
[j
].test_result
) {
161 printf("<test name=");
162 xml_string_print(stdout
, retrieve(line_categories
[0], CMD
).line
);
163 printf(" result=\"");
164 if(NO_RESULT
==final_result
) {
165 printf("UNRESOLVED");
166 } else if(FAIL
==final_result
) {
173 char *s
= retrieve(line_categories
[0], CWD
).line
;
179 strncpy(fn
, s
, sizeof fn
);
180 strncat(fn
, "/comment.txt", sizeof fn
);
181 strm
= fopen(fn
, "r");
183 if(fgets(detail
, -1+sizeof detail
, strm
)) {
184 detail
[strlen(detail
)-1] = '\0';
186 xml_string_print(stdout
, detail
);
192 printf(" <diagnostics>\n");
193 s
= retrieve(line_categories
[0], STDERR
).line
;
195 printf(" <diagnostic line=\"%d\" message=", ++cnt
);
196 xml_string_print(stdout
, s
);
197 printf(" severity=\"ERROR\"/>\n");
200 s
= retrieve(line_categories
[0], STDOUT
).line
;
202 printf(" <diagnostic line=\"%d\" message=", ++cnt
);
203 xml_string_print(stdout
, s
);
204 printf(" severity=\"note\"/>\n");
207 printf(" </diagnostics>\n");
208 printf("</test>\n\n");
210 for(j
=0; j
<NELEMENTS(line_categories
); ++j
) {
211 line_categories
[j
].line
[0] = '\0';
212 line_categories
[j
].test_result
= NO_RESULT
;
217 main(int argc
, char **argv
)
230 fgets(line
, sizeof line
, stdin
);
237 size_t len
= strlen(line_categories
[i
].key
);
239 //DBG("strnstr(%s, %s, %u)\n", line, line_categories[i].key, len);
240 if(strnstr(line
, line_categories
[i
].key
, len
)) {
246 char *lp
= &line
[len
];
247 //DBG("%s%s", line_categories[i].key, lp);
248 strncpy(line_categories
[i
].line
, lp
, sizeof line_categories
[i
].line
);
249 line_categories
[i
].test(line_categories
[i
]);
253 if(i
==NELEMENTS(line_categories
)-1) {
254 DBG("BADLINE:%s", line
);