]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blob - tests/example_error.c
Hook error() and error_at_line() if available.
[coloredstderr/coloredstderr.git] / tests / example_error.c
1 /*
2  * Test error() and error_at_line(). Non-standard, GNU only.
3  *
4  * Copyright (C) 2013  Simon Ruderich
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 #define _GNU_SOURCE /* for program_invocation_name */
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <errno.h>
24 #include <error.h>
25
26 void (*error_print_progname)(void);
27
28
29 static void print_prognmae(void) {
30     fprintf(stderr, "PROG");
31 }
32
33
34 int main(int argc, char **argv) {
35     program_invocation_name = "./example_error";
36
37     error(0, 0, "<message>");
38     error_at_line(0, 0, "file", 42, "<message>");
39
40     error(0, ENOMEM, "<message>");
41     error_at_line(0, ENOMEM, "file", 42, "<message>");
42     error_at_line(0, ENOMEM, "file", 42, "<message>");
43
44     error_print_progname = print_prognmae;
45     error_one_per_line = 1;
46
47     error(0, 0, "<message>");
48     error_at_line(0, 0, "file", 42, "<message>");
49
50     error(0, ENOMEM, "<message>");
51     error_at_line(0, ENOMEM, "file", 42, "<message>");
52     error_at_line(0, ENOMEM, "file", 42, "<message>");
53
54     /* Exit codes are not tested. */
55
56     return EXIT_SUCCESS;
57 }