diff mbox

test-skeleton.c: Use stderr for error messages

Message ID 1397210429-28716-1-git-send-email-will.newton@linaro.org
State Superseded
Headers show

Commit Message

Will Newton April 11, 2014, 10 a.m. UTC
At the moment a mixture of stderr and stdout is used for error
messages. Switch to using stderr for consistency.

ChangeLog:

2014-04-09  Will Newton  <will.newton@linaro.org>

	* test-skeleton.c (create_temp_file): Use stderr for
	outputting error messages.  (main): Likewise.
---
 test-skeleton.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Ondřej Bílka April 11, 2014, 12:32 p.m. UTC | #1
On Fri, Apr 11, 2014 at 11:00:29AM +0100, Will Newton wrote:
> At the moment a mixture of stderr and stdout is used for error
> messages. Switch to using stderr for consistency.
>
 Looks ok except that 

> ChangeLog:
> 
> 2014-04-09  Will Newton  <will.newton@linaro.org>
> 
> 	* test-skeleton.c (create_temp_file): Use stderr for
> 	outputting error messages.  (main): Likewise.

(main): should be at new line
Siddhesh Poyarekar April 11, 2014, 1:16 p.m. UTC | #2
On Fri, Apr 11, 2014 at 11:00:29AM +0100, Will Newton wrote:
> At the moment a mixture of stderr and stdout is used for error
> messages. Switch to using stderr for consistency.
> 
> ChangeLog:
> 
> 2014-04-09  Will Newton  <will.newton@linaro.org>
> 
> 	* test-skeleton.c (create_temp_file): Use stderr for
> 	outputting error messages.  (main): Likewise.

There was a discussion in the past about sticking to stdout for
everything for consistency.  I can't find the link to it, but it is
mentioned on the wiki:

https://sourceware.org/glibc/wiki/Testing/Testsuite#Writing_a_test_case

Siddhesh
Will Newton April 11, 2014, 1:39 p.m. UTC | #3
On 11 April 2014 14:16, Siddhesh Poyarekar <siddhesh@redhat.com> wrote:
> On Fri, Apr 11, 2014 at 11:00:29AM +0100, Will Newton wrote:
>> At the moment a mixture of stderr and stdout is used for error
>> messages. Switch to using stderr for consistency.
>>
>> ChangeLog:
>>
>> 2014-04-09  Will Newton  <will.newton@linaro.org>
>>
>>       * test-skeleton.c (create_temp_file): Use stderr for
>>       outputting error messages.  (main): Likewise.
>
> There was a discussion in the past about sticking to stdout for
> everything for consistency.  I can't find the link to it, but it is
> mentioned on the wiki:
>
> https://sourceware.org/glibc/wiki/Testing/Testsuite#Writing_a_test_case

So we should really be going the other way and outputting everything to stdout?

At the moment test stdout goes to the test output file but stderr goes
to the console. I'm not sure which is the more useful behaviour but
consistency certainly seems good.
Siddhesh Poyarekar April 11, 2014, 2:05 p.m. UTC | #4
On Fri, Apr 11, 2014 at 02:39:21PM +0100, Will Newton wrote:
> On 11 April 2014 14:16, Siddhesh Poyarekar <siddhesh@redhat.com> wrote:
> > On Fri, Apr 11, 2014 at 11:00:29AM +0100, Will Newton wrote:
> >> At the moment a mixture of stderr and stdout is used for error
> >> messages. Switch to using stderr for consistency.
> >>
> >> ChangeLog:
> >>
> >> 2014-04-09  Will Newton  <will.newton@linaro.org>
> >>
> >>       * test-skeleton.c (create_temp_file): Use stderr for
> >>       outputting error messages.  (main): Likewise.
> >
> > There was a discussion in the past about sticking to stdout for
> > everything for consistency.  I can't find the link to it, but it is
> > mentioned on the wiki:
> >
> > https://sourceware.org/glibc/wiki/Testing/Testsuite#Writing_a_test_case
> 
> So we should really be going the other way and outputting everything to stdout?

Yes, that is also why we avoid using perror in test cases.  There are
some that do, but they need to be updated.

Ideally I think we need a WARN status for test cases that want to warn
of a condition and not actually fail, but that's probably something
for later.

Siddhesh
diff mbox

Patch

diff --git a/test-skeleton.c b/test-skeleton.c
index d7d2f75..437c51d 100644
--- a/test-skeleton.c
+++ b/test-skeleton.c
@@ -110,7 +110,7 @@  create_temp_file (const char *base, char **filename)
 			   + sizeof ("XXXXXX"));
   if (fname == NULL)
     {
-      puts ("out of memory");
+      fputs ("out of memory", stderr);
       return -1;
     }
   strcpy (stpcpy (stpcpy (stpcpy (fname, test_dir), "/"), base), "XXXXXX");
@@ -118,7 +118,7 @@  create_temp_file (const char *base, char **filename)
   fd = mkstemp (fname);
   if (fd == -1)
     {
-      printf ("cannot open temporary file '%s': %m\n", fname);
+      fprintf (stderr, "cannot open temporary file '%s': %m\n", fname);
       free (fname);
       return -1;
     }
@@ -368,12 +368,12 @@  main (int argc, char *argv[])
   termpid = TEMP_FAILURE_RETRY (waitpid (pid, &status, 0));
   if (termpid == -1)
     {
-      printf ("Waiting for test program failed: %m\n");
+      fprintf (stderr, "Waiting for test program failed: %m\n");
       exit (1);
     }
   if (termpid != pid)
     {
-      printf ("Oops, wrong test program terminated: expected %ld, got %ld\n",
+      fprintf (stderr, "Oops, wrong test program terminated: expected %ld, got %ld\n",
 	      (long int) pid, (long int) termpid);
       exit (1);
     }