2 * Test error() and error_at_line(). Non-standard, GNU only.
4 * Copyright (C) 2013-2015 Simon Ruderich
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #define _GNU_SOURCE /* for program_invocation_name */
27 #include <sys/types.h>
31 #include "../src/compiler.h"
35 void (*error_print_progname)(void);
38 static void print_progname(void) {
39 fprintf(stderr, "PROG");
43 int main(int argc unused, char **argv unused) {
46 char name[] = "./example_error";
47 program_invocation_name = name;
49 error(0, 0, "<message>");
50 error_at_line(0, 0, "file", 42, "<message>");
51 FORKED_TEST(pid) { error(1, 0, "<message>"); }
52 FORKED_TEST(pid) { error_at_line(1, 0, "file", 42, "<message>"); }
54 error(0, ENOMEM, "<message>");
55 error_at_line(0, ENOMEM, "file", 42, "<message>");
56 error_at_line(0, ENOMEM, "file", 42, "<message>");
57 FORKED_TEST(pid) { error(1, ENOMEM, "<message>"); }
58 FORKED_TEST(pid) { error_at_line(1, ENOMEM, "file", 42, "<message>"); }
64 error_print_progname = print_progname;
65 error_one_per_line = 1;
67 error(0, 0, "<message>");
68 error_at_line(0, 0, "file", 42, "<message>");
69 FORKED_TEST(pid) { error(1, 0, "<message>"); }
70 FORKED_TEST(pid) { error_at_line(1, 0, "file", 42, "<message>"); }
72 error(0, ENOMEM, "<message>");
73 error_at_line(0, ENOMEM, "file", 42, "<message>");
74 error_at_line(0, ENOMEM, "file", 42, "<message>");
75 FORKED_TEST(pid) { error(1, ENOMEM, "<message>"); }
77 error_one_per_line = 0;
78 FORKED_TEST(pid) { error_at_line(1, ENOMEM, "file", 42, "<message>"); }