diff options
author | Robert Collins <robertc@robertcollins.net> | 2009-10-03 08:26:44 +1000 |
---|---|---|
committer | Robert Collins <robertc@robertcollins.net> | 2009-10-03 08:26:44 +1000 |
commit | 9e4100b7e256d536a866869c5c15c8473ebbab69 (patch) | |
tree | 5b56ae8a60a875d5712ca659966c43531a13cb87 | |
parent | a0fece2a82603e4cc7037313795b08e937e8a758 (diff) | |
download | subunit-git-9e4100b7e256d536a866869c5c15c8473ebbab69.tar.gz |
Add skip support to the C client.
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | c/include/subunit/child.h | 12 | ||||
-rw-r--r-- | c/lib/child.c | 50 | ||||
-rw-r--r-- | c/tests/test_child.c | 19 |
4 files changed, 67 insertions, 16 deletions
@@ -16,6 +16,8 @@ subunit release notes * INSTALLDIRS can be set to control the perl MakeMaker 'INSTALLDIRS' viarable when installing. + * The C library now has ``subunit_test_skip``. + BUG FIXES: * Install progress_model.py correctly. diff --git a/c/include/subunit/child.h b/c/include/subunit/child.h index 7fab7b5..0a4e601 100644 --- a/c/include/subunit/child.h +++ b/c/include/subunit/child.h @@ -62,6 +62,18 @@ extern void subunit_test_error(char const * const name, char const * const error); +/** + * subunit_test_skip: + * + * Report that a test has been skipped. An skip is a test that has not run to + * conclusion but hasn't given an error either - its result is unknown. + * @name: test case name + * @reason: a string describing the reason for the skip. + */ +extern void subunit_test_skip(char const * const name, + char const * const reason); + + #ifdef __cplusplus } #endif diff --git a/c/lib/child.c b/c/lib/child.c index 872a868..2b59747 100644 --- a/c/lib/child.c +++ b/c/lib/child.c @@ -19,6 +19,28 @@ #include <string.h> #include "subunit/child.h" +/* Write details about a test event. It is the callers responsibility to ensure + * that details are only provided for events the protocol expects details on. + * @event: The event - e.g. 'skip' + * @name: The test name/id. + * @details: The details of the event, may be NULL if no details are present. + */ +static void +subunit_send_event(char const * const event, char const * const name, + char const * const details) +{ + if (NULL == details) { + fprintf(stdout, "%s: %s\n", event, name); + } else { + fprintf(stdout, "%s: %s [\n", event, name); + fprintf(stdout, "%s", details); + if (details[strlen(details) - 1] != '\n') + fprintf(stdout, "\n"); + fprintf(stdout, "]\n"); + } + fflush(stdout); +} + /* these functions all flush to ensure that the test runner knows the action * that has been taken even if the subsequent test etc takes a long time or * never completes (i.e. a segfault). @@ -27,38 +49,34 @@ void subunit_test_start(char const * const name) { - fprintf(stdout, "test: %s\n", name); - fflush(stdout); + subunit_send_event("test", name, NULL); } void subunit_test_pass(char const * const name) { - fprintf(stdout, "success: %s\n", name); - fflush(stdout); + /* TODO: add success details as an option */ + subunit_send_event("success", name, NULL); } void subunit_test_fail(char const * const name, char const * const error) { - fprintf(stdout, "failure: %s [\n", name); - fprintf(stdout, "%s", error); - if (error[strlen(error) - 1] != '\n') - fprintf(stdout, "\n"); - fprintf(stdout, "]\n"); - fflush(stdout); + subunit_send_event("failure", name, error); } void subunit_test_error(char const * const name, char const * const error) { - fprintf(stdout, "error: %s [\n", name); - fprintf(stdout, "%s", error); - if (error[strlen(error) - 1] != '\n') - fprintf(stdout, "\n"); - fprintf(stdout, "]\n"); - fflush(stdout); + subunit_send_event("error", name, error); +} + + +void +subunit_test_skip(char const * const name, char const * const reason) +{ + subunit_send_event("skip", name, reason); } diff --git a/c/tests/test_child.c b/c/tests/test_child.c index f2b2845..6399eeb 100644 --- a/c/tests/test_child.c +++ b/c/tests/test_child.c @@ -146,6 +146,24 @@ START_TEST (test_error) } END_TEST + +static void +call_test_skip(void) +{ + subunit_test_skip("test case", "Multiple lines\n of output\n"); +} + + +START_TEST (test_skip) +{ + test_stdout_function("skip: test case [\n" + "Multiple lines\n" + " of output\n" + "]\n", + call_test_skip); +} +END_TEST + static Suite * child_suite(void) { @@ -156,6 +174,7 @@ child_suite(void) tcase_add_test (tc_core, test_pass); tcase_add_test (tc_core, test_fail); tcase_add_test (tc_core, test_error); + tcase_add_test (tc_core, test_skip); return s; } |