tests: improve diagnostics when write(2) fails
authorPeter Rosin <peda@lysator.liu.se>
Mon, 23 Jan 2012 08:18:46 +0000 (09:18 +0100)
committerPeter Rosin <peda@lysator.liu.se>
Mon, 23 Jan 2012 09:05:29 +0000 (10:05 +0100)
MinGW programs can't redirect file descriptor 9, they can only redirect
stdin, stdout and stderr.  So, improve the information in the test log.

See automake bug#10466.

* tests/parallel-tests-fd-redirect.test (baz.c, zardoz.c): Check the
return value from the write(2) call, and report detected errors.

tests/parallel-tests-fd-redirect.test

index 73a134e..8b16378 100755 (executable)
@@ -1,5 +1,5 @@
 #! /bin/sh
-# Copyright (C) 2011 Free Software Foundation, Inc.
+# Copyright (C) 2011, 2012 Free Software Foundation, Inc.
 #
 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -65,20 +65,26 @@ END
 chmod a+x foo.sh bar
 
 cat > baz.c <<'END'
+#include <stdio.h>
 #include <unistd.h>
 int main (void)
 {
-  write (9, " bazbazbaz\n", 11);
-  return 0;
+  ssize_t res = write (9, " bazbazbaz\n", 11);
+  if (res < 0)
+    perror("write failed");
+  return res != 11;
 }
 END
 
 cat > zardoz.c <<'END'
+#include <stdio.h>
 #include <unistd.h>
 int main (void)
 {
-  write (9, " quxquxqux\n", 11);
-  return 0;
+  ssize_t res = write (9, " quxquxqux\n", 11);
+  if (res < 0)
+    perror("write failed");
+  return res != 11;
 }
 END