From: hugo303 Date: Thu, 4 Nov 2004 12:42:51 +0000 (+0000) Subject: Applied ANSI C99 patch (#1047014) X-Git-Tag: 0.10.0~960 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d698ca3046d1c893060d1cef72c012dce1e57c48;p=check Applied ANSI C99 patch (#1047014) git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@190 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/check/ChangeLog b/check/ChangeLog index af5febd..4a8416e 100644 --- a/check/ChangeLog +++ b/check/ChangeLog @@ -1,3 +1,8 @@ +2004-11-04 hugo303 + + * src/check.c, src/check.h.in, tests/check_check_master.c, + tests/check_check_sub.c: Applied ANSI C99 patch (#1047014) + 2004-08-20 hugo303 * doc/tutorial.sgml: Updated with new features. diff --git a/check/src/check.c b/check/src/check.c index 78e29eb..be64765 100644 --- a/check/src/check.c +++ b/check/src/check.c @@ -170,17 +170,19 @@ void _mark_point (const char *file, int line) } void _fail_unless (int result, const char *file, - int line, const char * msg, ...) + int line, const char *expr, ...) { - if (msg == NULL) - eprintf ("_fail_unless() called with NULL msg",__FILE__,__LINE__); - + const char *msg; + send_loc_info (get_send_key(), file, line); if (!result) { va_list ap; char buf[BUFSIZ]; - - va_start(ap,msg); + + va_start(ap,expr); + msg = (const char*)va_arg(ap, char *); + if (msg == NULL) + msg = expr; vsnprintf(buf, BUFSIZ, msg, ap); va_end(ap); send_failure_info (get_send_key(), buf); diff --git a/check/src/check.h.in b/check/src/check.h.in index 78ad17a..07c893b 100644 --- a/check/src/check.h.in +++ b/check/src/check.h.in @@ -155,21 +155,21 @@ static void __testname (void)\ /* Fail the test case unless expr is true */ -#define fail_unless(expr, msg, args...)\ +#define fail_unless(expr, ...)\ _fail_unless(expr, __FILE__, __LINE__,\ - msg ? msg : "Assertion '"#expr"' failed", ##args) + "Assertion '"#expr"' failed" , ## __VA_ARGS__, NULL) /* Fail the test case if expr is true */ -#define fail_if(expr, msg, args...)\ +#define fail_if(expr, ...)\ _fail_unless(!(expr), __FILE__, __LINE__,\ - msg ?msg :"Assertion '"#expr"' failed", ##args) + "Assertion '"#expr"' failed", ## __VA_ARGS__, NULL) /* Always fail */ -#define fail(msg, args...) _fail_unless(0, __FILE__, __LINE__, msg, ##args) +#define fail(...) _fail_unless(0, __FILE__, __LINE__, "Failed" , ## __VA_ARGS__, NULL) /* Non macro version of #fail_unless, with more complicated interface */ void _fail_unless (int result, const char *file, - int line, const char *msg, ...); + int line, const char *expr, ...); /* Mark the last point reached in a unit test diff --git a/check/tests/check_check_master.c b/check/tests/check_check_master.c index ab65326..bd61aca 100644 --- a/check/tests/check_check_master.c +++ b/check/tests/check_check_master.c @@ -14,14 +14,14 @@ TestResult **tr_all_array; START_TEST(test_check_nfailures) { - fail_unless (sub_nfailed == 16, + fail_unless (sub_nfailed == 19, "Unexpected number of failures received, %d.", sub_nfailed); } END_TEST START_TEST(test_check_ntests_run) { - fail_unless (sub_ntests == 18, + fail_unless (sub_ntests == 21, "Unexpected number of tests run, %d.", sub_ntests); } END_TEST @@ -37,10 +37,13 @@ START_TEST(test_check_failure_msgs) /* "Test passed", */ "This test should fail", "Assertion '2 == 3' failed", + "Assertion '4 == 5' failed", "Assertion '2 != 3' failed", + "Assertion '4 != 5' failed", "3 != 4", "5 != 6", "7 == 7", + "Failed", "Received signal 11", "Received signal 8", "Received signal 8", @@ -81,6 +84,9 @@ START_TEST(test_check_failure_lnos) -1, -1, -1, + -1, + -1, + -1, -1}; for (i = 0; i < sub_nfailed; i++) { @@ -109,6 +115,9 @@ START_TEST(test_check_failure_ftypes) CK_FAILURE, CK_FAILURE, CK_FAILURE, + CK_FAILURE, + CK_FAILURE, + CK_FAILURE, CK_ERROR, CK_ERROR, CK_ERROR, @@ -150,6 +159,9 @@ START_TEST(test_check_failure_tcnames) "Simple Tests", "Simple Tests", "Simple Tests", + "Simple Tests", + "Simple Tests", + "Simple Tests", "Signal Tests", "Signal Tests", "Signal Tests", @@ -183,10 +195,13 @@ START_TEST(test_check_all_msgs) "Passed", "This test should fail", "Assertion '2 == 3' failed", + "Assertion '4 == 5' failed", "Assertion '2 != 3' failed", + "Assertion '4 != 5' failed", "3 != 4", "5 != 6", "7 == 7", + "Failed", "Received signal 11", "Received signal 8", "Received signal 8", @@ -223,6 +238,9 @@ START_TEST(test_check_all_ftypes) CK_FAILURE, CK_FAILURE, CK_FAILURE, + CK_FAILURE, + CK_FAILURE, + CK_FAILURE, CK_ERROR, CK_ERROR, CK_ERROR, diff --git a/check/tests/check_check_sub.c b/check/tests/check_check_sub.c index 8c82e7d..1ec9058 100644 --- a/check/tests/check_check_sub.c +++ b/check/tests/check_check_sub.c @@ -48,12 +48,26 @@ START_TEST(test_fail_null_msg) } END_TEST + +START_TEST(test_fail_no_msg) +{ + fail_unless(4 == 5); +} +END_TEST + START_TEST(test_fail_if_null_msg) { fail_if(2 != 3, NULL); } END_TEST + +START_TEST(test_fail_if_no_msg) +{ + fail_if(4 != 5); +} +END_TEST + START_TEST(test_fail_vararg_msg_1) { int x = 3; @@ -78,6 +92,12 @@ START_TEST(test_fail_vararg_msg_3) } END_TEST +START_TEST(test_fail_empty) +{ + fail(); +} +END_TEST + START_TEST(test_segv) { raise (SIGSEGV); @@ -170,10 +190,13 @@ Suite *make_sub_suite(void) tcase_add_test (tc_simple, test_fail_if_pass); tcase_add_test (tc_simple, test_fail_if_fail); tcase_add_test (tc_simple, test_fail_null_msg); + tcase_add_test (tc_simple, test_fail_no_msg); tcase_add_test (tc_simple, test_fail_if_null_msg); + tcase_add_test (tc_simple, test_fail_if_no_msg); tcase_add_test (tc_simple, test_fail_vararg_msg_1); tcase_add_test (tc_simple, test_fail_vararg_msg_2); tcase_add_test (tc_simple, test_fail_vararg_msg_3); + tcase_add_test (tc_simple, test_fail_empty); tcase_add_test (tc_signal, test_segv); tcase_add_test (tc_signal, test_fpe); tcase_add_test (tc_signal, test_mark_point);