Only define loff_t for __USE_MISC (bug 14553).
[glibc.git] / support / support_capture_subprocess_check.c
blobff5ee89fb02599ae5206f21745046dd8f888ed42
1 /* Verify capture output from a subprocess.
2 Copyright (C) 2017-2018 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #include <stdbool.h>
20 #include <stdio.h>
21 #include <support/capture_subprocess.h>
22 #include <support/check.h>
24 static void
25 print_context (const char *context, bool *failed)
27 if (*failed)
28 /* Do not duplicate message. */
29 return;
30 support_record_failure ();
31 printf ("error: subprocess failed: %s\n", context);
34 void
35 support_capture_subprocess_check (struct support_capture_subprocess *proc,
36 const char *context, int status,
37 int allowed)
39 TEST_VERIFY ((allowed & sc_allow_none)
40 || (allowed & sc_allow_stdout)
41 || (allowed & sc_allow_stderr));
42 TEST_VERIFY (!((allowed & sc_allow_none)
43 && ((allowed & sc_allow_stdout)
44 || (allowed & sc_allow_stderr))));
46 bool failed = false;
47 if (proc->status != status)
49 print_context (context, &failed);
50 printf ("error: expected exit status: %d\n", status);
51 printf ("error: actual exit status: %d\n", proc->status);
53 if (!(allowed & sc_allow_stdout) && proc->out.length != 0)
55 print_context (context, &failed);
56 printf ("error: unexpected output from subprocess\n");
57 fwrite (proc->out.buffer, proc->out.length, 1, stdout);
58 puts ("\n");
60 if (!(allowed & sc_allow_stderr) && proc->err.length != 0)
62 print_context (context, &failed);
63 printf ("error: unexpected error output from subprocess\n");
64 fwrite (proc->err.buffer, proc->err.length, 1, stdout);
65 puts ("\n");