mirror of
https://github.com/FAUSheppy/colorredstderr-mirror
synced 2025-12-09 16:38:32 +01:00
Hook error() and error_at_line() if available.
They are used by some GNU programs to display error messages.
This commit is contained in:
@@ -4,8 +4,14 @@ example_SOURCES = example.c
|
||||
example_exec_SOURCES = example_exec.c
|
||||
example_vfork_SOURCES = example_vfork.c
|
||||
|
||||
if HAVE_ERROR_H
|
||||
check_PROGRAMS += example_error
|
||||
example_error_SOURCES = example_error.c
|
||||
endif
|
||||
|
||||
dist_check_SCRIPTS = run.sh lib.sh
|
||||
dist_check_DATA = example.expected \
|
||||
example_error.expected \
|
||||
example_exec.expected \
|
||||
example_vfork.expected \
|
||||
example-noforce.sh \
|
||||
|
||||
57
tests/example_error.c
Normal file
57
tests/example_error.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Test error() and error_at_line(). Non-standard, GNU only.
|
||||
*
|
||||
* Copyright (C) 2013 Simon Ruderich
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE /* for program_invocation_name */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <error.h>
|
||||
|
||||
void (*error_print_progname)(void);
|
||||
|
||||
|
||||
static void print_prognmae(void) {
|
||||
fprintf(stderr, "PROG");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
program_invocation_name = "./example_error";
|
||||
|
||||
error(0, 0, "<message>");
|
||||
error_at_line(0, 0, "file", 42, "<message>");
|
||||
|
||||
error(0, ENOMEM, "<message>");
|
||||
error_at_line(0, ENOMEM, "file", 42, "<message>");
|
||||
error_at_line(0, ENOMEM, "file", 42, "<message>");
|
||||
|
||||
error_print_progname = print_prognmae;
|
||||
error_one_per_line = 1;
|
||||
|
||||
error(0, 0, "<message>");
|
||||
error_at_line(0, 0, "file", 42, "<message>");
|
||||
|
||||
error(0, ENOMEM, "<message>");
|
||||
error_at_line(0, ENOMEM, "file", 42, "<message>");
|
||||
error_at_line(0, ENOMEM, "file", 42, "<message>");
|
||||
|
||||
/* Exit codes are not tested. */
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
10
tests/example_error.expected
Normal file
10
tests/example_error.expected
Normal file
@@ -0,0 +1,10 @@
|
||||
>STDERR>./example_error:<STDERR<>STDERR> <STDERR<>STDERR><message><STDERR<>STDERR>
|
||||
<STDERR<>STDERR>./example_error:<STDERR<>STDERR>file:42:<STDERR<>STDERR> <STDERR<>STDERR><message><STDERR<>STDERR>
|
||||
<STDERR<>STDERR>./example_error:<STDERR<>STDERR> <STDERR<>STDERR><message><STDERR<>STDERR>: Cannot allocate memory<STDERR<>STDERR>
|
||||
<STDERR<>STDERR>./example_error:<STDERR<>STDERR>file:42:<STDERR<>STDERR> <STDERR<>STDERR><message><STDERR<>STDERR>: Cannot allocate memory<STDERR<>STDERR>
|
||||
<STDERR<>STDERR>./example_error:<STDERR<>STDERR>file:42:<STDERR<>STDERR> <STDERR<>STDERR><message><STDERR<>STDERR>: Cannot allocate memory<STDERR<>STDERR>
|
||||
<STDERR<>STDERR>PROG<STDERR<>STDERR><message><STDERR<>STDERR>
|
||||
<STDERR<>STDERR>PROG<STDERR<>STDERR>file:42:<STDERR<>STDERR> <STDERR<>STDERR><message><STDERR<>STDERR>
|
||||
<STDERR<>STDERR>PROG<STDERR<>STDERR><message><STDERR<>STDERR>: Cannot allocate memory<STDERR<>STDERR>
|
||||
<STDERR<>STDERR>PROG<STDERR<>STDERR>file:42:<STDERR<>STDERR> <STDERR<>STDERR><message><STDERR<>STDERR>: Cannot allocate memory<STDERR<>STDERR>
|
||||
<STDERR<
|
||||
@@ -35,9 +35,14 @@ test_script example-redirects.sh
|
||||
test_program example
|
||||
test_program example_exec
|
||||
test_program example_vfork
|
||||
test -x "$builddir/example_error" && test_program example_error
|
||||
|
||||
test_script_subshell example-simple.sh
|
||||
test_script_subshell example-redirects.sh
|
||||
test_program_subshell example
|
||||
test_program_subshell example_exec
|
||||
test_program_subshell example_vfork
|
||||
test -x "$builddir/example_error" && test_program_subshell example_error
|
||||
|
||||
# Necessary in case the test -x evaluates to false.
|
||||
true
|
||||
|
||||
Reference in New Issue
Block a user