From: Bruno Haible Date: Sun, 29 Nov 2020 22:14:56 +0000 (+0100) Subject: spawn-pipe tests: Fix test failure with MSVC. X-Git-Tag: v1.0~3458 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=d74317eac9eea1c7d0f096a5761885d34d58a3c3;p=gnulib.git spawn-pipe tests: Fix test failure with MSVC. * tests/test-spawn-pipe-child.c: Include . (gl_msvc_invalid_parameter_handler): New function. (main): Set a global invalid-parameter handler. * modules/spawn-pipe-tests (Depends-on): Add msvc-inval, stdint. --- diff --git a/ChangeLog b/ChangeLog index 5722677272..c702e4458a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2020-11-29 Bruno Haible + + spawn-pipe tests: Fix test failure with MSVC. + * tests/test-spawn-pipe-child.c: Include . + (gl_msvc_invalid_parameter_handler): New function. + (main): Set a global invalid-parameter handler. + * modules/spawn-pipe-tests (Depends-on): Add msvc-inval, stdint. + 2020-11-29 Bruno Haible execute: Add tests. diff --git a/modules/spawn-pipe-tests b/modules/spawn-pipe-tests index 9a6c0bccd1..5d1372cc02 100644 --- a/modules/spawn-pipe-tests +++ b/modules/spawn-pipe-tests @@ -6,6 +6,8 @@ tests/macros.h Depends-on: close +msvc-inval +stdint configure.ac: diff --git a/tests/test-spawn-pipe-child.c b/tests/test-spawn-pipe-child.c index 2767d1e71b..176710e631 100644 --- a/tests/test-spawn-pipe-child.c +++ b/tests/test-spawn-pipe-child.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -52,6 +53,17 @@ static FILE *myerr; # define fdopen _fdopen #endif +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER +static void __cdecl +gl_msvc_invalid_parameter_handler (const wchar_t *expression, + const wchar_t *function, + const wchar_t *file, + unsigned int line, + uintptr_t dummy) +{ +} +#endif + /* Return non-zero if FD is open. */ static int is_open (int fd) @@ -72,9 +84,6 @@ is_open (int fd) int main (int argc, char *argv[]) { - char buffer[2] = { 's', 't' }; - int fd; - /* fd 2 might be closed, but fd BACKUP_STDERR_FILENO is the original stderr. */ myerr = fdopen (BACKUP_STDERR_FILENO, "w"); @@ -83,10 +92,17 @@ main (int argc, char *argv[]) ASSERT (argc == 2); +#if HAVE_MSVC_INVALID_PARAMETER_HANDLER + /* Avoid exceptions from within _get_osfhandle. */ + _set_invalid_parameter_handler (gl_msvc_invalid_parameter_handler); +#endif + /* Read one byte from fd 0, and write its value plus one to fd 1. fd 2 should be closed iff the argument is 1. Check that no other file descriptors leaked. */ + char buffer[2] = { 's', 't' }; + ASSERT (read (STDIN_FILENO, buffer, 2) == 1); buffer[0]++; @@ -111,6 +127,7 @@ main (int argc, char *argv[]) ASSERT (0); } + int fd; for (fd = 3; fd < 7; fd++) { errno = 0;