]> Savannah Git Hosting - gnulib.git/commitdiff
string-desc tests: Avoid test failure on native Windows.
authorBruno Haible <bruno@clisp.org>
Sat, 22 Apr 2023 15:38:28 +0000 (17:38 +0200)
committerBruno Haible <bruno@clisp.org>
Sat, 22 Apr 2023 15:38:28 +0000 (17:38 +0200)
* tests/test-string-desc.c: Include <fcntl.h>, <unistd.h>.
(main): Expect a file name argument. Write to this file, instead of to
fd 3.
* tests/test-string-desc.sh: Pass a file name as argument, instead of
using '3>'.
* modules/string-desc-tests (Depends-on): Add close.

ChangeLog
modules/string-desc-tests
tests/test-string-desc.c
tests/test-string-desc.sh

index f795a645806f3a57c6129dee64fb14bc3b49c960..33cf7be32483dbafae5e1ef328c859f84fdc7575 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2023-04-22  Bruno Haible  <bruno@clisp.org>
+
+       string-desc tests: Avoid test failure on native Windows.
+       * tests/test-string-desc.c: Include <fcntl.h>, <unistd.h>.
+       (main): Expect a file name argument. Write to this file, instead of to
+       fd 3.
+       * tests/test-string-desc.sh: Pass a file name as argument, instead of
+       using '3>'.
+       * modules/string-desc-tests (Depends-on): Add close.
+
 2023-04-22  Bruno Haible  <bruno@clisp.org>
 
        threadlib, pthread-h, threads-h: Avoid mingw's libwinpthread by default.
index d7923c3a604e5652a1cc3ba2c59954e106c79b5b..687d4e2af2b48a1a8d4ed0c5da3e1cc0bde7a81c 100644 (file)
@@ -4,6 +4,7 @@ tests/test-string-desc.c
 tests/macros.h
 
 Depends-on:
+close
 
 configure.ac:
 
index 53aeb68743925ffa4aa96ca46d0addc6bcf9c243..042e6cb6a94c1fe79189fc24be0998b48562d37d 100644 (file)
 
 #include "string-desc.h"
 
+#include <fcntl.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 
 #include "macros.h"
 
 int
-main (void)
+main (int argc, char *argv[])
 {
+  ASSERT (argc > 1);
+  int fd3 = open (argv[1], O_RDWR | O_TRUNC | O_CREAT, 0600);
+  ASSERT (fd3 >= 0);
+
   string_desc_t s0 = string_desc_new_empty ();
   string_desc_t s1 = string_desc_from_c ("Hello world!");
   string_desc_t s2 = string_desc_new_addr (21, "The\0quick\0brown\0\0fox");
@@ -109,9 +115,9 @@ main (void)
                            string_desc_from_c ("llo")) == 0);
 
   /* Test string_desc_write.  */
-  ASSERT (string_desc_write (3, s0) == 0);
-  ASSERT (string_desc_write (3, s1) == 0);
-  ASSERT (string_desc_write (3, s2) == 0);
+  ASSERT (string_desc_write (fd3, s0) == 0);
+  ASSERT (string_desc_write (fd3, s1) == 0);
+  ASSERT (string_desc_write (fd3, s2) == 0);
 
   /* Test string_desc_fwrite.  */
   ASSERT (string_desc_fwrite (stdout, s0) == 0);
@@ -182,5 +188,7 @@ main (void)
     free (ptr);
   }
 
+  close (fd3);
+
   return 0;
 }
index 57f0e2371ba33dd7066a0b65ef474f00996c71b7..a4d92792eb4d56fdee6604400db5ddf55d538fe5 100755 (executable)
@@ -1,7 +1,7 @@
 #!/bin/sh
 . "${srcdir=.}/init.sh"; path_prepend_ .
 
-${CHECKER} test-string-desc${EXEEXT} > test-string-desc-1.tmp 3> test-string-desc-3.tmp || Exit 1
+${CHECKER} test-string-desc${EXEEXT} test-string-desc-3.tmp > test-string-desc-1.tmp || Exit 1
 
 printf 'Hello world!The\0quick\0brown\0\0fox\0' > test-string-desc.ok