Blame tests/check_nofork_teardown.c

Packit 0b5880
/*
Packit 0b5880
 * Check: a unit test framework for C
Packit 0b5880
 * Copyright (C) 2001, 2002 Arien Malec
Packit 0b5880
 *
Packit 0b5880
 * This library is free software; you can redistribute it and/or
Packit 0b5880
 * modify it under the terms of the GNU Lesser General Public
Packit 0b5880
 * License as published by the Free Software Foundation; either
Packit 0b5880
 * version 2.1 of the License, or (at your option) any later version.
Packit 0b5880
 *
Packit 0b5880
 * This library is distributed in the hope that it will be useful,
Packit 0b5880
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 0b5880
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 0b5880
 * Lesser General Public License for more details.
Packit 0b5880
 *
Packit 0b5880
 * You should have received a copy of the GNU Lesser General Public
Packit 0b5880
 * License along with this library; if not, write to the
Packit 0b5880
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
Packit 0b5880
 * MA 02110-1301, USA.
Packit 0b5880
 */
Packit 0b5880
Packit 0b5880
#include "../lib/libcompat.h"
Packit 0b5880
Packit 0b5880
#include <stdio.h>
Packit 0b5880
#include <stdlib.h>
Packit 0b5880
#include "check.h"
Packit 0b5880
Packit 0b5880
/**
Packit 0b5880
 * This test checks the result if in CK_NOFORK
Packit 0b5880
 * mode a unit test fails but a checked teardown
Packit 0b5880
 * runs after the failed test.
Packit 0b5880
 *
Packit 0b5880
 * Previously, the failure would be reported as:
Packit 0b5880
 *
Packit 0b5880
 * 0%: Checks: 1, Failures: 1, Errors: 0
Packit 0b5880
 * (null):-1:S:tc:will_fail:0: Assertion '0' failed
Packit 0b5880
 *
Packit 0b5880
 * The reason why this happens is this: the end of the
Packit 0b5880
 * message sequence coming down the pipe is CK_MSG_LOC
Packit 0b5880
 * (location of failing test), CK_MSG_FAIL, CK_MSG_CTX
Packit 0b5880
 * (TEARDOWN). It is this final message that confuses
Packit 0b5880
 * things, because rcvmsg_update_ctx() updates
Packit 0b5880
 * rmsg->lastctx (which likely is the right thing for it
Packit 0b5880
 * to do), which is the ctx value used by the first 'if'
Packit 0b5880
 * body in construct_test_result() in its call to
Packit 0b5880
 * tr_set_loc_by_ctx().
Packit 0b5880
 *
Packit 0b5880
 * After the fix, the test failure should be reported
Packit 0b5880
 * as:
Packit 0b5880
 *
Packit 0b5880
 * 0%: Checks: 1, Failures: 1, Errors: 0
Packit 0b5880
 * check_nofork_teardown.c:33:F:tc:will_fail:0: Assertion '0' failed
Packit 0b5880
 */
Packit 0b5880
Packit 0b5880
START_TEST( will_fail )
Packit 0b5880
{
Packit 0b5880
    ck_assert(0);
Packit 0b5880
}
Packit 0b5880
END_TEST
Packit 0b5880
Packit 0b5880
static void empty_checked_teardown( void )
Packit 0b5880
{
Packit 0b5880
}
Packit 0b5880
Packit 0b5880
int main( void )
Packit 0b5880
{
Packit 0b5880
    SRunner *sr = srunner_create( NULL );
Packit 0b5880
    Suite *s = suite_create( "bug-99" );
Packit 0b5880
    TCase *tc = tcase_create( "tc" );
Packit 0b5880
    int result;
Packit 0b5880
Packit 0b5880
    srunner_add_suite( sr, s );
Packit 0b5880
    srunner_set_fork_status( sr, CK_NOFORK );
Packit 0b5880
    suite_add_tcase( s, tc );
Packit 0b5880
    tcase_add_checked_fixture( tc, NULL, empty_checked_teardown );
Packit 0b5880
    tcase_add_test( tc, will_fail );
Packit 0b5880
Packit 0b5880
    srunner_run_all( sr, CK_ENV );
Packit 0b5880
    result = srunner_ntests_failed( sr ) ? EXIT_FAILURE : EXIT_SUCCESS;
Packit 0b5880
    srunner_free( sr );
Packit 0b5880
Packit 0b5880
    return result;
Packit 0b5880
}