From: brarcher Date: Sun, 22 Sep 2013 21:27:53 +0000 (+0000) Subject: Post an error if a fork mode is set and fork is unavailable X-Git-Tag: 0.10.0~439 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=659ee6ebcceb8a9f1cb496444e56d4db8494b5b8;p=check Post an error if a fork mode is set and fork is unavailable The default fork mode if fork is unavailable is CK_NOFORK. Someone trying to set a fork mode without fork available will only result in failures running tests. Posting an error up front before tests are run makes more sense. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@775 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/src/check_run.c b/src/check_run.c index 944a41e..b516471 100644 --- a/src/check_run.c +++ b/src/check_run.c @@ -594,6 +594,13 @@ enum fork_status srunner_fork_status (SRunner *sr) void srunner_set_fork_status (SRunner *sr, enum fork_status fstat) { +#if !defined(HAVE_FORK) + /* If fork() is unavailable, do not allow a fork mode to be set */ + if (fstat != CK_NOFORK) + { + eprintf("This version does not support fork", __FILE__, __LINE__); + } +#endif /* ! HAVE_FORK */ sr->fstat = fstat; } diff --git a/tests/check_check_fork.c b/tests/check_check_fork.c index 75907fd..c09fa55 100644 --- a/tests/check_check_fork.c +++ b/tests/check_check_fork.c @@ -81,7 +81,7 @@ START_TEST(test_default_fork) } END_TEST -START_TEST(test_set_fork) +START_TEST(test_set_nofork) { srunner_set_fork_status(fork_dummy_sr, CK_NOFORK); ck_assert_msg(srunner_fork_status(fork_dummy_sr) == CK_NOFORK, @@ -89,6 +89,12 @@ START_TEST(test_set_fork) } END_TEST +/* + * The following tests will fail if fork is unavailable, as + * attempting to set the fork mode as anything but + * CK_NOFORK is considered an error. + */ +#if defined(HAVE_FORK) START_TEST(test_env) { putenv((char *) "CK_FORK=no"); @@ -105,7 +111,7 @@ START_TEST(test_env_and_set) "Explicit setting of fork status should override env"); } END_TEST - +#endif /* HAVE_FORK */ START_TEST(test_nofork) { @@ -124,9 +130,11 @@ Suite *make_fork_suite(void) suite_add_tcase(s, tc); tcase_add_test(tc,test_default_fork); - tcase_add_test(tc,test_set_fork); + tcase_add_test(tc,test_set_nofork); +#if defined(HAVE_FORK) tcase_add_test(tc,test_env); tcase_add_test(tc,test_env_and_set); +#endif /* HAVE_FORK */ tcase_add_test(tc,test_nofork); return s;