mirror of
https://github.com/FAUSheppy/colorredstderr-mirror
synced 2025-12-09 16:38:32 +01:00
Fix error_at_line() not always exiting if status != 0.
Also add tests.
This commit is contained in:
8
NEWS
8
NEWS
@@ -1,6 +1,14 @@
|
||||
NEWS
|
||||
====
|
||||
|
||||
0.X
|
||||
---
|
||||
|
||||
- Fix hook for GNU's error_at_line() not exiting if status != 0. If
|
||||
error_one_per_line was used and suppressed a message, then error_at_line()
|
||||
didn't exit.
|
||||
|
||||
|
||||
0.1
|
||||
---
|
||||
|
||||
|
||||
@@ -371,7 +371,7 @@ static void error_vararg(int status, int errnum,
|
||||
if (error_one_per_line
|
||||
&& filename != NULL && linenum != 0
|
||||
&& filename == last_filename && linenum == last_linenum) {
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
last_filename = filename;
|
||||
last_linenum = linenum;
|
||||
@@ -404,6 +404,7 @@ static void error_vararg(int status, int errnum,
|
||||
|
||||
fprintf(stderr, "\n");
|
||||
|
||||
out:
|
||||
if (status != 0) {
|
||||
exit(status);
|
||||
}
|
||||
|
||||
@@ -20,12 +20,16 @@
|
||||
#include <config.h>
|
||||
|
||||
#define _GNU_SOURCE /* for program_invocation_name */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <error.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../src/compiler.h"
|
||||
#include "example.h"
|
||||
|
||||
|
||||
void (*error_print_progname)(void);
|
||||
@@ -37,26 +41,41 @@ static void print_progname(void) {
|
||||
|
||||
|
||||
int main(int argc unused, char **argv unused) {
|
||||
program_invocation_name = "./example_error";
|
||||
pid_t pid;
|
||||
|
||||
char name[] = "./example_error";
|
||||
program_invocation_name = name;
|
||||
|
||||
error(0, 0, "<message>");
|
||||
error_at_line(0, 0, "file", 42, "<message>");
|
||||
FORKED_TEST(pid) { error(1, 0, "<message>"); }
|
||||
FORKED_TEST(pid) { error_at_line(1, 0, "file", 42, "<message>"); }
|
||||
|
||||
error(0, ENOMEM, "<message>");
|
||||
error_at_line(0, ENOMEM, "file", 42, "<message>");
|
||||
error_at_line(0, ENOMEM, "file", 42, "<message>");
|
||||
FORKED_TEST(pid) { error(1, ENOMEM, "<message>"); }
|
||||
FORKED_TEST(pid) { error_at_line(1, ENOMEM, "file", 42, "<message>"); }
|
||||
|
||||
fflush(stdout);
|
||||
printf("\n\n");
|
||||
fflush(stdout);
|
||||
|
||||
error_print_progname = print_progname;
|
||||
error_one_per_line = 1;
|
||||
|
||||
error(0, 0, "<message>");
|
||||
error_at_line(0, 0, "file", 42, "<message>");
|
||||
FORKED_TEST(pid) { error(1, 0, "<message>"); }
|
||||
FORKED_TEST(pid) { error_at_line(1, 0, "file", 42, "<message>"); }
|
||||
|
||||
error(0, ENOMEM, "<message>");
|
||||
error_at_line(0, ENOMEM, "file", 42, "<message>");
|
||||
error_at_line(0, ENOMEM, "file", 42, "<message>");
|
||||
FORKED_TEST(pid) { error(1, ENOMEM, "<message>"); }
|
||||
|
||||
/* Exit codes are not tested. */
|
||||
error_one_per_line = 0;
|
||||
FORKED_TEST(pid) { error_at_line(1, ENOMEM, "file", 42, "<message>"); }
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,27 @@
|
||||
>STDERR>./example_error: <message>
|
||||
./example_error:file:42: <message>
|
||||
./example_error: <message>
|
||||
<STDERR<exit code: 1
|
||||
>STDERR>./example_error:file:42: <message>
|
||||
<STDERR<exit code: 1
|
||||
>STDERR>./example_error: <message>: Cannot allocate memory
|
||||
./example_error:file:42: <message>: Cannot allocate memory
|
||||
./example_error:file:42: <message>: Cannot allocate memory
|
||||
./example_error: <message>: Cannot allocate memory
|
||||
./example_error:file:42: <message>: Cannot allocate memory
|
||||
./example_error:file:42: <message>: Cannot allocate memory
|
||||
PROG<message>
|
||||
<STDERR<exit code: 1
|
||||
>STDERR>./example_error:file:42: <message>: Cannot allocate memory
|
||||
<STDERR<exit code: 1
|
||||
|
||||
|
||||
>STDERR>PROG<message>
|
||||
PROGfile:42: <message>
|
||||
PROG<message>: Cannot allocate memory
|
||||
PROG<message>
|
||||
<STDERR<exit code: 1
|
||||
exit code: 1
|
||||
>STDERR>PROG<message>: Cannot allocate memory
|
||||
PROGfile:42: <message>: Cannot allocate memory
|
||||
<STDERR<EOF
|
||||
PROG<message>: Cannot allocate memory
|
||||
<STDERR<exit code: 1
|
||||
>STDERR>PROGfile:42: <message>: Cannot allocate memory
|
||||
<STDERR<exit code: 1
|
||||
EOF
|
||||
|
||||
Reference in New Issue
Block a user