make/tests/scripts/features/errors
Paul Smith 047bd5a16f [SV 46433] Show recipe line offsets in line number messages.
While displaying line numbers, show the relevant line number inside
the recipe not just the first line of the entire recipe.
Sample changes suggested by Brian Vandenberg <phantall@gmail.com>

* gnumake.h (gmk_floc): Add an 'offset' to track the recipe offset.
* read.c (eval, eval_makefile, eval_buffer): Initialize 'offset'.
(record_files, install_pattern_rule): Ditto.
* job.c (new_job, job_next_command): Update 'offset' based on the
line of the recipe we're expanding or invoking.
(child_error): Add 'offset' when showing the line number.
* function.c (func_shell_base): Ditto.
* output.c (error, fatal): Ditto.
* NEWS: Mention the new ability.
* tests/scripts/features/errors: Check the line number on errors.
* tests/scripts/functions/warning: Check the line number on warnings.
* tests/scripts/features/output-sync,
tests/scripts/features/parallelism, tests/scripts/functions/shell,
tests/scripts/functions/error: Update line numbers.
2016-04-11 07:51:05 -04:00

108 lines
2.7 KiB
Perl

# -*-perl-*-
$description = "The following tests the -i option and the '-' in front of \n"
."commands to test that make ignores errors in these commands\n"
."and continues processing.";
$details = "This test runs two makes. The first runs on a target with a \n"
."command that has a '-' in front of it (and a command that is \n"
."intended to fail) and then a delete command after that is \n"
."intended to succeed. If make ignores the failure of the first\n"
."command as it is supposed to, then the second command should \n"
."delete a file and this is what we check for. The second make\n"
."that is run in this test is identical except that the make \n"
."command is given with the -i option instead of the '-' in \n"
."front of the command. They should run the same. ";
if ($vos)
{
$rm_command = "delete_file";
}
else
{
$rm_command = "rm";
}
open(MAKEFILE,"> $makefile");
# The Contents of the MAKEFILE ...
print MAKEFILE "clean:\n"
."\t-$rm_command cleanit\n"
."\t$rm_command foo\n"
."clean2: \n"
."\t$rm_command cleanit\n"
."\t$rm_command foo\n";
# END of Contents of MAKEFILE
close(MAKEFILE);
&touch("foo");
unlink("cleanit");
$cleanit_error = `sh -c "$rm_command cleanit 2>&1"`;
chomp $cleanit_error;
$delete_error_code = $? >> 8;
# TEST #1
# -------
$answer = "$rm_command cleanit
$cleanit_error
$make_name: [$makefile:2: clean] Error $delete_error_code (ignored)
$rm_command foo\n";
&run_make_with_options($makefile,"",&get_logfile);
# If make acted as planned, it should ignore the error from the first
# command in the target and execute the second which deletes the file "foo"
# This file, therefore, should not exist if the test PASSES.
if (-f "foo") {
$test_passed = 0;
}
# The output for this on VOS is too hard to replicate, so we only check it
# on unix.
if (!$vos)
{
&compare_output($answer,&get_logfile(1));
}
&touch("foo");
# TEST #2
# -------
$answer = "$rm_command cleanit
$cleanit_error
$make_name: [$makefile:5: clean2] Error $delete_error_code (ignored)
$rm_command foo\n";
&run_make_with_options($makefile,"clean2 -i",&get_logfile);
if (-f "foo") {
$test_passed = 0;
}
if (!$vos) {
&compare_output($answer,&get_logfile(1));
}
# Test that error line offset works
run_make_test(q!
all:
@echo hi
@echo there
@exit 1
!,
'', "hi\nthere\n#MAKE#: *** [#MAKEFILE#:5: all] Error 1", 512);
1;
### Local Variables:
### eval: (setq whitespace-action (delq 'auto-cleanup whitespace-action))
### End: