check_nofork_teardown.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. * Check: a unit test framework for C
  3. * Copyright (C) 2001, 2002 Arien Malec
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the
  17. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
  18. * MA 02110-1301, USA.
  19. */
  20. #include "../lib/libcompat.h"
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include "check.h"
  24. /**
  25. * This test checks the result if in CK_NOFORK
  26. * mode a unit test fails but a checked teardown
  27. * runs after the failed test.
  28. *
  29. * Previously, the failure would be reported as:
  30. *
  31. * 0%: Checks: 1, Failures: 1, Errors: 0
  32. * (null):-1:S:tc:will_fail:0: Assertion '0' failed
  33. *
  34. * The reason why this happens is this: the end of the
  35. * message sequence coming down the pipe is CK_MSG_LOC
  36. * (location of failing test), CK_MSG_FAIL, CK_MSG_CTX
  37. * (TEARDOWN). It is this final message that confuses
  38. * things, because rcvmsg_update_ctx() updates
  39. * rmsg->lastctx (which likely is the right thing for it
  40. * to do), which is the ctx value used by the first 'if'
  41. * body in construct_test_result() in its call to
  42. * tr_set_loc_by_ctx().
  43. *
  44. * After the fix, the test failure should be reported
  45. * as:
  46. *
  47. * 0%: Checks: 1, Failures: 1, Errors: 0
  48. * check_nofork_teardown.c:33:F:tc:will_fail:0: Assertion '0' failed
  49. */
  50. START_TEST( will_fail )
  51. {
  52. ck_assert(0);
  53. }
  54. END_TEST
  55. static void empty_checked_teardown( void )
  56. {
  57. }
  58. int main( void )
  59. {
  60. SRunner *sr = srunner_create( NULL );
  61. Suite *s = suite_create( "bug-99" );
  62. TCase *tc = tcase_create( "tc" );
  63. int result;
  64. srunner_add_suite( sr, s );
  65. srunner_set_fork_status( sr, CK_NOFORK );
  66. suite_add_tcase( s, tc );
  67. tcase_add_checked_fixture( tc, NULL, empty_checked_teardown );
  68. tcase_add_test( tc, will_fail );
  69. srunner_run_all( sr, CK_ENV );
  70. result = srunner_ntests_failed( sr ) ? EXIT_FAILURE : EXIT_SUCCESS;
  71. srunner_free( sr );
  72. return result;
  73. }