summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2004-05-16 19:16:52 +0000
committerPaul Smith <psmith@gnu.org>2004-05-16 19:16:52 +0000
commit08c8105c5468ff743d2f2ff2fdf3b77a6313b53e (patch)
tree51954f0469a6d70c1b58fd30a5955aa5e4b65c86 /tests
parente334942e573ea8a4416eca0afafcaf45c3bba06f (diff)
downloadgunmake-08c8105c5468ff743d2f2ff2fdf3b77a6313b53e.tar.gz
Various enhancements
- OS/2 Patches - OpenVMS updates - Sanitize the handling of -include/sinclude with and without -k - Fix the setting of $< for order-only rules.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/run_make_tests.pl132
-rw-r--r--tests/scripts/features/echoing9
-rw-r--r--tests/scripts/features/errors25
-rw-r--r--tests/scripts/features/include33
-rw-r--r--tests/scripts/features/order_only11
-rw-r--r--tests/scripts/functions/wildcard7
-rw-r--r--tests/scripts/options/dash-C9
-rw-r--r--tests/scripts/options/dash-k14
-rw-r--r--tests/scripts/targets/FORCE13
-rw-r--r--tests/scripts/targets/PHONY15
-rw-r--r--tests/scripts/targets/SILENT12
-rw-r--r--tests/scripts/targets/clean5
-rw-r--r--tests/scripts/variables/special22
-rw-r--r--tests/test_driver.pl47
14 files changed, 199 insertions, 155 deletions
diff --git a/tests/run_make_tests.pl b/tests/run_make_tests.pl
index 4389d43..8452c6b 100755
--- a/tests/run_make_tests.pl
+++ b/tests/run_make_tests.pl
@@ -48,66 +48,100 @@ sub valid_option
return 0;
}
-sub run_make_with_options
+
+# This is an "all-in-one" function. Arguments are as follows:
+#
+# [0] (string): The makefile to be tested.
+# [1] (string): Arguments to pass to make.
+# [2] (string): Answer we should get back.
+# [3] (integer): Exit code we expect. A missing code means 0 (success)
+
+sub run_make_test
{
- local ($filename,$options,$logname,$expected_code) = @_;
- local($code);
- local($command) = $make_path;
+ local ($makestring, $options, $answer, $err_code) = @_;
- $expected_code = 0 unless defined($expected_code);
+ if (! defined($makefile)) {
+ $makefile = &get_tmpfile();
+ }
- if ($filename)
- {
- $command .= " -f $filename";
- }
+ # Replace @MAKEFILE@ with the makefile name and @MAKE@ with the path to
+ # make in both $makestring and $answer.
- if ($options)
- {
- $command .= " $options";
- }
+ $makestring =~ s/#MAKEFILE#/$makefile/g;
+ $makestring =~ s/#MAKE#/$make_name/g;
- if ($valgrind) {
- print VALGRIND "\n\nExecuting: $command\n";
- }
+ $answer =~ s/#MAKEFILE#/$makefile/g;
+ $answer =~ s/#MAKE#/$make_name/g;
- $code = &run_command_with_output($logname,$command);
+ open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n";
+ print MAKEFILE $makestring, "\n";
+ close(MAKEFILE) || die "Failed to write $makefile: $!\n";
- # Check to see if we have Purify errors. If so, keep the logfile.
- # For this to work you need to build with the Purify flag -exit-status=yes
+ &run_make_with_options($makefile, $options, &get_logfile(0), $err_code);
+ &compare_output($answer, &get_logfile(1));
- if ($pure_log && -f $pure_log) {
- if ($code & 0x7000) {
- $code &= ~0x7000;
+ $makefile = undef;
+}
- # If we have a purify log, save it
- $tn = $pure_testname . ($num_of_logfiles ? ".$num_of_logfiles" : "");
- print("Renaming purify log file to $tn\n") if $debug;
- rename($pure_log, "$tn")
- || die "Can't rename $log to $tn: $!\n";
- ++$purify_errors;
- }
- else {
- unlink($pure_log);
- }
- }
+# The old-fashioned way...
+sub run_make_with_options {
+ local ($filename,$options,$logname,$expected_code) = @_;
+ local($code);
+ local($command) = $make_path;
- if ($code != $expected_code)
- {
- print "Error running $make_path ($code): $command\n";
- $test_passed = 0;
- # If it's a SIGINT, stop here
- if ($code & 127) {
- print STDERR "\nCaught signal ".($code & 127)."!\n";
- exit($code);
- }
- return 0;
- }
+ $expected_code = 0 unless defined($expected_code);
- if ($profile & $vos)
- {
- system "add_profile $make_path";
- }
-1;
+ # Reset to reflect this one test.
+ $test_passed = 1;
+
+ if ($filename) {
+ $command .= " -f $filename";
+ }
+
+ if ($options) {
+ $command .= " $options";
+ }
+
+ if ($valgrind) {
+ print VALGRIND "\n\nExecuting: $command\n";
+ }
+
+ $code = &run_command_with_output($logname,$command);
+
+ # Check to see if we have Purify errors. If so, keep the logfile.
+ # For this to work you need to build with the Purify flag -exit-status=yes
+
+ if ($pure_log && -f $pure_log) {
+ if ($code & 0x7000) {
+ $code &= ~0x7000;
+
+ # If we have a purify log, save it
+ $tn = $pure_testname . ($num_of_logfiles ? ".$num_of_logfiles" : "");
+ print("Renaming purify log file to $tn\n") if $debug;
+ rename($pure_log, "$tn")
+ || die "Can't rename $log to $tn: $!\n";
+ ++$purify_errors;
+ } else {
+ unlink($pure_log);
+ }
+ }
+
+ if ($code != $expected_code) {
+ print "Error running $make_path (expected $expected_code; got $code): $command\n";
+ $test_passed = 0;
+ # If it's a SIGINT, stop here
+ if ($code & 127) {
+ print STDERR "\nCaught signal ".($code & 127)."!\n";
+ exit($code);
+ }
+ return 0;
+ }
+
+ if ($profile & $vos) {
+ system "add_profile $make_path";
+ }
+
+ 1;
}
sub print_usage
diff --git a/tests/scripts/features/echoing b/tests/scripts/features/echoing
index ed1e862..2e366cd 100644
--- a/tests/scripts/features/echoing
+++ b/tests/scripts/features/echoing
@@ -54,13 +54,10 @@ $answer = "echo This makefile did not clean the dir... good\n"
# -------
&run_make_with_options($makefile,"clean",&get_logfile,0);
-$answer = "";
-&compare_output($answer,&get_logfile(1));
-
-if (-f $example)
-{
- $test_passed = 0;
+if (-f $example) {
+ $test_passed = 0;
}
+&compare_output('',&get_logfile(1));
# TEST #3
# -------
diff --git a/tests/scripts/features/errors b/tests/scripts/features/errors
index a39064f..253f50f 100644
--- a/tests/scripts/features/errors
+++ b/tests/scripts/features/errors
@@ -52,6 +52,13 @@ $answer = "$delete_command cleanit\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)
@@ -59,14 +66,6 @@ if (!$vos)
&compare_output($answer,&get_logfile(1));
}
-# 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;
-}
-
&touch("foo");
@@ -80,14 +79,12 @@ $answer = "$delete_command cleanit\n"
&run_make_with_options($makefile,"clean2 -i",&get_logfile);
-if (!$vos)
-{
- &compare_output($answer,&get_logfile(1));
+if (-f "foo") {
+ $test_passed = 0;
}
-if (-f "foo")
-{
- $test_passed = 0;
+if (!$vos) {
+ &compare_output($answer,&get_logfile(1));
}
1;
diff --git a/tests/scripts/features/include b/tests/scripts/features/include
index 60f4482..5f20ad8 100644
--- a/tests/scripts/features/include
+++ b/tests/scripts/features/include
@@ -2,7 +2,8 @@
$description = "Test various forms of the GNU make `include' command.";
-$details = "Test include, -include, sinclude and various regressions involving them.
+$details = "\
+Test include, -include, sinclude and various regressions involving them.
Test extra whitespace at the end of the include, multiple -includes and
sincludes (should not give an error) and make sure that errors are reported
for targets that were also -included.";
@@ -46,16 +47,36 @@ $answer = "There should be no errors for this makefile.\n";
$answer = "This is another included makefile\n";
&compare_output($answer, &get_logfile(1));
+$makefile = undef;
+
# Try to build the "error" target; this will fail since we don't know
# how to create makeit.mk, but we should also get a message (even though
# the -include suppressed it during the makefile read phase, we should
# see one during the makefile run phase).
-# The fix to this caused more problems than the error, so I removed it.
-# pds -- 22 Jan 2000
+run_make_test
+ ('
+-include foo.mk
+error: foo.mk ; @echo $@
+',
+ '',
+ "#MAKE#: *** No rule to make target `foo.mk', needed by `error'. Stop.\n",
+ 512
+ );
+
+# Make sure that target-specific variables don't impact things. This could
+# happen because a file record is created when a target-specific variable is
+# set.
+
+run_make_test
+ ('
+bar.mk: foo := baz
+-include bar.mk
+hello: ; @echo hello
+',
+ '',
+ "hello\n"
+ );
-#&run_make_with_options($makefile, "error", &get_logfile, 512);
-#$answer = "$make_name: *** No rule to make target `makeit.mk', needed by `error'.\n";
-#&compare_output($answer, &get_logfile(1));
1;
diff --git a/tests/scripts/features/order_only b/tests/scripts/features/order_only
index ac0d538..82a7253 100644
--- a/tests/scripts/features/order_only
+++ b/tests/scripts/features/order_only
@@ -144,4 +144,15 @@ $answer = "touch baz\n";
unlink(qw(foo.w foo.x baz));
+# TEST #9 -- make sure that $< is set correctly in the face of order-only
+# prerequisites in pattern rules.
+
+run_make_test('
+%r: | baz ; @echo $< $^ $|
+bar: foo
+foo:;@:
+baz:;@:
+', '', "foo foo baz\n");
+
+
1;
diff --git a/tests/scripts/functions/wildcard b/tests/scripts/functions/wildcard
index 0f79acc..5e5a5ff 100644
--- a/tests/scripts/functions/wildcard
+++ b/tests/scripts/functions/wildcard
@@ -85,13 +85,12 @@ else
&run_make_with_options($makefile,"clean",&get_logfile);
-&compare_output($answer,&get_logfile(1));
-
-if ((-f "example.1")||(-f "example.two")||(-f "example.3")||(-f "example.for"))
-{
+if ((-f "example.1")||(-f "example.two")||(-f "example.3")||(-f "example.for")) {
$test_passed = 0;
}
+&compare_output($answer,&get_logfile(1));
+
1;
diff --git a/tests/scripts/options/dash-C b/tests/scripts/options/dash-C
index 3f2b3a1..f31238f 100644
--- a/tests/scripts/options/dash-C
+++ b/tests/scripts/options/dash-C
@@ -33,6 +33,10 @@ chdir $workdir;
$wpath = &get_this_pwd;
chdir $pwd;
+if (-f $example) {
+ $test_passed = 0;
+}
+
# Create the answer to what should be produced by this Makefile
$answer = "$make_name: Entering directory `$wpath'\n"
. "$delete_command EXAMPLE_FILE\n"
@@ -40,9 +44,4 @@ $answer = "$make_name: Entering directory `$wpath'\n"
&compare_output($answer,&get_logfile(1));
-if (-f $example)
-{
- $test_passed = 0;
-}
-
1;
diff --git a/tests/scripts/options/dash-k b/tests/scripts/options/dash-k
index fe5689e..d87a786 100644
--- a/tests/scripts/options/dash-k
+++ b/tests/scripts/options/dash-k
@@ -97,4 +97,18 @@ $make_name: Target `all' not remade because of errors.\n";
&compare_output($answer, &get_logfile(1));
+# TEST -- make sure we keep the error code if we can't create an included
+# makefile.
+
+run_make_test('all: ; @echo hi
+include ifile
+ifile: no-such-file; @false
+',
+ '-k',
+ "#MAKEFILE#:2: ifile: No such file or directory
+#MAKE#: *** No rule to make target `no-such-file', needed by `ifile'.
+#MAKE#: Failed to remake makefile `ifile'.
+hi\n",
+ 512);
+
1;
diff --git a/tests/scripts/targets/FORCE b/tests/scripts/targets/FORCE
index 90ee48d..befb326 100644
--- a/tests/scripts/targets/FORCE
+++ b/tests/scripts/targets/FORCE
@@ -1,4 +1,4 @@
-$description = "The following tests rules without Commands or Dependencies.";
+$description = "The following tests rules without Commands or Dependencies.";
$details = "If the rule ...\n";
@@ -17,7 +17,7 @@ open(MAKEFILE,"> $makefile");
print MAKEFILE ".IGNORE :\n";
print MAKEFILE "clean: FORCE\n";
-print MAKEFILE "\t$delete_command clean\n";
+print MAKEFILE "\t$delete_command clean\n";
print MAKEFILE "FORCE:\n";
# END of Contents of MAKEFILE
@@ -26,20 +26,15 @@ close(MAKEFILE);
# Create a file named "clean". This is the same name as the target clean
-# and tricks the target into thinking that it is up to date. (Unless you
+# and tricks the target into thinking that it is up to date. (Unless you
# use the .PHONY target.
&touch("clean");
$answer = "$delete_command clean\n";
&run_make_with_options($makefile,"clean",&get_logfile);
-&compare_output($answer,&get_logfile(1));
+&compare_output($answer,&get_logfile(1));
-if (-f $example)
-{
- $test_passed = 0;
-}
-
1;
diff --git a/tests/scripts/targets/PHONY b/tests/scripts/targets/PHONY
index 14d5ae1..dd46b3f 100644
--- a/tests/scripts/targets/PHONY
+++ b/tests/scripts/targets/PHONY
@@ -27,7 +27,7 @@ print MAKEFILE ".PHONY : clean \n";
print MAKEFILE "all: \n";
print MAKEFILE "\t\@echo This makefile did not clean the dir ... good\n";
print MAKEFILE "clean: \n";
-print MAKEFILE "\t$delete_command $example clean\n";
+print MAKEFILE "\t$delete_command $example clean\n";
# END of Contents of MAKEFILE
@@ -36,20 +36,19 @@ close(MAKEFILE);
&touch($example);
# Create a file named "clean". This is the same name as the target clean
-# and tricks the target into thinking that it is up to date. (Unless you
+# and tricks the target into thinking that it is up to date. (Unless you
# use the .PHONY target.
&touch("clean");
$answer = "$delete_command $example clean\n";
&run_make_with_options($makefile,"clean",&get_logfile);
-&compare_output($answer,&get_logfile(1));
-
-if (-f $example)
-{
- $test_passed = 0;
+if (-f $example) {
+ $test_passed = 0;
}
-
+
+&compare_output($answer,&get_logfile(1));
+
1;
diff --git a/tests/scripts/targets/SILENT b/tests/scripts/targets/SILENT
index 375cad4..5f9a1db 100644
--- a/tests/scripts/targets/SILENT
+++ b/tests/scripts/targets/SILENT
@@ -22,7 +22,7 @@ open(MAKEFILE,"> $makefile");
print MAKEFILE ".SILENT : clean\n";
print MAKEFILE "clean: \n";
-print MAKEFILE "\t$delete_command EXAMPLE_FILE\n";
+print MAKEFILE "\t$delete_command EXAMPLE_FILE\n";
# END of Contents of MAKEFILE
@@ -32,13 +32,11 @@ close(MAKEFILE);
$answer = "";
&run_make_with_options($makefile,"clean",&get_logfile,0);
-
-&compare_output($answer,&get_logfile(1));
-if (-f $example)
-{
- $test_passed = 0;
+if (-f $example) {
+ $test_passed = 0;
}
-
+&compare_output($answer,&get_logfile(1));
+
1;
diff --git a/tests/scripts/targets/clean b/tests/scripts/targets/clean
index 69f4fd1..b32c976 100644
--- a/tests/scripts/targets/clean
+++ b/tests/scripts/targets/clean
@@ -33,11 +33,10 @@ $answer = "This makefile did not clean the dir... good\n";
$answer = "$delete_command $example\n";
&run_make_with_options($makefile,"clean",&get_logfile,0);
-
-&compare_output($answer,&get_logfile(1)) || &error ("abort");
if (-f $example) {
- $test_passed = 0;
+ $test_passed = 0;
}
+&compare_output($answer,&get_logfile(1)) || &error ("abort");
1;
diff --git a/tests/scripts/variables/special b/tests/scripts/variables/special
index 58c8655..77b355c 100644
--- a/tests/scripts/variables/special
+++ b/tests/scripts/variables/special
@@ -4,12 +4,7 @@ $description = "Test special GNU make variables.";
$details = "";
-$makefile2 = &get_tmpfile;
-
-
-open(MAKEFILE, "> $makefile");
-
-print MAKEFILE <<'EOF';
+&run_make_test('
X1 := $(sort $(filter FOO BAR,$(.VARIABLES)))
@@ -23,21 +18,12 @@ all:
@echo X1 = $(X1)
@echo X2 = $(X2)
@echo LAST = $(sort $(filter FOO BAR,$(.VARIABLES)))
-
-EOF
-
-close(MAKEFILE);
-
-# TEST #1
-# -------
-
-&run_make_with_options($makefile, "", &get_logfile);
-$answer = "X1 =\nX2 = FOO\nLAST = BAR FOO\n";
-&compare_output($answer, &get_logfile(1));
-
+',
+ '', "X1 =\nX2 = FOO\nLAST = BAR FOO\n");
+# $makefile2 = &get_tmpfile;
# open(MAKEFILE, "> $makefile2");
# print MAKEFILE <<'EOF';
diff --git a/tests/test_driver.pl b/tests/test_driver.pl
index 0ddb884..0bca669 100644
--- a/tests/test_driver.pl
+++ b/tests/test_driver.pl
@@ -28,6 +28,10 @@ $tests_run = 0;
# The number of tests in this category that have passed
$tests_passed = 0;
+
+# Yeesh. This whole test environment is such a hack!
+$test_passed = 1;
+
sub toplevel
{
# Get a clean environment
@@ -376,7 +380,7 @@ sub run_each_test
foreach $testname (sort @TESTS)
{
++$categories_run;
- $passed = 1; # reset by test on failure
+ $suite_passed = 1; # reset by test on failure
$num_of_logfiles = 0;
$num_of_tmpfiles = 0;
$description = "";
@@ -423,7 +427,7 @@ sub run_each_test
# How did it go?
if (!defined($code))
{
- $passed = 0;
+ $suite_passed = 0;
if (length ($@))
{
warn "\n*** Test died ($testname): $@\n";
@@ -434,14 +438,14 @@ sub run_each_test
}
}
elsif ($code == -1) {
- $passed = 0;
+ $suite_passed = 0;
}
elsif ($code != 1 && $code != -1) {
- $passed = 0;
+ $suite_passed = 0;
warn "\n*** Test returned $code\n";
}
- if ($passed) {
+ if ($suite_passed) {
++$categories_passed;
$status = "ok ($tests_passed passed)";
for ($i = $num_of_tmpfiles; $i; $i--)
@@ -608,10 +612,7 @@ sub compare_output
local($answer,$logfile) = @_;
local($slurp);
- if ($debug)
- {
- print "Comparing Output ........ ";
- }
+ print "Comparing Output ........ " if $debug;
$slurp = &read_file_into_string ($logfile);
@@ -622,34 +623,28 @@ sub compare_output
++$tests_run;
- if ($slurp eq $answer)
+ if ($slurp eq $answer && $test_passed)
{
- if ($debug)
- {
- print "ok\n";
- }
+ print "ok\n" if $debug;
++$tests_passed;
return 1;
}
- else
- {
- if ($debug)
- {
- print "DIFFERENT OUTPUT\n";
- }
- $passed = 0;
+
+ if ($slurp ne $answer) {
+ print "DIFFERENT OUTPUT\n" if $debug;
+
&create_file (&get_basefile, $answer);
- if ($debug)
- {
- print "\nCreating Difference File ...\n";
- }
+ print "\nCreating Difference File ...\n" if $debug;
+
# Create the difference file
local($command) = "diff -c " . &get_basefile . " " . $logfile;
&run_command_with_output(&get_difffile,$command);
- return 0;
}
+
+ $suite_passed = 0;
+ return 0;
}
sub read_file_into_string