]> ruderich.org/simon Gitweb - coloredstderr/coloredstderr.git/blob - tests/example_error.c
e1140492e6f35a410afc9ec1517e6743553d8395
[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 #include <config.h>
21
22 #define _GNU_SOURCE /* for program_invocation_name */
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <errno.h>
26 #include <error.h>
27
28 #include "../src/compiler.h"
29
30
31 void (*error_print_progname)(void);
32
33
34 static void print_prognmae(void) {
35     fprintf(stderr, "PROG");
36 }
37
38
39 int main(int argc unused, char **argv unused) {
40     program_invocation_name = "./example_error";
41
42     error(0, 0, "<message>");
43     error_at_line(0, 0, "file", 42, "<message>");
44
45     error(0, ENOMEM, "<message>");
46     error_at_line(0, ENOMEM, "file", 42, "<message>");
47     error_at_line(0, ENOMEM, "file", 42, "<message>");
48
49     error_print_progname = print_prognmae;
50     error_one_per_line = 1;
51
52     error(0, 0, "<message>");
53     error_at_line(0, 0, "file", 42, "<message>");
54
55     error(0, ENOMEM, "<message>");
56     error_at_line(0, ENOMEM, "file", 42, "<message>");
57     error_at_line(0, ENOMEM, "file", 42, "<message>");
58
59     /* Exit codes are not tested. */
60
61     return EXIT_SUCCESS;
62 }