In nofork mode, the location of a failed assertion within a test
case is lost if that test case has a checked teardown fixture
(even if that fixture function is empty).
The reason why this happens is this: the end of the message sequence
coming down the pipe is CK_MSG_LOC (location of failing test),
CK_MSG_FAIL, CK_MSG_CTX (TEARDOWN). It is this final message that
confuses things, because rcvmsg_update_ctx() updates rmsg->lastctx
(which I suspect is the right thing for it to do), which is the ctx
value used by the first 'if' body in construct_test_result() in its
call to tr_set_loc_by_ctx().
The solution is to initialize tr->ctx to rmsg->failctx if
it is not CK_CTX_INVALID.
Bug #99.
git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@1193
64e312b2-a51f-0410-8e61-
82d0ca0eb02a
Georg Sauthoff (Solaris support, misc autotools fixes)
forest (AIX and Solaris support)
Michael Piszczek (misc cleanup)
+ Stewart Brodie (bug fix: no fork mode failure reporting with teardowns)
Anybody who has contributed code to Check or Check's build system is
considered an author. Send patches to this file to
add_test(NAME test_xml_output.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests COMMAND sh test_xml_output.sh)
add_test(NAME test_tap_output.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests COMMAND sh test_tap_output.sh)
add_test(NAME test_check_nofork.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests COMMAND sh test_check_nofork.sh)
+ add_test(NAME test_check_nofork_teardown.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/tests COMMAND sh test_check_nofork_teardown.sh)
endif(UNIX OR MINGW OR MSYS)
* Fix issue with string formatting in ck_assert(), where using
the % operator would be interpreted as a string formatter. Bug #96.
+* In nofork mode, the location of a failed assertion within a test
+ case was lost if that test case has a checked teardown fixture
+ (even if that fixture function is empty). This is now fixed.
+ Bug #99
+
Sat July 26, 2014: Released Check 0.9.14
based on r1174 (2014-07-03 18:43:49 +0000)
if(rmsg->msg != NULL || waserror)
{
- tr->ctx = rmsg->lastctx;
+ if(rmsg->failctx != CK_CTX_INVALID)
+ {
+ tr->ctx = rmsg->failctx;
+ }
+ else
+ {
+ tr->ctx = rmsg->lastctx;
+ }
+
tr->msg = rmsg->msg;
rmsg->msg = NULL;
tr_set_loc_by_ctx(tr, tr->ctx, rmsg);
set(CHECK_NOFORK_SOURCES check_nofork.c)
add_executable(check_nofork ${CHECK_NOFORK_SOURCES})
target_link_libraries(check_nofork check compat)
+
+set(CHECK_NOFORK_TEARDOWN_SOURCES check_nofork_teardown.c)
+add_executable(check_nofork_teardown ${CHECK_NOFORK_TEARDOWN_SOURCES})
+target_link_libraries(check_nofork_teardown check compat)
check_check \
test_output.sh \
test_check_nofork.sh \
+ test_check_nofork_teardown.sh \
test_xml_output.sh \
test_log_output.sh \
test_tap_output.sh
check_stress \
check_thread_stress \
check_nofork \
+ check_nofork_teardown \
check_mem_leaks \
ex_output
check_nofork_SOURCES = check_nofork.c
check_nofork_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
+check_nofork_teardown_SOURCES = check_nofork_teardown.c
+check_nofork_teardown_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
+
ex_output_SOURCES = ex_output.c
ex_output_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include "check.h"
+
+/**
+ * This test checks the result if in CK_NOFORK
+ * mode a unit test fails but a checked teardown
+ * runs after the failed test.
+ *
+ * Previously, the failure would be reported as:
+ *
+ * 0%: Checks: 1, Failures: 1, Errors: 0
+ * (null):-1:S:tc:will_fail:0: Assertion '0' failed
+ *
+ * The reason why this happens is this: the end of the
+ * message sequence coming down the pipe is CK_MSG_LOC
+ * (location of failing test), CK_MSG_FAIL, CK_MSG_CTX
+ * (TEARDOWN). It is this final message that confuses
+ * things, because rcvmsg_update_ctx() updates
+ * rmsg->lastctx (which likely is the right thing for it
+ * to do), which is the ctx value used by the first 'if'
+ * body in construct_test_result() in its call to
+ * tr_set_loc_by_ctx().
+ *
+ * After the fix, the test failure should be reported
+ * as:
+ *
+ * 0%: Checks: 1, Failures: 1, Errors: 0
+ * check_nofork_teardown.c:33:F:tc:will_fail:0: Assertion '0' failed
+ */
+
+START_TEST( will_fail )
+{
+ ck_assert(0);
+}
+END_TEST
+
+static void empty_checked_teardown( void )
+{
+}
+
+int main( void )
+{
+ SRunner *sr = srunner_create( NULL );
+ Suite *s = suite_create( "bug-99" );
+ TCase *tc = tcase_create( "tc" );
+ int result;
+
+ srunner_add_suite( sr, s );
+ srunner_set_fork_status( sr, CK_NOFORK );
+ suite_add_tcase( s, tc );
+ tcase_add_checked_fixture( tc, NULL, empty_checked_teardown );
+ tcase_add_test( tc, will_fail );
+
+ srunner_run_all( sr, CK_ENV );
+ result = srunner_ntests_failed( sr ) ? EXIT_FAILURE : EXIT_SUCCESS;
+ srunner_free( sr );
+
+ return result;
+}
--- /dev/null
+#!/usr/bin/env sh
+
+. ./test_vars
+
+expected="Running suite(s): bug-99
+0%: Checks: 1, Failures: 1, Errors: 0
+check_nofork_teardown.c:34:F:tc:will_fail:0: Assertion '0' failed"
+
+actual=`./check_nofork_teardown${EXEEXT} | tr -d "\r"`
+if [ x"${expected}" = x"${actual}" ]; then
+ exit 0
+else
+ echo "Problem with check_nofork_teardown${EXEEXT}"
+ echo "Expected: "
+ echo "${expected}"
+ echo "Got: "
+ echo "${actual}"
+ exit 1
+fi