Use TEST_COMPARE_STRING in recently added test

Message ID 20181107142713.9841-1-gabriel@inconstante.eti.br
State Committed
Headers

Commit Message

Gabriel F. T. Gomes Nov. 7, 2018, 2:27 p.m. UTC
  The commit

commit 1df872fd74f730bcae3df201a229195445d2e18a
Author: Florian Weimer <fweimer@redhat.com>
Date:   Wed Nov 7 12:42:44 2018 +0100

    support: Implement TEST_COMPARE_STRING

added the new macro TEST_COMPARE_STRING, which compares the output of
functions under test against expected strings, and, when there's a
mismatch, automatically reports an error and prints the differences.
This patch adapts recently added test cases to use this new macro.

Tested for powerpc64le (as is, and locally patched to intentionally fail
and produce error output).

	* argp/tst-ldbl-argp.c (do_one_test): Use TEST_COMPARE_STRING,
	instead of manually comparing and reporting mismatching strings.
	* misc/tst-ldbl-error.c (do_one_test): Likewise.
	* misc/tst-ldbl-warn.c (do_one_test): Likewise.
---
 argp/tst-ldbl-argp.c  | 9 +--------
 misc/tst-ldbl-error.c | 9 +--------
 misc/tst-ldbl-warn.c  | 6 +-----
 3 files changed, 3 insertions(+), 21 deletions(-)
  

Comments

Florian Weimer Nov. 7, 2018, 2:35 p.m. UTC | #1
* Gabriel F. T. Gomes:

> 	* argp/tst-ldbl-argp.c (do_one_test): Use TEST_COMPARE_STRING,
> 	instead of manually comparing and reporting mismatching strings.
> 	* misc/tst-ldbl-error.c (do_one_test): Likewise.
> 	* misc/tst-ldbl-warn.c (do_one_test): Likewise.

Patch looks okay to me.  Thanks.

Florian
  
Gabriel F. T. Gomes Nov. 9, 2018, 12:46 a.m. UTC | #2
On Wed, 07 Nov 2018, Florian Weimer wrote:

>* Gabriel F. T. Gomes:
>
>> 	* argp/tst-ldbl-argp.c (do_one_test): Use TEST_COMPARE_STRING,
>> 	instead of manually comparing and reporting mismatching strings.
>> 	* misc/tst-ldbl-error.c (do_one_test): Likewise.
>> 	* misc/tst-ldbl-warn.c (do_one_test): Likewise.  
>
>Patch looks okay to me.  Thanks.

Thanks.  Now committed.
  

Patch

diff --git a/argp/tst-ldbl-argp.c b/argp/tst-ldbl-argp.c
index 4465f812af..231abeb18c 100644
--- a/argp/tst-ldbl-argp.c
+++ b/argp/tst-ldbl-argp.c
@@ -73,14 +73,7 @@  do_one_test (const char *expected)
   struct support_capture_subprocess result;
   result = support_capture_subprocess ((void *) &do_test_call, NULL);
 
-  if (strcmp (result.err.buffer, expected) != 0)
-    {
-      support_record_failure ();
-      printf ("error:\n"
-	      "    expected: '%s'\n"
-	      "      actual: '%s'\n",
-	      expected, result.err.buffer);
-    }
+  TEST_COMPARE_STRING (result.err.buffer, expected);
 
   return 0;
 }
diff --git a/misc/tst-ldbl-error.c b/misc/tst-ldbl-error.c
index a02cb2772a..76b2c8f784 100644
--- a/misc/tst-ldbl-error.c
+++ b/misc/tst-ldbl-error.c
@@ -95,14 +95,7 @@  do_one_test (void *callback, const char *expected, ...)
   message = strstr (result.err.buffer, needle);
 
   /* Verify that the output message is as expected.  */
-  if (strcmp (message, expected) != 0)
-    {
-      support_record_failure ();
-      printf ("error:\n"
-	      "    expected: '%s'\n"
-	      "      actual: '%s'\n",
-	      expected, message);
-    }
+  TEST_COMPARE_STRING (message, expected);
 
   va_end (args);
 }
diff --git a/misc/tst-ldbl-warn.c b/misc/tst-ldbl-warn.c
index 3ac0e4c873..69a528755c 100644
--- a/misc/tst-ldbl-warn.c
+++ b/misc/tst-ldbl-warn.c
@@ -61,11 +61,7 @@  do_one_test (int select, const char *format, va_list args,
 
   /* Close the in-memory stream and check the output buffer.  */
   xfclose_memstream (&stream);
-  if (strcmp (stream.buffer, expected) != 0)
-    FAIL_EXIT1 ("error:\n"
-		"    expected: '%s'\n"
-		"      actual: '%s'\n",
-		expected, stream.buffer);
+  TEST_COMPARE_STRING (stream.buffer, expected);
 
   if (stream.buffer != NULL)
     free (stream.buffer);