]> granicus.if.org Git - check/commitdiff
modify test_xml_output.sh to compare output based on HAVE_FORK
authorbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Mon, 23 Sep 2013 13:07:03 +0000 (13:07 +0000)
committerbrarcher <brarcher@64e312b2-a51f-0410-8e61-82d0ca0eb02a>
Mon, 23 Sep 2013 13:07:03 +0000 (13:07 +0000)
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

tests/ex_xml_output.c
tests/test_xml_output.sh

index a76e6097f5c1da38ea0833aa936bc2c85a7250bd..0a9893699cdc952dc9a70d90d61ed6017d617640 100644 (file)
@@ -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;
 }
index e165d8a30fbe4768ab73e39ac0afb0cf6a74f03c..882bdb1ea46fc0804eb154a282c64d3624559488 100755 (executable)
@@ -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="<?xml version=\"1.0\"?>
+if [ $HAVE_FORK -eq 1 ]; then
+expected_xml="<?xml version=\"1.0\"?>
 <?xml-stylesheet type=\"text/xsl\" href=\"http://check.sourceforge.net/xml/check_unittest.xslt\"?>
 <testsuites xmlns=\"http://check.sourceforge.net/ns\">
   <suite>
@@ -28,7 +31,7 @@ expected="<?xml version=\"1.0\"?>
       <message>Failure</message>
     </test>
     <test result=\"error\">
-      <fn>ex_xml_output.c:20</fn>
+      <fn>ex_xml_output.c:25</fn>
       <id>test_exit</id>
       <iteration>0</iteration>
       <description>Core</description>
@@ -38,28 +41,28 @@ expected="<?xml version=\"1.0\"?>
   <suite>
     <title>S2</title>
     <test result=\"success\">
-      <fn>ex_xml_output.c:28</fn>
+      <fn>ex_xml_output.c:34</fn>
       <id>test_pass2</id>
       <iteration>0</iteration>
       <description>Core</description>
       <message>Passed</message>
     </test>
     <test result=\"failure\">
-      <fn>ex_xml_output.c:34</fn>
+      <fn>ex_xml_output.c:40</fn>
       <id>test_loop</id>
       <iteration>0</iteration>
       <description>Core</description>
       <message>Iteration 0 failed</message>
     </test>
     <test result=\"success\">
-      <fn>ex_xml_output.c:34</fn>
+      <fn>ex_xml_output.c:40</fn>
       <id>test_loop</id>
       <iteration>1</iteration>
       <description>Core</description>
       <message>Passed</message>
     </test>
     <test result=\"failure\">
-      <fn>ex_xml_output.c:34</fn>
+      <fn>ex_xml_output.c:40</fn>
       <id>test_loop</id>
       <iteration>2</iteration>
       <description>Core</description>
@@ -69,7 +72,7 @@ expected="<?xml version=\"1.0\"?>
   <suite>
     <title>XML escape &quot; &apos; &lt; &gt; &amp; tests</title>
     <test result=\"failure\">
-      <fn>ex_xml_output.c:40</fn>
+      <fn>ex_xml_output.c:46</fn>
       <id>test_xml_esc_fail_msg</id>
       <iteration>0</iteration>
       <description>description &quot; &apos; &lt; &gt; &amp;</description>
@@ -77,27 +80,96 @@ expected="<?xml version=\"1.0\"?>
     </test>
   </suite>
 </testsuites>"
+expected_duration_count=9
+expected_duration_error=5
+else
+expected_xml=`printf "<?xml version=\"1.0\"?>\r
+<?xml-stylesheet type=\"text/xsl\" href=\"http://check.sourceforge.net/xml/check_unittest.xslt\"?>\r
+<testsuites xmlns=\"http://check.sourceforge.net/ns\">\r
+  <suite>\r
+    <title>S1</title>\r
+    <test result=\"success\">\r
+      <fn>ex_xml_output.c:10</fn>\r
+      <id>test_pass</id>\r
+      <iteration>0</iteration>\r
+      <description>Core</description>\r
+      <message>Passed</message>\r
+    </test>\r
+    <test result=\"failure\">\r
+      <fn>ex_xml_output.c:16</fn>\r
+      <id>test_fail</id>\r
+      <iteration>0</iteration>\r
+      <description>Core</description>\r
+      <message>Failure</message>\r
+    </test>\r
+  </suite>\r
+  <suite>\r
+    <title>S2</title>\r
+    <test result=\"success\">\r
+      <fn>ex_xml_output.c:34</fn>\r
+      <id>test_pass2</id>\r
+      <iteration>0</iteration>\r
+      <description>Core</description>\r
+      <message>Passed</message>\r
+    </test>\r
+    <test result=\"failure\">\r
+      <fn>ex_xml_output.c:40</fn>\r
+      <id>test_loop</id>\r
+      <iteration>0</iteration>\r
+      <description>Core</description>\r
+      <message>Iteration 0 failed</message>\r
+    </test>\r
+    <test result=\"success\">\r
+      <fn>ex_xml_output.c:40</fn>\r
+      <id>test_loop</id>\r
+      <iteration>1</iteration>\r
+      <description>Core</description>\r
+      <message>Passed</message>\r
+    </test>\r
+    <test result=\"failure\">\r
+      <fn>ex_xml_output.c:40</fn>\r
+      <id>test_loop</id>\r
+      <iteration>2</iteration>\r
+      <description>Core</description>\r
+      <message>Iteration 2 failed</message>\r
+    </test>\r
+  </suite>\r
+  <suite>\r
+    <title>XML escape &quot; &apos; &lt; &gt; &amp; tests</title>\r
+    <test result=\"failure\">\r
+      <fn>ex_xml_output.c:46</fn>\r
+      <id>test_xml_esc_fail_msg</id>\r
+      <iteration>0</iteration>\r
+      <description>description &quot; &apos; &lt; &gt; &amp;</description>\r
+      <message>fail &quot; &apos; &lt; &gt; &amp; message</message>\r
+    </test>\r
+  </suite>\r
+</testsuites>\r
+"`
+expected_duration_count=8
+expected_duration_error=4
+fi
 
 ./ex_xml_output${EXEEXT} > /dev/null
-actual=`cat test.log.xml | grep -v \<duration\> | grep -v \<datetime\> | grep -v \<path\>`
-if [ x"${expected}" != x"${actual}" ]; then
+actual_xml=`cat test.log.xml | grep -v \<duration\> | grep -v \<datetime\> | grep -v \<path\>`
+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 \<duration\> test.log.xml`
-if [ x"${duration_count}" != x9 ]; then
-    echo "Wrong number of <duration> elements in test.log.xml";
+actual_duration_count=`grep -c \<duration\> test.log.xml`
+if [ x"${expected_duration_count}" != x"${actual_duration_count}" ]; then
+    echo "Wrong number of <duration> elements in test.log.xml, ${expected_duration_count} vs ${actual_duration_count}";
     exit 1;
 fi
 
-duration_error=`cat test.log.xml | grep \<duration\> | grep -c "\-1\.000000"`
-if [ x"${duration_error}" != x5 ]; then
-    echo "Wrong format for (or number of) error <duration> elements in test.log.xml";
+actual_duration_error=`cat test.log.xml | grep \<duration\> | grep -c "\-1\.000000"`
+if [ x"${expected_duration_error}" != x"${actual_duration_error}" ]; then
+    echo "Wrong format for (or number of) error <duration> elements in test.log.xml, ${expected_duration_error} vs ${actual_duration_error}";
     exit 1;
 fi