| 1 |
--- check-0.9.3.orig/src/check_impl.h |
| 2 |
+++ check-0.9.3/src/check_impl.h |
| 3 |
@@ -86,6 +86,7 @@ |
| 4 |
CLSTART_S, |
| 5 |
CLEND_SR, |
| 6 |
CLEND_S, |
| 7 |
+ CLSTART_T, /* A test case is about to run */ |
| 8 |
CLEND_T |
| 9 |
}; |
| 10 |
|
| 11 |
--- check-0.9.3.orig/src/check_log.c |
| 12 |
+++ check-0.9.3/src/check_log.c |
| 13 |
@@ -25,12 +25,14 @@ |
| 14 |
#include <sys/time.h> |
| 15 |
#include <time.h> |
| 16 |
#include <check.h> |
| 17 |
+#include <subunit/child.h> |
| 18 |
|
| 19 |
#include "check_error.h" |
| 20 |
#include "check_list.h" |
| 21 |
#include "check_impl.h" |
| 22 |
#include "check_log.h" |
| 23 |
#include "check_print.h" |
| 24 |
+#include "check_str.h" |
| 25 |
|
| 26 |
|
| 27 |
static void srunner_send_evt (SRunner *sr, void *obj, enum cl_event evt); |
| 28 |
@@ -107,6 +109,13 @@ |
| 29 |
srunner_send_evt (sr, s, CLEND_S); |
| 30 |
} |
| 31 |
|
| 32 |
+void log_test_start (SRunner *sr, TCase * tc, TF * tfun) |
| 33 |
+{ |
| 34 |
+ char buffer[100]; |
| 35 |
+ snprintf(buffer, 99, "%s:%s", tc->name, tfun->name); |
| 36 |
+ srunner_send_evt (sr, buffer, CLSTART_T); |
| 37 |
+} |
| 38 |
+ |
| 39 |
void log_test_end (SRunner *sr, TestResult *tr) |
| 40 |
{ |
| 41 |
srunner_send_evt (sr, tr, CLEND_T); |
| 42 |
@@ -128,7 +137,6 @@ |
| 43 |
void stdout_lfun (SRunner *sr, FILE *file, enum print_output printmode, |
| 44 |
void *obj, enum cl_event evt) |
| 45 |
{ |
| 46 |
- TestResult *tr; |
| 47 |
Suite *s; |
| 48 |
|
| 49 |
if (printmode == CK_ENV) { |
| 50 |
@@ -160,8 +168,9 @@ |
| 51 |
case CLEND_S: |
| 52 |
s = obj; |
| 53 |
break; |
| 54 |
+ case CLSTART_T: |
| 55 |
+ break; |
| 56 |
case CLEND_T: |
| 57 |
- tr = obj; |
| 58 |
break; |
| 59 |
default: |
| 60 |
eprintf("Bad event type received in stdout_lfun", __FILE__, __LINE__); |
| 61 |
@@ -194,12 +203,14 @@ |
| 62 |
case CLEND_S: |
| 63 |
s = obj; |
| 64 |
break; |
| 65 |
+ case CLSTART_T: |
| 66 |
+ break; |
| 67 |
case CLEND_T: |
| 68 |
tr = obj; |
| 69 |
tr_fprint(file, tr, CK_VERBOSE); |
| 70 |
break; |
| 71 |
default: |
| 72 |
- eprintf("Bad event type received in stdout_lfun", __FILE__, __LINE__); |
| 73 |
+ eprintf("Bad event type received in lfile_lfun", __FILE__, __LINE__); |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
@@ -247,6 +258,8 @@ |
| 78 |
fprintf(file, " </suite>\n"); |
| 79 |
s = obj; |
| 80 |
break; |
| 81 |
+ case CLSTART_T: |
| 82 |
+ break; |
| 83 |
case CLEND_T: |
| 84 |
tr = obj; |
| 85 |
tr_xmlprint(file, tr, CK_VERBOSE); |
| 86 |
@@ -258,6 +271,66 @@ |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
+void subunit_lfun (SRunner *sr, FILE *file, enum print_output printmode, |
| 91 |
+ void *obj, enum cl_event evt) |
| 92 |
+{ |
| 93 |
+ TestResult *tr; |
| 94 |
+ Suite *s; |
| 95 |
+ char const * name; |
| 96 |
+ |
| 97 |
+ /* assert(printmode == CK_SUBUNIT); */ |
| 98 |
+ |
| 99 |
+ switch (evt) { |
| 100 |
+ case CLINITLOG_SR: |
| 101 |
+ break; |
| 102 |
+ case CLENDLOG_SR: |
| 103 |
+ break; |
| 104 |
+ case CLSTART_SR: |
| 105 |
+ break; |
| 106 |
+ case CLSTART_S: |
| 107 |
+ s = obj; |
| 108 |
+ break; |
| 109 |
+ case CLEND_SR: |
| 110 |
+ if (printmode > CK_SILENT) { |
| 111 |
+ fprintf (file, "\n"); |
| 112 |
+ srunner_fprint (file, sr, printmode); |
| 113 |
+ } |
| 114 |
+ break; |
| 115 |
+ case CLEND_S: |
| 116 |
+ s = obj; |
| 117 |
+ break; |
| 118 |
+ case CLSTART_T: |
| 119 |
+ name = obj; |
| 120 |
+ subunit_test_start(name); |
| 121 |
+ break; |
| 122 |
+ case CLEND_T: |
| 123 |
+ tr = obj; |
| 124 |
+ { |
| 125 |
+ char *name = ck_strdup_printf ("%s:%s", tr->tcname, tr->tname); |
| 126 |
+ char *msg = tr_short_str (tr); |
| 127 |
+ switch (tr->rtype) { |
| 128 |
+ case CK_PASS: |
| 129 |
+ subunit_test_pass(name); |
| 130 |
+ break; |
| 131 |
+ case CK_FAILURE: |
| 132 |
+ subunit_test_fail(name, msg); |
| 133 |
+ break; |
| 134 |
+ case CK_ERROR: |
| 135 |
+ subunit_test_error(name, msg); |
| 136 |
+ break; |
| 137 |
+ default: |
| 138 |
+ eprintf("Bad result type in subunit_lfun", __FILE__, __LINE__); |
| 139 |
+ free(name); |
| 140 |
+ free(msg); |
| 141 |
+ } |
| 142 |
+ } |
| 143 |
+ break; |
| 144 |
+ default: |
| 145 |
+ eprintf("Bad event type received in subunit_lfun", __FILE__, __LINE__); |
| 146 |
+ } |
| 147 |
+} |
| 148 |
+ |
| 149 |
+ |
| 150 |
FILE *srunner_open_lfile (SRunner *sr) |
| 151 |
{ |
| 152 |
FILE *f = NULL; |
| 153 |
@@ -286,7 +359,10 @@ |
| 154 |
{ |
| 155 |
FILE *f; |
| 156 |
sr->loglst = check_list_create(); |
| 157 |
- srunner_register_lfun (sr, stdout, 0, stdout_lfun, print_mode); |
| 158 |
+ if (print_mode != CK_SUBUNIT) |
| 159 |
+ srunner_register_lfun (sr, stdout, 0, stdout_lfun, print_mode); |
| 160 |
+ else |
| 161 |
+ srunner_register_lfun (sr, stdout, 0, subunit_lfun, print_mode); |
| 162 |
f = srunner_open_lfile (sr); |
| 163 |
if (f) { |
| 164 |
srunner_register_lfun (sr, f, 1, lfile_lfun, print_mode); |
| 165 |
--- check-0.9.3.orig/src/check_log.h |
| 166 |
+++ check-0.9.3/src/check_log.h |
| 167 |
@@ -26,6 +26,7 @@ |
| 168 |
void log_suite_start (SRunner *sr, Suite *s); |
| 169 |
void log_suite_end (SRunner *sr, Suite *s); |
| 170 |
void log_test_end (SRunner *sr, TestResult *tr); |
| 171 |
+void log_test_start (SRunner *sr, TCase *tc, TF *tfun); |
| 172 |
|
| 173 |
void stdout_lfun (SRunner *sr, FILE *file, enum print_output, |
| 174 |
void *obj, enum cl_event evt); |
| 175 |
@@ -36,6 +37,9 @@ |
| 176 |
void xml_lfun (SRunner *sr, FILE *file, enum print_output, |
| 177 |
void *obj, enum cl_event evt); |
| 178 |
|
| 179 |
+void subunit_lfun (SRunner *sr, FILE *file, enum print_output, |
| 180 |
+ void *obj, enum cl_event evt); |
| 181 |
+ |
| 182 |
void srunner_register_lfun (SRunner *sr, FILE *lfile, int close, |
| 183 |
LFun lfun, enum print_output); |
| 184 |
|
| 185 |
--- check-0.9.3.orig/src/check_run.c |
| 186 |
+++ check-0.9.3/src/check_run.c |
| 187 |
@@ -181,6 +181,7 @@ |
| 188 |
|
| 189 |
for (list_front(tfl); !list_at_end (tfl); list_advance (tfl)) { |
| 190 |
tfun = list_val (tfl); |
| 191 |
+ log_test_start (sr, tc, tfun); |
| 192 |
switch (srunner_fork_status(sr)) { |
| 193 |
case CK_FORK: |
| 194 |
tr = tcase_run_tfun_fork (sr, tc, tfun); |
| 195 |
--- check-0.9.3.orig/src/check_str.c |
| 196 |
+++ check-0.9.3/src/check_str.c |
| 197 |
@@ -47,6 +47,20 @@ |
| 198 |
return rstr; |
| 199 |
} |
| 200 |
|
| 201 |
+char *tr_short_str (TestResult *tr) |
| 202 |
+{ |
| 203 |
+ const char *exact_msg; |
| 204 |
+ char *rstr; |
| 205 |
+ |
| 206 |
+ exact_msg = (tr->rtype == CK_ERROR) ? "(after this point) ": ""; |
| 207 |
+ |
| 208 |
+ rstr = ck_strdup_printf ("%s:%d: %s%s", |
| 209 |
+ tr->file, tr->line, |
| 210 |
+ exact_msg, tr->msg); |
| 211 |
+ |
| 212 |
+ return rstr; |
| 213 |
+} |
| 214 |
+ |
| 215 |
char *sr_stat_str (SRunner *sr) |
| 216 |
{ |
| 217 |
char *str; |
| 218 |
--- check-0.9.3.orig/src/check_str.h |
| 219 |
+++ check-0.9.3/src/check_str.h |
| 220 |
@@ -25,6 +25,12 @@ |
| 221 |
value has been malloc'd, and must be freed by the caller */ |
| 222 |
char *tr_str (TestResult *tr); |
| 223 |
|
| 224 |
+/* Return a string representation of the given TestResult message |
| 225 |
+ without the test id or result type. This is suitable for separate |
| 226 |
+ formatting of the test and the message. Return value has been |
| 227 |
+ malloc'd, and must be freed by the caller */ |
| 228 |
+char *tr_short_str (TestResult *tr); |
| 229 |
+ |
| 230 |
/* Return a string representation of the given SRunner's run |
| 231 |
statistics (% passed, num run, passed, errors, failures). Return |
| 232 |
value has been malloc'd, and must be freed by the caller |
| 233 |
--- check-0.9.3.orig/src/check.h.in |
| 234 |
+++ check-0.9.3/src/check.h.in |
| 235 |
@@ -212,6 +212,7 @@ |
| 236 |
CK_NORMAL, /* All failed tests */ |
| 237 |
CK_VERBOSE, /* All tests */ |
| 238 |
CK_ENV, /* Look at environment var */ |
| 239 |
+ CK_SUBUNIT, /* Run as a subunit child process */ |
| 240 |
CK_LAST |
| 241 |
}; |
| 242 |
|
| 243 |
--- check-0.9.3.orig/src/check_print.c |
| 244 |
+++ check-0.9.3/src/check_print.c |
| 245 |
@@ -54,7 +54,7 @@ |
| 246 |
static void srunner_fprint_summary (FILE *file, SRunner *sr, |
| 247 |
enum print_output print_mode) |
| 248 |
{ |
| 249 |
- if (print_mode >= CK_MINIMAL) { |
| 250 |
+ if (print_mode >= CK_MINIMAL && print_mode != CK_SUBUNIT) { |
| 251 |
char *str; |
| 252 |
|
| 253 |
str = sr_stat_str (sr); |
| 254 |
@@ -68,6 +68,9 @@ |
| 255 |
enum print_output print_mode) |
| 256 |
{ |
| 257 |
List *resultlst; |
| 258 |
+ |
| 259 |
+ if (print_mode == CK_SUBUNIT) |
| 260 |
+ return; |
| 261 |
|
| 262 |
resultlst = sr->resultlst; |
| 263 |
|
| 264 |
--- check-0.9.3.orig/tests/ex_output.c |
| 265 |
+++ check-0.9.3/tests/ex_output.c |
| 266 |
@@ -51,7 +51,7 @@ |
| 267 |
{ |
| 268 |
|
| 269 |
if (argc != 2) { |
| 270 |
- printf ("Usage: ex_output (CK_SILENT | CK_MINIMAL | CK_NORMAL | CK_VERBOSE)\n"); |
| 271 |
+ printf ("Usage: ex_output (CK_SILENT | CK_MINIMAL | CK_NORMAL | CK_VERBOSE | CK_SUBUNIT)\n"); |
| 272 |
return EXIT_FAILURE; |
| 273 |
} |
| 274 |
|
| 275 |
@@ -63,8 +63,10 @@ |
| 276 |
run_tests(CK_NORMAL); |
| 277 |
else if (strcmp (argv[1], "CK_VERBOSE") == 0) |
| 278 |
run_tests(CK_VERBOSE); |
| 279 |
+ else if (strcmp (argv[1], "CK_SUBUNIT") == 0) |
| 280 |
+ run_tests(CK_SUBUNIT); |
| 281 |
else { |
| 282 |
- printf ("Usage: ex_output (CK_SILENT | CK_MINIMAL | CK_NORMAL | CK_VERBOSE)\n"); |
| 283 |
+ printf ("Usage: ex_output (CK_SILENT | CK_MINIMAL | CK_NORMAL | CK_VERBOSE | CK_SUBUNIT)\n"); |
| 284 |
return EXIT_FAILURE; |
| 285 |
} |
| 286 |
|
| 287 |
--- check-0.9.3.orig/tests/check_check_log.c |
| 288 |
+++ check-0.9.3/tests/check_check_log.c |
| 289 |
@@ -2,6 +2,9 @@ |
| 290 |
#include <stdlib.h> |
| 291 |
#include <string.h> |
| 292 |
#include <check.h> |
| 293 |
+#include <check_list.h> |
| 294 |
+#include <check_impl.h> |
| 295 |
+#include <check_log.h> |
| 296 |
#include "check_check.h" |
| 297 |
|
| 298 |
|
| 299 |
@@ -78,15 +81,40 @@ |
| 300 |
} |
| 301 |
END_TEST |
| 302 |
|
| 303 |
+ |
| 304 |
+START_TEST(test_init_logging_subunit) |
| 305 |
+{ |
| 306 |
+ /* init_logging with CK_SUBUNIT sets stdout |
| 307 |
+ * to a subunit function, not any log. |
| 308 |
+ */ |
| 309 |
+ Log * first_log = NULL; |
| 310 |
+ Suite *s = suite_create("Suite"); |
| 311 |
+ SRunner *sr = srunner_create(s); |
| 312 |
+ srunner_init_logging(sr, CK_SUBUNIT); |
| 313 |
+ list_front (sr->loglst); |
| 314 |
+ fail_if (list_at_end(sr->loglst), "No entries in log list"); |
| 315 |
+ first_log = list_val(sr->loglst); |
| 316 |
+ fail_if (first_log == NULL, "log is NULL"); |
| 317 |
+ list_advance(sr->loglst); |
| 318 |
+ fail_unless(list_at_end(sr->loglst), "More than one entry in log list"); |
| 319 |
+ fail_unless(first_log->lfun == subunit_lfun, |
| 320 |
+ "Log function is not the subunit lfun."); |
| 321 |
+ srunner_end_logging(sr); |
| 322 |
+ srunner_free(sr); |
| 323 |
+} |
| 324 |
+END_TEST |
| 325 |
+ |
| 326 |
+ |
| 327 |
Suite *make_log_suite(void) |
| 328 |
{ |
| 329 |
|
| 330 |
Suite *s; |
| 331 |
- TCase *tc_core, *tc_core_xml; |
| 332 |
+ TCase *tc_core, *tc_core_xml, *tc_core_subunit; |
| 333 |
|
| 334 |
s = suite_create("Log"); |
| 335 |
tc_core = tcase_create("Core"); |
| 336 |
tc_core_xml = tcase_create("Core XML"); |
| 337 |
+ tc_core_subunit = tcase_create("Core SubUnit"); |
| 338 |
|
| 339 |
suite_add_tcase(s, tc_core); |
| 340 |
tcase_add_test(tc_core, test_set_log); |
| 341 |
@@ -98,6 +126,9 @@ |
| 342 |
tcase_add_test(tc_core_xml, test_no_set_xml); |
| 343 |
tcase_add_test(tc_core_xml, test_double_set_xml); |
| 344 |
|
| 345 |
+ suite_add_tcase(s, tc_core_subunit); |
| 346 |
+ tcase_add_test(tc_core_subunit, test_init_logging_subunit); |
| 347 |
+ |
| 348 |
return s; |
| 349 |
} |
| 350 |
|
| 351 |
--- check-0.9.3.orig/tests/test_output.sh |
| 352 |
+++ check-0.9.3/tests/test_output.sh |
| 353 |
@@ -18,11 +18,22 @@ |
| 354 |
${lsrc}ex_output.c:8:P:Core:test_pass: Passed |
| 355 |
${lsrc}ex_output.c:14:F:Core:test_fail: Failure |
| 356 |
${lsrc}ex_output.c:18:E:Core:test_exit: (after this point) Early exit with return value 1" |
| 357 |
+t4="xtest: Core:test_pass |
| 358 |
+success: Core:test_pass |
| 359 |
+test: Core:test_fail |
| 360 |
+failure: Core:test_fail [ |
| 361 |
+${lsrc}ex_output.c:14: Failure |
| 362 |
+] |
| 363 |
+test: Core:test_exit |
| 364 |
+error: Core:test_exit [ |
| 365 |
+${lsrc}ex_output.c:18: (after this point) Early exit with return value 1 |
| 366 |
+]" |
| 367 |
|
| 368 |
op0=`./ex_output CK_SILENT` |
| 369 |
op1=`./ex_output CK_MINIMAL` |
| 370 |
op2=`./ex_output CK_NORMAL` |
| 371 |
op3=`./ex_output CK_VERBOSE` |
| 372 |
+op4=`./ex_output CK_SUBUNIT` |
| 373 |
|
| 374 |
|
| 375 |
test_output ( ) { |
| 376 |
@@ -41,4 +52,5 @@ |
| 377 |
test_output "$t1" x"$op1" "CK_MINIMAL"; |
| 378 |
test_output "$t2" x"$op2" "CK_NORMAL"; |
| 379 |
test_output "$t3" x"$op3" "CK_VERBOSE"; |
| 380 |
+test_output "$t4" x"$op4" "CK_SUBUNIT"; |
| 381 |
exit 0 |
| 382 |
--- check-0.9.3.orig/configure.in |
| 383 |
+++ check-0.9.3/configure.in |
| 384 |
@@ -44,6 +44,7 @@ |
| 385 |
AC_HEADER_SYS_WAIT |
| 386 |
AC_CHECK_HEADERS(unistd.h) |
| 387 |
AC_CHECK_HEADERS(stdint.h) |
| 388 |
+AC_CHECK_HEADERS(subunit/child.h) |
| 389 |
|
| 390 |
dnl Checks for typedefs, structures, and compiler characteristics. |
| 391 |
AC_C_CONST |
| 392 |
@@ -55,6 +56,7 @@ |
| 393 |
AC_CHECK_SIZEOF(long, 4) |
| 394 |
|
| 395 |
dnl Checks for library functions. |
| 396 |
+AC_CHECK_LIB(subunit, subunit_test_start) |
| 397 |
dnl AC_FUNC_FORK |
| 398 |
dnl AC_FUNC_MALLOC |
| 399 |
AC_FUNC_VPRINTF |