# HG changeset patch # User Rik # Date 1385505428 28800 # Node ID c3cd335bd71bd722d6a46c2462a619bda39c1325 # Parent a1210e318be74dfe275b02a8a3c201d3af609a33 Rewrite failing popen2 test for Windows (bug #40606). * syscalls.cc: Rewrite failing popen2 test for Windows (bug #40606). diff -r a1210e318be7 -r c3cd335bd71b libinterp/corefcn/syscalls.cc --- a/libinterp/corefcn/syscalls.cc Tue Nov 26 22:49:10 2013 +0100 +++ b/libinterp/corefcn/syscalls.cc Tue Nov 26 14:37:08 2013 -0800 @@ -378,53 +378,71 @@ } /* -%!test -%! unix_sort = true; -%! cmd = {"sort", "-r"}; -%! if (ispc ()) -%! status = system ("sort /? 2>NUL 1>NUL"); -%! if (status == 0) -%! unix_sort = false; -%! cmd = {"sort", "/R"}; -%! endif -%! endif -%! [in, out, pid] = popen2 (cmd{:}); -%! if (isunix ()) + +%!test # UNIX-style test +%! if (isunix () || ismac ()) +%! [in, out, pid] = popen2 ("sort", "-r"); %! EAGAIN = errno ("EAGAIN"); -%! else -%! EAGAIN = errno ("EINVAL"); -%! endif -%! fputs (in, "these\nare\nsome\nstrings\n"); -%! fclose (in); -%! done = false; -%! str = {}; -%! idx = 0; -%! errs = 0; -%! do -%! if (! isunix ()) -%! errno (0); -%! endif -%! s = fgets (out); -%! if (ischar (s)) -%! idx++; -%! str{idx} = s; -%! elseif (errno () == EAGAIN) -%! fclear (out); -%! sleep (0.1); -%! if (++errs == 100) +%! fputs (in, "these\nare\nsome\nstrings\n"); +%! fclose (in); +%! done = false; +%! str = {}; +%! idx = 0; +%! errs = 0; +%! do +%! if (ismac ()) # FIXME: Is this necessary? +%! errno (0); +%! endif +%! s = fgets (out); +%! if (ischar (s)) +%! idx++; +%! str{idx} = s; +%! elseif (errno () == EAGAIN) +%! fclear (out); +%! sleep (0.1); +%! if (++errs == 100) +%! done = true; +%! endif +%! else %! done = true; %! endif -%! else -%! done = true; -%! endif -%! until (done) -%! fclose (out); -%! waitpid (pid); -%! if (unix_sort) +%! until (done) +%! fclose (out); +%! waitpid (pid); %! assert (str, {"these\n","strings\n","some\n","are\n"}); -%! else +%! endif + +%!test # Windows-style test +%! if (ispc () && ! isunix ()) +%! [in, out, pid] = popen2 ('C:\Windows\system32\sort.exe', "/R"); +%! EAGAIN = errno ("EINVAL"); +%! fputs (in, "these\r\nare\r\nsome\r\nstrings\r\n"); +%! fclose (in); +%! done = false; +%! str = {}; +%! idx = 0; +%! errs = 0; +%! do +%! errno (0); +%! s = fgets (out); +%! if (ischar (s)) +%! idx++; +%! str{idx} = s; +%! elseif (errno () == EAGAIN) +%! fclear (out); +%! sleep (0.1); +%! if (++errs == 100) +%! done = true; +%! endif +%! else +%! done = true; +%! endif +%! until (done) +%! fclose (out); +%! waitpid (pid); %! assert (str, {"these\r\n","strings\r\n","some\r\n","are\r\n"}); %! endif + */ DEFUNX ("fcntl", Ffcntl, args, ,