/*
* Test error() and error_at_line(). Non-standard, GNU only.
*
* Copyright (C) 2013-2018 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 .
*/
#include
#define _GNU_SOURCE /* for program_invocation_name */
#include
#include
#include
#include
#include
#include
#include
#include "../src/compiler.h"
#include "example.h"
void (*error_print_progname)(void);
static void print_progname(void) {
fprintf(stderr, "PROG");
}
int main(int argc unused, char **argv unused) {
pid_t pid;
char name[] = "./example_error";
program_invocation_name = name;
error(0, 0, "");
error_at_line(0, 0, "file", 42, "");
FORKED_TEST(pid) { error(1, 0, ""); }
FORKED_TEST(pid) { error_at_line(1, 0, "file", 42, ""); }
error(0, ENOMEM, "");
error_at_line(0, ENOMEM, "file", 42, "");
error_at_line(0, ENOMEM, "file", 42, "");
FORKED_TEST(pid) { error(1, ENOMEM, ""); }
FORKED_TEST(pid) { error_at_line(1, ENOMEM, "file", 42, ""); }
fflush(stdout);
printf("\n\n");
fflush(stdout);
error_print_progname = print_progname;
error_one_per_line = 1;
error(0, 0, "");
error_at_line(0, 0, "file", 42, "");
FORKED_TEST(pid) { error(1, 0, ""); }
FORKED_TEST(pid) { error_at_line(1, 0, "file", 42, ""); }
error(0, ENOMEM, "");
error_at_line(0, ENOMEM, "file", 42, "");
error_at_line(0, ENOMEM, "file", 42, "");
FORKED_TEST(pid) { error(1, ENOMEM, ""); }
error_one_per_line = 0;
FORKED_TEST(pid) { error_at_line(1, ENOMEM, "file", 42, ""); }
return EXIT_SUCCESS;
}