From: brarcher Date: Mon, 23 Sep 2013 13:07:03 +0000 (+0000) Subject: modify test_xml_output.sh to compare output based on HAVE_FORK X-Git-Tag: 0.10.0~431 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bcd32e178ee5645a720342d937ea85c5d65ae173;p=check modify test_xml_output.sh to compare output based on HAVE_FORK When run in Windows, the output differs slightly from when it is run under *NIX due to line endings. *NIX uses \n, whereas Windows uses \r\n. To account for this, printf is used to generate the Windows expected string. Additionally, the test_exit test was removed, as it is not valid if fork is unavailable. Note that the test does not yet pass for MinGW due to a bug yet to be identified. The last test failure to compare against currently has a duration which is not -1. git-svn-id: svn+ssh://svn.code.sf.net/p/check/code/trunk@783 64e312b2-a51f-0410-8e61-82d0ca0eb02a --- diff --git a/tests/ex_xml_output.c b/tests/ex_xml_output.c index a76e609..0a98936 100644 --- a/tests/ex_xml_output.c +++ b/tests/ex_xml_output.c @@ -17,11 +17,17 @@ START_TEST(test_fail) } END_TEST +/* + * This test will fail without fork, as it will result in the + * unit test runniner exiting early. + */ +#if defined(HAVE_FORK) START_TEST(test_exit) { exit(1); } END_TEST +#endif /* HAVE_FORK */ START_TEST(test_pass2) { @@ -51,7 +57,9 @@ static Suite *make_s1_suite (void) suite_add_tcase(s, tc); tcase_add_test (tc, test_pass); tcase_add_test (tc, test_fail); +#if defined(HAVE_FORK) tcase_add_test (tc, test_exit); +#endif /* HAVE_FORK */ return s; } diff --git a/tests/test_xml_output.sh b/tests/test_xml_output.sh index e165d8a..882bdb1 100755 --- a/tests/test_xml_output.sh +++ b/tests/test_xml_output.sh @@ -1,14 +1,17 @@ #!/bin/sh -. ./test_vars +# For this test script, it is assumed that HAVE_FORK=0 implies +# running in a Windows environment. That means not only are +# fork-related tests not run, but also line endings are important. +# In *NIX environments line endings are \n, but in Windows they +# are expected to be \r\n. For this reason, HAVE_FORK=0 uses +# printf to generate the comparison strings, so the line endings +# can be controlled. -if [ "${srcdir}" = "." ]; then - lsrc="" -else - lsrc="${srcdir}/" -fi +. ./test_vars -expected=" +if [ $HAVE_FORK -eq 1 ]; then +expected_xml=" @@ -28,7 +31,7 @@ expected=" Failure - ex_xml_output.c:20 + ex_xml_output.c:25 test_exit 0 Core @@ -38,28 +41,28 @@ expected=" S2 - ex_xml_output.c:28 + ex_xml_output.c:34 test_pass2 0 Core Passed - ex_xml_output.c:34 + ex_xml_output.c:40 test_loop 0 Core Iteration 0 failed - ex_xml_output.c:34 + ex_xml_output.c:40 test_loop 1 Core Passed - ex_xml_output.c:34 + ex_xml_output.c:40 test_loop 2 Core @@ -69,7 +72,7 @@ expected=" XML escape " ' < > & tests - ex_xml_output.c:40 + ex_xml_output.c:46 test_xml_esc_fail_msg 0 description " ' < > & @@ -77,27 +80,96 @@ expected=" " +expected_duration_count=9 +expected_duration_error=5 +else +expected_xml=`printf "\r +\r +\r + \r + S1\r + \r + ex_xml_output.c:10\r + test_pass\r + 0\r + Core\r + Passed\r + \r + \r + ex_xml_output.c:16\r + test_fail\r + 0\r + Core\r + Failure\r + \r + \r + \r + S2\r + \r + ex_xml_output.c:34\r + test_pass2\r + 0\r + Core\r + Passed\r + \r + \r + ex_xml_output.c:40\r + test_loop\r + 0\r + Core\r + Iteration 0 failed\r + \r + \r + ex_xml_output.c:40\r + test_loop\r + 1\r + Core\r + Passed\r + \r + \r + ex_xml_output.c:40\r + test_loop\r + 2\r + Core\r + Iteration 2 failed\r + \r + \r + \r + XML escape " ' < > & tests\r + \r + ex_xml_output.c:46\r + test_xml_esc_fail_msg\r + 0\r + description " ' < > &\r + fail " ' < > & message\r + \r + \r +\r +"` +expected_duration_count=8 +expected_duration_error=4 +fi ./ex_xml_output${EXEEXT} > /dev/null -actual=`cat test.log.xml | grep -v \ | grep -v \ | grep -v \` -if [ x"${expected}" != x"${actual}" ]; then +actual_xml=`cat test.log.xml | grep -v \ | grep -v \ | grep -v \` +if [ x"${expected_xml}" != x"${actual_xml}" ]; then echo "Problem with ex_xml_output${EXEEXT} ${3}"; echo "Expected:"; - echo "${expected}"; + echo "${expected_xml}"; echo "Got:"; - echo "${actual}"; + echo "${actual_xml}"; exit 1; fi -duration_count=`grep -c \ test.log.xml` -if [ x"${duration_count}" != x9 ]; then - echo "Wrong number of elements in test.log.xml"; +actual_duration_count=`grep -c \ test.log.xml` +if [ x"${expected_duration_count}" != x"${actual_duration_count}" ]; then + echo "Wrong number of elements in test.log.xml, ${expected_duration_count} vs ${actual_duration_count}"; exit 1; fi -duration_error=`cat test.log.xml | grep \ | grep -c "\-1\.000000"` -if [ x"${duration_error}" != x5 ]; then - echo "Wrong format for (or number of) error elements in test.log.xml"; +actual_duration_error=`cat test.log.xml | grep \ | grep -c "\-1\.000000"` +if [ x"${expected_duration_error}" != x"${actual_duration_error}" ]; then + echo "Wrong format for (or number of) error elements in test.log.xml, ${expected_duration_error} vs ${actual_duration_error}"; exit 1; fi