diff options
Diffstat (limited to 'src/kmk/tests')
38 files changed, 1679 insertions, 691 deletions
diff --git a/src/kmk/tests/ChangeLog b/src/kmk/tests/ChangeLog index d9a0488..d036568 100644 --- a/src/kmk/tests/ChangeLog +++ b/src/kmk/tests/ChangeLog @@ -1,3 +1,187 @@ +2010-07-28 Paul Smith <psmith@gnu.org> + + * scripts/targets/POSIX: Compatibility issues with Solaris (and + Tru64?); "false" returns different exit codes, and set -x shows + output with extra whitespace. Run the commands by hand first to + find out what the real shell would do, then compare what make does. + * scripts/variables/SHELL: Ditto. + +2010-07-12 Paul Smith <psmith@gnu.org> + + * test_driver.pl: Add a new $perl_name containing the path to Perl. + * run_make_tests.pl (run_make_test): Replace the special string + #PERL# in a makefile etc. with the path the Perl executable so + makefiles can use it. + + * scripts/targets/ONESHELL: Add a new set of regression tests for + the .ONESHELL feature. + +2010-07-06 Paul Smith <psmith@gnu.org> + + * scripts/variables/SHELL: Test the new .SHELLFLAGS variable. + + * scripts/targets/POSIX: New file. Test the .POSIX special target. + Verify that enabling .POSIX changes the shell flags to set -e. + +2010-07-01 Paul Smith <psmith@gnu.org> + + * scripts/features/recursion: Add a space to separate command-line + args. Fixes Savannah bug #29968. + +2009-11-12 Boris Kolpackov <boris@codesynthesis.com> + + * scripts/features/vpath3: Test for the new library search + behavior. + +2009-10-06 Boris Kolpackov <boris@codesynthesis.com> + + * scripts/features/se_explicit: Enable the test for now fixed + Savannah bug 25780. + +2009-10-06 Boris Kolpackov <boris@codesynthesis.com> + + * scripts/variables/undefine: Tests for the new undefine feature. + +2009-10-03 Paul Smith <psmith@gnu.org> + + * scripts/features/parallelism: Test for open Savannah bug #26846. + + * scripts/variables/MAKE: Rewrite for new run_make_test() format. + + * scripts/variables/MAKEFLAGS: Created. + Add test for Savannah bug #2216 (still open). + + * scripts/features/include: Test for Savannah bug #102 (still open). + +2009-09-30 Boris Kolpackov <boris@codesynthesis.com> + + * scripts/features/include: Add diagnostics issuing tests for + cases where targets have been updated and failed with the + dontcare flag. Savannah bugs #15110, #25493, #12686, #17740. + +2009-09-28 Paul Smith <psmith@gnu.org> + + * scripts/functions/shell: Add regression test for Savannah bug + #20513 (still open). + + * scripts/features/se_explicit: Add regression tests for Savannah + bug #25780 (still open). + + * run_make_tests.pl (valid_option): Add a new flag, -all([-_]?tests)? + that runs tests we know will fail. This allows us to add + regression tests to the test suite for bugs that haven't been + fixed yet. + +2009-09-28 Boris Kolpackov <boris@codesynthesis.com> + + * scripts/features/patspecific_vars: Add a test for the shortest + stem first order. + + * scripts/features/patternrules: Add a test for the shortest stem + first order. + +2009-09-24 Paul Smith <psmith@gnu.org> + + * scripts/features/se_implicit: Add a test for order-only + secondary expansion prerequisites. + +2009-09-23 Paul Smith <psmith@gnu.org> + + * scripts/features/patternrules: Test that we can remove pattern + rules, both single and multiple prerequisites. Savannah bug #18622. + + * scripts/features/echoing: Rework for run_make_test(). + +2009-06-14 Paul Smith <psmith@gnu.org> + + * scripts/features/vpath: Verify we don't get bogus circular + dependency warnings if we choose a different file via vpath during + update. Savannah bug #13529. + +2009-06-13 Paul Smith <psmith@gnu.org> + + * scripts/variables/MAKEFILES: Verify that MAKEFILES included + files (and files included by them) don't set the default goal. + Savannah bug #13401. + + * scripts/functions/wildcard: Test that wildcards with + non-existent glob matchers return empty. + +2009-06-09 Paul Smith <psmith@gnu.org> + + * scripts/options/dash-B: Test the $? works correctly with -B. + Savannah bug #17825. + + * scripts/features/patternrules: Test that dependencies of + "also_make" targets are created properly. Savannah bug #19108. + + * test_driver.pl (compare_output): Create a "run" file for failed + tests containing the command that was run. + (get_runfile): New function. + + * run_make_tests.pl (valid_option): Enhanced support for valgrind: + allow memcheck and massif tools. + + * scripts/features/patternrules: Have to comment out a line in the + first test due to backing out a change that broke the implicit + rule search algorithm. Savannah bug #17752. + * scripts/misc/general4: Remove a test that is redundant with + patternrules. + + * scripts/features/parallelism: Add a test for re-exec with + jobserver master override. Savannah bug #18124. + +2009-06-08 Paul Smith <psmith@gnu.org> + + * scripts/features/targetvars: Add a test for continued target + vars after a semicolon. Savannah bug #17521. + +2009-06-07 Paul Smith <psmith@gnu.org> + + * scripts/features/se_explicit: Make sure we catch defining + prereqs during snap_deps(). Savannah bug #24622. + + * scripts/variables/automatic: Check prereq ordering when the + target with the recipe has no prereqs. Savannah bug #21198. + + * scripts/variables/LIBPATTERNS: Add a new set of test for + $(.LIBPATTERNS) (previously untested!) + +2009-06-04 Paul Smith <psmith@gnu.org> + + * scripts/variables/SHELL: The export target-specific SHELL test + has an incorrect known-good-value. + + * scripts/misc/general4: Check for whitespace (ffeed, vtab, etc.) + + * scripts/features/se_explicit: Add tests for Savannah bug #24588. + +2009-05-31 Paul Smith <psmith@gnu.org> + + * scripts/variables/DEFAULT_GOAL: Add tests for Savannah bug #25697. + + * scripts/features/targetvars: Add tests of overrides for Savannah + bug #26207. + * scripts/features/patspecific_vars: Ditto. + + * scripts/features/patternrules: Add a test for Savannah bug #26593. + +2009-05-30 Paul Smith <psmith@gnu.org> + + * scripts/variables/flavors: Update with new variable flavor tests. + * scripts/variables/define: Create a new set of tests for + define/endef and move those aspects of the flavors suite here. + +2009-05-25 Paul Smith <psmith@gnu.org> + + * scripts/features/targetvars: Ditto. + + * scripts/features/export: Test new variable parsing abilities. + +2009-02-23 Ramon Garcia <ramon.garcia.f@gmail.com> + + * scripts/variables/private: Create a new suite of tests for 'private'. + 2007-11-04 Paul Smith <psmith@gnu.org> * scripts/functions/eval: Update error message for command -> recipe. @@ -879,7 +1063,7 @@ Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the diff --git a/src/kmk/tests/NEWS b/src/kmk/tests/NEWS index 6d4fcbb..43971ec 100644 --- a/src/kmk/tests/NEWS +++ b/src/kmk/tests/NEWS @@ -163,7 +163,7 @@ Changes from 0.1 to 0.2 (5-4-92): ------------------------------------------------------------------------------- Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the diff --git a/src/kmk/tests/README b/src/kmk/tests/README index 9791005..3860bdb 100644 --- a/src/kmk/tests/README +++ b/src/kmk/tests/README @@ -8,7 +8,7 @@ distributed under the following terms: ----------------------------------------------------------------------------- Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. + 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Make. GNU Make is free software; you can redistribute it and/or modify it under the diff --git a/src/kmk/tests/mkshadow b/src/kmk/tests/mkshadow index 22eb447..d41b40e 100755 --- a/src/kmk/tests/mkshadow +++ b/src/kmk/tests/mkshadow @@ -4,7 +4,8 @@ # Typically you'd put the shadow in /tmp or another local disk # # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -# 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under diff --git a/src/kmk/tests/run_make_tests.pl b/src/kmk/tests/run_make_tests.pl index 00dc41d..c8d7b55 100755 --- a/src/kmk/tests/run_make_tests.pl +++ b/src/kmk/tests/run_make_tests.pl @@ -12,7 +12,8 @@ # (and others) # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, -# 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under @@ -28,10 +29,17 @@ # You should have received a copy of the GNU General Public License along with # this program. If not, see <http://www.gnu.org/licenses/>. + $valgrind = 0; # invoke make with valgrind -$valgrind_args = '--num-callers=15 --tool=memcheck --leak-check=full'; +$valgrind_args = ''; +$memcheck_args = '--num-callers=15 --tool=memcheck --leak-check=full'; +$massif_args = '--num-callers=15 --tool=massif --alloc-fn=xmalloc --alloc-fn=xcalloc --alloc-fn=xrealloc --alloc-fn=xstrdup --alloc-fn=xstrndup'; $pure_log = undef; +$command_string = ''; + +$all_tests = 0; + require "test_driver.pl"; # Some target systems might not have the POSIX module... @@ -43,20 +51,30 @@ sub valid_option { local($option) = @_; - if ($option =~ /^-make([-_]?path)?$/) - { - $make_path = shift @argv; - if (!-f $make_path) - { - print "$option $make_path: Not found.\n"; - exit 0; - } - return 1; + if ($option =~ /^-make([-_]?path)?$/i) { + $make_path = shift @argv; + if (!-f $make_path) { + print "$option $make_path: Not found.\n"; + exit 0; + } + return 1; + } + + if ($option =~ /^-all([-_]?tests)?$/i) { + $all_tests = 1; + return 1; + } + + if ($option =~ /^-(valgrind|memcheck)$/i) { + $valgrind = 1; + $valgrind_args = $memcheck_args; + return 1; } - if ($option =~ /^-valgrind$/i) { - $valgrind = 1; - return 1; + if ($option =~ /^-massif$/i) { + $valgrind = 1; + $valgrind_args = $massif_args; + return 1; } # This doesn't work--it _should_! Someone badly needs to fix this. @@ -105,6 +123,7 @@ sub run_make_test $makestring =~ s/#MAKEFILE#/$makefile/g; $makestring =~ s/#MAKEPATH#/$mkpath/g; $makestring =~ s/#MAKE#/$make_name/g; + $makestring =~ s/#PERL#/$perl_name/g; $makestring =~ s/#PWD#/$pwd/g; # Populate the makefile! @@ -119,6 +138,7 @@ sub run_make_test $answer =~ s/#MAKEFILE#/$makefile/g; $answer =~ s/#MAKEPATH#/$mkpath/g; $answer =~ s/#MAKE#/$make_name/g; + $answer =~ s/#PERL#/$perl_name/g; $answer =~ s/#PWD#/$pwd/g; run_make_with_options($makefile, $options, &get_logfile(0), @@ -148,6 +168,8 @@ sub run_make_with_options { $command .= " $options"; } + $command_string = "$command\n"; + if ($valgrind) { print VALGRIND "\n\nExecuting: $command\n"; } @@ -155,7 +177,10 @@ sub run_make_with_options { { my $old_timeout = $test_timeout; - $test_timeout = $timeout if $timeout; + $timeout and $test_timeout = $timeout; + + # If valgrind is enabled, turn off the timeout check + $valgrind and $test_timeout = 0; $code = &run_command_with_output($logname,$command); @@ -183,10 +208,12 @@ sub run_make_with_options { if ($code != $expected_code) { print "Error running $make_path (expected $expected_code; got $code): $command\n"; $test_passed = 0; + $runf = &get_runfile; + &create_file (&get_runfile, $command_string); # If it's a SIGINT, stop here if ($code & 127) { print STDERR "\nCaught signal ".($code & 127)."!\n"; - exit($code); + ($code & 127) == 2 and exit($code); } return 0; } @@ -195,19 +222,28 @@ sub run_make_with_options { system "add_profile $make_path"; } - 1; + return 1; } sub print_usage { &print_standard_usage ("run_make_tests", - "[-make_path make_pathname] [-valgrind]",); + "[-make_path make_pathname] [-memcheck] [-massif]",); } sub print_help { - &print_standard_help ("-make_path", - "\tYou may specify the pathname of the copy of make to run."); + &print_standard_help ( + "-make_path", + "\tYou may specify the pathname of the copy of make to run.", + "-valgrind", + "-memcheck", + "\tRun the test suite under valgrind's memcheck tool.", + "\tChange the default valgrind args with the VALGRIND_ARGS env var.", + "-massif", + "\tRun the test suite under valgrind's massif toool.", + "\tChange the default valgrind args with the VALGRIND_ARGS env var." + ); } sub get_this_pwd { @@ -335,11 +371,12 @@ sub set_more_defaults # Set up for valgrind, if requested. if ($valgrind) { + my $args = $valgrind_args; open(VALGRIND, "> valgrind.out") || die "Cannot open valgrind.out: $!\n"; # -q --leak-check=yes - exists $ENV{VALGRIND_ARGS} and $valgrind_args = $ENV{VALGRIND_ARGS}; - $make_path = "valgrind --log-fd=".fileno(VALGRIND)." $valgrind_args $make_path"; + exists $ENV{VALGRIND_ARGS} and $args = $ENV{VALGRIND_ARGS}; + $make_path = "valgrind --log-fd=".fileno(VALGRIND)." $args $make_path"; # F_SETFD is 2 fcntl(VALGRIND, 2, 0) or die "fcntl(setfd) failed: $!\n"; system("echo Starting on `date` 1>&".fileno(VALGRIND)); diff --git a/src/kmk/tests/scripts/features/echoing b/src/kmk/tests/scripts/features/echoing index 2e366cd..40debf5 100644 --- a/src/kmk/tests/scripts/features/echoing +++ b/src/kmk/tests/scripts/features/echoing @@ -1,87 +1,64 @@ -$description = "The following test creates a makefile to test command \n" - ."echoing. It tests that when a command line starts with \n" - ."a '\@', the echoing of that line is suppressed. It also \n" - ."tests the -n option which tells make to ONLY echo the \n" - ."commands and no execution happens. In this case, even \n" - ."the commands with '\@' are printed. Lastly, it tests the \n" - ."-s flag which tells make to prevent all echoing, as if \n" - ."all commands started with a '\@'."; - -$details = "This test is similar to the 'clean' test except that a '\@' has\n" - ."been placed in front of the delete command line. Four tests \n" - ."are run here. First, make is run normally and the first echo\n" - ."command should be executed. In this case there is no '\@' so \n" - ."we should expect make to display the command AND display the \n" - ."echoed message. Secondly, make is run with the clean target, \n" - ."but since there is a '\@' at the beginning of the command, we\n" - ."expect no output; just the deletion of a file which we check \n" - ."for. Third, we give the clean target again except this time\n" - ."we give make the -n option. We now expect the command to be \n" - ."displayed but not to be executed. In this case we need only \n" - ."to check the output since an error message would be displayed\n" - ."if it actually tried to run the delete command again and the \n" - ."file didn't exist. Lastly, we run the first test again with \n" - ."the -s option and check that make did not echo the echo \n" - ."command before printing the message."; +# -*-perl-*- +$description = "The following test creates a makefile to test command +echoing. It tests that when a command line starts with +a '\@', the echoing of that line is suppressed. It also +tests the -n option which tells make to ONLY echo the +commands and no execution happens. In this case, even +the commands with '\@' are printed. Lastly, it tests the +-s flag which tells make to prevent all echoing, as if +all commands started with a '\@'."; + +$details = "This test is similar to the 'clean' test except that a '\@' has +been placed in front of the delete command line. Four tests +are run here. First, make is run normally and the first echo +command should be executed. In this case there is no '\@' so +we should expect make to display the command AND display the +echoed message. Secondly, make is run with the clean target, +but since there is a '\@' at the beginning of the command, we +expect no output; just the deletion of a file which we check +for. Third, we give the clean target again except this time +we give make the -n option. We now expect the command to be +displayed but not to be executed. In this case we need only +to check the output since an error message would be displayed +if it actually tried to run the delete command again and the +file didn't exist. Lastly, we run the first test again with +the -s option and check that make did not echo the echo +command before printing the message.\n"; $example = "EXAMPLE_FILE"; -open(MAKEFILE,"> $makefile"); - -# The Contents of the MAKEFILE ... - -print MAKEFILE "all: \n"; -print MAKEFILE "\techo This makefile did not clean the dir... good\n"; -print MAKEFILE "clean: \n"; -print MAKEFILE "\t\@$delete_command $example\n"; - -# END of Contents of MAKEFILE - -close(MAKEFILE); - -&touch($example); +touch($example); # TEST #1 # ------- -&run_make_with_options($makefile,"",&get_logfile,0); -$answer = "echo This makefile did not clean the dir... good\n" - ."This makefile did not clean the dir... good\n"; -&compare_output($answer,&get_logfile(1)); - +run_make_test(" +all: +\techo This makefile did not clean the dir... good +clean: +\t\@$delete_command $example\n", + '', 'echo This makefile did not clean the dir... good +This makefile did not clean the dir... good'); # TEST #2 # ------- -&run_make_with_options($makefile,"clean",&get_logfile,0); +run_make_test(undef, 'clean', ''); if (-f $example) { $test_passed = 0; + unlink($example); } -&compare_output('',&get_logfile(1)); # TEST #3 # ------- -&run_make_with_options($makefile,"-n clean",&get_logfile,0); -$answer = "$delete_command $example\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, '-n clean', "$delete_command $example\n"); # TEST #4 # ------- -&run_make_with_options($makefile,"-s",&get_logfile,0); -$answer = "This makefile did not clean the dir... good\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, '-s', "This makefile did not clean the dir... good\n"); 1; - - - - - - - - - diff --git a/src/kmk/tests/scripts/features/export b/src/kmk/tests/scripts/features/export index 38efe11..81bff0c 100644 --- a/src/kmk/tests/scripts/features/export +++ b/src/kmk/tests/scripts/features/export @@ -6,12 +6,7 @@ $details = ""; # The test driver cleans out our environment for us so we don't have to worry # about that here. -open(MAKEFILE,"> $makefile"); - -# The Contents of the MAKEFILE ... - -print MAKEFILE <<'EOMAKE'; - +&run_make_test(' FOO = foo BAR = bar BOZ = boz @@ -40,76 +35,44 @@ endif all: @echo "FOO=$(FOO) BAR=$(BAR) BAZ=$(BAZ) BOZ=$(BOZ) BITZ=$(BITZ) BOTZ=$(BOTZ)" @echo "FOO=$$FOO BAR=$$BAR BAZ=$$BAZ BOZ=$$BOZ BITZ=$$BITZ BOTZ=$$BOTZ" - -EOMAKE - -close(MAKEFILE); - -# TEST 0: basics - -&run_make_with_options($makefile,"",&get_logfile,0); - -$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz -FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"; - -&compare_output($answer,&get_logfile(1)); +', + '', "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz +FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 1: make sure vars inherited from the parent are exported $extraENV{FOO} = 1; -&run_make_with_options($makefile,"",&get_logfile,0); - -$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz -FOO=foo BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"; - -&compare_output($answer,&get_logfile(1)); +&run_make_test(undef, '', "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz +FOO=foo BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 2: global export. Explicit unexport takes precedence. -&run_make_with_options($makefile,"EXPORT_ALL=1",&get_logfile,0); - -$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz -FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"; - -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, "EXPORT_ALL=1" , + "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz +FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 3: global unexport. Explicit export takes precedence. -&run_make_with_options($makefile,"UNEXPORT_ALL=1",&get_logfile,0); - -$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz -FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"; - -&compare_output($answer,&get_logfile(1)); +&run_make_test(undef, "UNEXPORT_ALL=1", + "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz +FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 4: both: in the above makefile the unexport comes last so that rules. -&run_make_with_options($makefile,"EXPORT_ALL=1 UNEXPORT_ALL=1",&get_logfile,0); - -$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz -FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"; - -&compare_output($answer,&get_logfile(1)); +&run_make_test(undef, "EXPORT_ALL=1 UNEXPORT_ALL=1", + "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz +FOO= BAR= BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 5: test the pseudo target. -&run_make_with_options($makefile,"EXPORT_ALL_PSEUDO=1",&get_logfile,0); - -$answer = "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz -FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"; - -&compare_output($answer,&get_logfile(1)); - +&run_make_test(undef, "EXPORT_ALL_PSEUDO=1", + "FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=botz +FOO=foo BAR=bar BAZ=baz BOZ=boz BITZ=bitz BOTZ=\n"); # TEST 6: Test the expansion of variables inside export -$makefile2 = &get_tmpfile; - -open(MAKEFILE, "> $makefile2"); - -print MAKEFILE <<'EOF'; - +&run_make_test(' foo = f-ok bar = b-ok @@ -125,24 +88,12 @@ export $(B)ar all: @echo foo=$(foo) bar=$(bar) @echo foo=$$foo bar=$$bar - -EOF - -close(MAKEFILE); - -&run_make_with_options($makefile2,"",&get_logfile,0); -$answer = "foo=f-ok bar=b-ok\nfoo=f-ok bar=b-ok\n"; -&compare_output($answer,&get_logfile(1)); - +', + "", "foo=f-ok bar=b-ok\nfoo=f-ok bar=b-ok\n"); # TEST 7: Test the expansion of variables inside unexport -$makefile3 = &get_tmpfile; - -open(MAKEFILE, "> $makefile3"); - -print MAKEFILE <<'EOF'; - +&run_make_test(' foo = f-ok bar = b-ok @@ -160,24 +111,12 @@ unexport $(B)ar all: @echo foo=$(foo) bar=$(bar) @echo foo=$$foo bar=$$bar - -EOF - -close(MAKEFILE); - -&run_make_with_options($makefile3,"",&get_logfile,0); -$answer = "foo=f-ok bar=b-ok\nfoo= bar=\n"; -&compare_output($answer,&get_logfile(1)); - +', + '', "foo=f-ok bar=b-ok\nfoo= bar=\n"); # TEST 7: Test exporting multiple variables on the same line -$makefile4 = &get_tmpfile; - -open(MAKEFILE, "> $makefile4"); - -print MAKEFILE <<'EOF'; - +&run_make_test(' A = a B = b C = c @@ -196,23 +135,14 @@ export F G H I J export D E $(SOME) all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J -EOF - -close(MAKEFILE); - -&run_make_with_options($makefile4,"",&get_logfile,0); -$answer = "A=a B=b C=c D=d E=e F=f G=g H=h I=i J=j\n"; -&compare_output($answer,&get_logfile(1)); - +', + '', "A=a B=b C=c D=d E=e F=f G=g H=h I=i J=j\n"); # TEST 8: Test unexporting multiple variables on the same line -$makefile5 = &get_tmpfile; - -open(MAKEFILE, "> $makefile5"); - -print MAKEFILE <<'EOF'; +@extraENV{qw(A B C D E F G H I J)} = qw(1 2 3 4 5 6 7 8 9 10); +&run_make_test(' A = a B = b C = c @@ -231,16 +161,26 @@ unexport F G H I J unexport D E $(SOME) all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J -EOF - -close(MAKEFILE); - -@extraENV{qw(A B C D E F G H I J)} = qw(1 2 3 4 5 6 7 8 9 10); - -&run_make_with_options($makefile5,"",&get_logfile,0); -$answer = "A= B= C= D= E= F= G= H= I= J=\n"; -&compare_output($answer,&get_logfile(1)); - +', + '', "A= B= C= D= E= F= G= H= I= J=\n"); + +# TEST 9: Check setting a variable named "export" + +&run_make_test(' +export = 123 +export export +export export = 456 +a: ; @echo "\$$(export)=$(export) / \$$export=$$export" +', + '', "\$(export)=456 / \$export=456\n"); + +# TEST 9: Check "export" as a target + +&run_make_test(' +a: export +export: ; @echo "$@" +', + '', "export\n"); # This tells the test driver that the perl test script executed properly. 1; diff --git a/src/kmk/tests/scripts/features/include b/src/kmk/tests/scripts/features/include index 196a987..ba8908c 100644 --- a/src/kmk/tests/scripts/features/include +++ b/src/kmk/tests/scripts/features/include @@ -90,8 +90,6 @@ all: ; @: foo: bar; @: ', '', ''); -1; - # Make sure that we don't die when the command fails but we dontcare. # (Savannah bug #13216). @@ -117,4 +115,65 @@ include -include sinclude', '', ''); + +# Test that the diagnostics is issued even if the target has been +# tried before with the dontcare flag (direct dependency case). +# +run_make_test(' +-include foo + +all: bar + +foo: baz +bar: baz +', +'', +"#MAKE#: *** No rule to make target `baz', needed by `bar'. Stop.\n", +512); + +# Test that the diagnostics is issued even if the target has been +# tried before with the dontcare flag (indirect dependency case). +# +run_make_test(' +-include foo + +all: bar + +foo: baz +bar: baz +baz: end +', +'', +"#MAKE#: *** No rule to make target `end', needed by `baz'. Stop.\n", +512); + +# Test that the diagnostics is issued even if the target has been +# tried before with the dontcare flag (include/-include case). +# +run_make_test(' +include bar +-include foo + +all: + +foo: baz +bar: baz +baz: end +', +'', +"#MAKEFILE#:2: bar: No such file or directory +#MAKE#: *** No rule to make target `end', needed by `baz'. Stop.\n", +512); + +if ($all_tests) { + # Test that include of a rebuild-able file doesn't show a warning + # Savannah bug #102 + run_make_test(q! +include foo +foo: ; @echo foo = bar > $@ +!, + '', "#MAKE#: `foo' is up to date.\n"); + rmfiles('foo'); +} + 1; diff --git a/src/kmk/tests/scripts/features/override b/src/kmk/tests/scripts/features/override index 23e4f2b..fff6c4e 100644 --- a/src/kmk/tests/scripts/features/override +++ b/src/kmk/tests/scripts/features/override @@ -1,34 +1,45 @@ -$description = "The following test creates a makefile to ..."; +# -*-perl-*- -$details = ""; - -open(MAKEFILE,"> $makefile"); - -# The Contents of the MAKEFILE ... - -print MAKEFILE "override define foo\n" - ."\@echo First comes the definition.\n" - ."\@echo Then comes the override.\n" - ."endef\n" - ."all: \n" - ."\t\$(foo)\n"; +$description = "Test the override directive on variable assignments."; -# END of Contents of MAKEFILE - -close(MAKEFILE); +$details = ""; -&run_make_with_options($makefile,"foo=Hello",&get_logfile); +# TEST 0: Basic override -# Create the answer to what should be produced by this Makefile -$answer = "First comes the definition.\n" - ."Then comes the override.\n"; +run_make_test(' +X = start +override recur = $(X) +override simple := $(X) +X = end +all: ; @echo "$(recur) $(simple)" +', + 'recur=I simple=J', "end start\n"); -&compare_output($answer,&get_logfile(1)); +# TEST 1: Override with append -1; +run_make_test(' +X += X1 +override X += X2 +override Y += Y1 +Y += Y2 +all: ; @echo "$(X) $(Y)" +', + '', "X1 X2 Y1\n"); +# TEST 2: Override with append to the command line +run_make_test(undef, 'X=C Y=C', "C X2 C Y1\n"); +# Test override of define/endef +run_make_test(' +override define foo +@echo First comes the definition. +@echo Then comes the override. +endef +all: ; $(foo) +', + 'foo=Hello', "First comes the definition.\nThen comes the override.\n"); +1; diff --git a/src/kmk/tests/scripts/features/parallelism b/src/kmk/tests/scripts/features/parallelism index 13827a4..d3d3489 100644 --- a/src/kmk/tests/scripts/features/parallelism +++ b/src/kmk/tests/scripts/features/parallelism @@ -43,7 +43,7 @@ all: 1 2; \@echo success "-j4", "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n"); -unlink('1.inc', '2.inc'); +rmfiles(qw(1.inc 2.inc)); # Test parallelism with included files--this time recurse first and make @@ -62,7 +62,7 @@ endif "-j4", "ONE.inc\nTHREE.inc\nTWO.inc\nONE\nTHREE\nTWO\nsuccess\n"); -unlink('1.inc', '2.inc'); +rmfiles(qw(1.inc 2.inc)); # Grant Taylor reports a problem where tokens can be lost (not written back # to the pipe when they should be): this happened when there is a $(shell ...) @@ -152,8 +152,83 @@ intermed: | phony ; touch $@ .PHONY: phony phony: ; : phony', '-rR -j', ': phony'); -unlink('target'); +rmfiles('target'); + +# TEST #10: Don't put --jobserver-fds into a re-exec'd MAKEFLAGS. +# We can't test this directly because there's no way a makefile can +# show the value of MAKEFLAGS we were re-exec'd with. We can intuit it +# by looking for "disabling jobserver mode" warnings; we should only +# get one from the original invocation and none from the re-exec. +# See Savannah bug #18124 + +run_make_test(q! +-include inc.mk +recur: +# @echo 'MAKEFLAGS = $(MAKEFLAGS)' + @rm -f inc.mk + @$(MAKE) -j2 -f #MAKEFILE# all +all: +# @echo 'MAKEFLAGS = $(MAKEFLAGS)' + @echo $@ +inc.mk: +# @echo 'MAKEFLAGS = $(MAKEFLAGS)' + @echo 'FOO = bar' > $@ +!, + '--no-print-directory -j2', "#MAKE#[1]: warning: -jN forced in submake: disabling jobserver mode.\nall\n"); + +rmfiles('inc.mk'); + +if ($all_tests) { + # Implicit files aren't properly recreated during parallel builds + # Savannah bug #26864 + + # The first run works fine + run_make_test(q! +%.bar: %.x foo.y ; cat $^ > $@ +%.x: ; touch $@ +foo.y: foo.y.in ; cp $< $@ +foo.y.in: ; touch $@ +!, + '-j2 main.bar', + "touch foo.y.in +touch main.x +cp foo.y.in foo.y +cat main.x foo.y > main.bar +rm main.x"); + + # Now we touch the .in file and make sure it still works + touch('foo.y.in'); + + run_make_test(undef, '-j2 main.bar', "cp foo.y.in foo.y +touch main.x +cat main.x foo.y > main.bar +rm main.x"); + + # Clean up + rmfiles(qw(foo.y foo.y.in main.bar)); +} + +if ($all_tests) { + # Jobserver FD handling is messed up in some way. + # Savannah bug #28189 + # It doesn't look like that bug anymore but this is the code it runs + run_make_test(q! +ifdef EXTRA +vpath %.dst / +xxx.dst: ; true +yyy.dst: ; true +endif + +M := $(MAKE) +xx: ; $M --no-print-directory -j2 -f $(MAKEFILE_LIST) xxx.dst yyy.dst EXTRA=1 +!, + '-j2', + '#MAKE#[1]: warning: -jN forced in submake: disabling jobserver mode. +true +true +'); +} # Make sure that all jobserver FDs are closed if we need to re-exec the # master copy. @@ -182,12 +257,12 @@ unlink('target'); # '-j2 INCL=false fdprint', # 'bar'); -# unlink('dependfile', 'output'); +# rmfiles(qw(dependfile output)); # # Do it again, this time where the include is done by the non-master make. # run_make_test(undef, '-j2 recurse INCL=false', 'bar'); -# unlink('dependfile', 'output'); +# rmfiles(qw(dependfile output)); 1; diff --git a/src/kmk/tests/scripts/features/patspecific_vars b/src/kmk/tests/scripts/features/patspecific_vars index 196f2f4..8f78ad0 100644 --- a/src/kmk/tests/scripts/features/patspecific_vars +++ b/src/kmk/tests/scripts/features/patspecific_vars @@ -120,5 +120,29 @@ run_make_test(undef, # reuse previous makefile 'normal: global: new $t pattern: good $t inherit: good $t; pattrn: global: new $t pattern: good $t inherit: good $t;'); +# TEST #8: override in pattern-specific variables + +run_make_test(' +a%: override FOO += f1 +a%: FOO += f2 +ab: ; @echo "$(FOO)" +', + '', "f1\n"); + +run_make_test(undef, 'FOO=C', "C f1\n"); + +# TEST #9: Test shortest stem selection in pattern-specific variables. + +run_make_test(' +%-mt.x: x := two +%.x: x := one + +all: foo.x foo-mt.x + +foo.x: ;@echo $x +foo-mt.x: ;@echo $x +', +'', +"one\ntwo"); 1; diff --git a/src/kmk/tests/scripts/features/patternrules b/src/kmk/tests/scripts/features/patternrules index 44355dc..e123954 100644 --- a/src/kmk/tests/scripts/features/patternrules +++ b/src/kmk/tests/scripts/features/patternrules @@ -15,11 +15,13 @@ $dir =~ s,.*/([^/]+)$,../$1,; # to match properly. # -run_make_test(' +run_make_test(q! .PHONY: all all: case.1 case.2 case.3 -a: void + +# We can't have this, due to "Implicit Rule Search Algorithm" step 5c +#xxx: void # 1 - existing file %.1: void @@ -41,9 +43,7 @@ a: void @exit 0 3.implicit-phony: -', -'', -''); +!, '', ''); # TEST #1: make sure files that are built via implicit rules are marked # as targets (Savannah bug #12202). @@ -149,5 +149,80 @@ echo foo.c foo.h >foo.o'); unlink('foo.in', 'foo.h', 'foo.c', 'foo.o'); +# TEST #5: make sure both prefix and suffix patterns work with multiple +# target patterns (Savannah bug #26593). +# +run_make_test(' +all: foo.s1 foo.s2 p1.foo p2.foo + +p1.% p2.%: %.orig + @echo $@ +%.s1 %.s2: %.orig + @echo $@ + +.PHONY: foo.orig +', + '', "foo.s1\np1.foo\n"); + +# TEST 6: Make sure that non-target files are still eligible to be created +# as part of implicit rule chaining. Savannah bug #17752. + +run_make_test(q! +BIN = xyz +COPY = $(BIN).cp +SRC = $(BIN).c +allbroken: $(COPY) $(BIN) ; @echo ok +$(SRC): ; @echo 'main(){}' > $@ +%.cp: % ; @cp $< $@ +% : %.c ; @cp $< $@ +clean: ; @rm -rf $(SRC) $(COPY) $(BIN) +!, + '', "ok\n"); + +unlink(qw(xyz xyz.cp xyz.c)); + +# TEST 7: Make sure that all prereqs of all "also_make" targets get created +# before any of the things that depend on any of them. Savannah bug #19108. + +run_make_test(q! +final: x ; @echo $@ +x: x.t1 x.t2 ; @echo $@ +x.t2: dep +dep: ; @echo $@ +%.t1 %.t2: ; @echo $*.t1 ; echo $*.t2 +!, + '', "dep\nx.t1\nx.t2\nx\nfinal\n"); + + +# TEST 8: Verify we can remove pattern rules. Savannah bug #18622. + +my @f = (qw(foo.w foo.ch)); +touch(@f); + +run_make_test(q! +CWEAVE := : + +# Disable builtin rules +%.tex : %.w +%.tex : %.w %.ch +!, + 'foo.tex', + "#MAKE#: *** No rule to make target `foo.tex'. Stop.", 512); + +unlink(@f); + +# TEST #9: Test shortest stem selection in pattern rules. + +run_make_test(' +%.x: ;@echo one +%-mt.x: ;@echo two + +all: foo.x foo-mt.x +', +'', +"one\ntwo"); + +1; + # This tells the test driver that the perl test script executed properly. 1; diff --git a/src/kmk/tests/scripts/features/recursion b/src/kmk/tests/scripts/features/recursion index bc50e0b..f9c0755 100644 --- a/src/kmk/tests/scripts/features/recursion +++ b/src/kmk/tests/scripts/features/recursion @@ -16,7 +16,7 @@ last: @echo MAKELEVEL = $('. (!$is_kmk ? 'MAKELEVEL' : 'KMK_LEVEL') .') @echo THE END ', - ('CFLAGS=-O -w' . ($parallel_jobs ? '-j 2' : '')), + ('CFLAGS=-O -w' . ($parallel_jobs ? ' -j 2' : '')), ($vos ? "#MAKE#: Entering directory `#PWD#' make 'CFLAGS=-O' -f #MAKEFILE# foo diff --git a/src/kmk/tests/scripts/features/se_explicit b/src/kmk/tests/scripts/features/se_explicit index d80b947..325d57c 100644 --- a/src/kmk/tests/scripts/features/se_explicit +++ b/src/kmk/tests/scripts/features/se_explicit @@ -26,9 +26,9 @@ run_make_test(undef, 'SE=1', "three\nfour\nbariz\nfoo\$bar : baraz bariz"); # TEST #1: automatic variables. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: -.DEFAULT: ; @echo $@ +.DEFAULT: ; @echo '$@' foo: bar baz @@ -41,7 +41,7 @@ foo: $$@.1 \ $$|.5 \ $$*.6 -', +!, '-j1', 'bar baz @@ -62,17 +62,16 @@ buz.5 # Test #2: target/pattern -specific variables. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: -.DEFAULT: ; @echo $@ +.DEFAULT: ; @echo '$@' foo.x: $$a $$b foo.x: a := bar %.x: b := baz - -', +!, '', 'bar baz @@ -81,39 +80,27 @@ baz # Test #3: order of prerequisites. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: -.DEFAULT: ; @echo $@ +.DEFAULT: ; @echo '$@' all: foo bar baz # Subtest #1 -# foo: foo.1; @: - foo: foo.2 - foo: foo.3 - # Subtest #2 -# bar: bar.2 - bar: bar.1; @: - bar: bar.3 - # Subtest #3 -# baz: baz.1 - baz: baz.2 - baz: ; @: - -', +!, '-j1', 'foo.1 foo.2 @@ -125,5 +112,47 @@ baz.1 baz.2 '); +# TEST #4: eval in a context where there is no reading_file +run_make_test(q! +.SECONDEXPANSION: +all : $$(eval $$(info test)) +!, + '', "test\n#MAKE#: Nothing to be done for `all'.\n"); + +# TEST #5: (NEGATIVE) catch eval in a prereq list trying to create new +# target/prereq relationships. + +run_make_test(q! +.SECONDEXPANSION: +proj1.exe : proj1.o $$(eval $$(test)) +define test +proj1.o : proj1.c +proj1.c: proj1.h +endef +!, + '', "#MAKE#: *** prerequisites cannot be defined in recipes. Stop.\n", 512); + + +# Automatic $$+ variable expansion issue. Savannah bug #25780 +run_make_test(q! +all : foo foo +.SECONDEXPANSION: +all : $$+ ; @echo '$+' +foo : ; +!, + '', "foo foo foo foo\n"); + + +# Automatic $$+ variable expansion issue. Savannah bug #25780 +run_make_test(q! +all : bar bar +bar : ; +q%x : ; +.SECONDEXPANSION: +a%l: q1x $$+ q2x ; @echo '$+' +!, + '', "q1x bar bar q2x bar bar\n"); + + # This tells the test driver that the perl test script executed properly. 1; diff --git a/src/kmk/tests/scripts/features/se_implicit b/src/kmk/tests/scripts/features/se_implicit index 8ab3c84..6dbe227 100644 --- a/src/kmk/tests/scripts/features/se_implicit +++ b/src/kmk/tests/scripts/features/se_implicit @@ -11,9 +11,9 @@ $dir =~ s,.*/([^/]+)$,../$1,; # Test #1: automatic variables. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: -.DEFAULT: ; @echo $@ +.DEFAULT: ; @echo '$@' foo.a: bar baz @@ -37,9 +37,9 @@ foo.%: 1.$$@ \ 4.biz \ 5.buz \ 6.a: - @echo $@ + @echo '$@' -', +!, '-j1', '1.foo.a 2.bar @@ -60,7 +60,7 @@ buz # Test #2: target/pattern -specific variables. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: foo.x: @@ -71,20 +71,16 @@ foo.x: x_a := bar %.x: x_b := baz -bar baz: ; @echo $@ - -', -'', -'bar -baz -'); +bar baz: ; @echo '$@' +!, + '', "bar\nbaz\n"); # Test #3: order of prerequisites. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: -.DEFAULT: ; @echo $@ +.DEFAULT: ; @echo '$@' all: foo bar baz @@ -97,7 +93,7 @@ foo: foo.2 foo: foo.3 -foo.1: ; @echo $@ +foo.1: ; @echo '$@' # Subtest #2 @@ -108,7 +104,7 @@ bar: bar.2 bar: bar.3 -bar.1: ; @echo $@ +bar.1: ; @echo '$@' # Subtest #3 @@ -118,9 +114,8 @@ baz: baz.1 baz: baz.2 %az: ; @: - -', -'-j1', +!, + '-j1', 'foo.1 foo.2 foo.3 @@ -134,20 +129,18 @@ baz.2 # Test #4: stem splitting logic. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: $(dir)/tmp/bar.o: -$(dir)/tmp/foo/bar.c: ; @echo $@ -$(dir)/tmp/bar/bar.c: ; @echo $@ -foo.h: ; @echo $@ +$(dir)/tmp/foo/bar.c: ; @echo '$@' +$(dir)/tmp/bar/bar.c: ; @echo '$@' +foo.h: ; @echo '$@' %.o: $$(addsuffix /%.c,foo bar) foo.h - @echo $@: {$<} $^ - -', -"dir=$dir", -"$dir/tmp/foo/bar.c + @echo '$@: {$<} $^' +!, + "dir=$dir", "$dir/tmp/foo/bar.c $dir/tmp/bar/bar.c foo.h $dir/tmp/bar.o: {$dir/tmp/foo/bar.c} $dir/tmp/foo/bar.c $dir/tmp/bar/bar.c foo.h @@ -156,18 +149,17 @@ $dir/tmp/bar.o: {$dir/tmp/foo/bar.c} $dir/tmp/foo/bar.c $dir/tmp/bar/bar.c foo.h # Test #5: stem splitting logic and order-only prerequisites. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: $(dir)/tmp/foo.o: $(dir)/tmp/foo.c -$(dir)/tmp/foo.c: ; @echo $@ -bar.h: ; @echo $@ +$(dir)/tmp/foo.c: ; @echo '$@' +bar.h: ; @echo '$@' %.o: %.c|bar.h - @echo $@: {$<} {$|} $^ + @echo '$@: {$<} {$|} $^' -', -"dir=$dir", -"$dir/tmp/foo.c +!, + "dir=$dir", "$dir/tmp/foo.c bar.h $dir/tmp/foo.o: {$dir/tmp/foo.c} {bar.h} $dir/tmp/foo.c "); @@ -175,58 +167,60 @@ $dir/tmp/foo.o: {$dir/tmp/foo.c} {bar.h} $dir/tmp/foo.c # Test #6: lack of implicit prerequisites. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: foo.o: foo.c -foo.c: ; @echo $@ +foo.c: ; @echo '$@' %.o: - @echo $@: {$<} $^ + @echo '$@: {$<} $^' +!, + '', "foo.c\nfoo.o: {foo.c} foo.c\n"); -', -'', -'foo.c -foo.o: {foo.c} foo.c -'); # Test #7: Test stem from the middle of the name. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: foobarbaz: foo%baz: % $$*.1 - @echo $* + @echo '$*' bar bar.1: - @echo $@ + @echo '$@' +!, + '', "bar\nbar.1\nbar\n"); -', -'', -'bar -bar.1 -bar -'); # Test #8: Make sure stem triple-expansion does not happen. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: foo$$bar: f%r: % $$*.1 - @echo \'$*\' + @echo '$*' oo$$ba oo$$ba.1: - @echo \'$@\' - -', -'', -'oo$ba + @echo '$@' +!, + '', 'oo$ba oo$ba.1 oo$ba '); +# Test #9: Check the value of $^ +run_make_test(q! +.SECONDEXPANSION: + +%.so: | $$(extra) ; @echo $^ + +foo.so: extra := foo.o +foo.so: +foo.o: +!, + '', "\n"); # This tells the test driver that the perl test script executed properly. 1; diff --git a/src/kmk/tests/scripts/features/se_statpat b/src/kmk/tests/scripts/features/se_statpat index 731b00b..828afa2 100644 --- a/src/kmk/tests/scripts/features/se_statpat +++ b/src/kmk/tests/scripts/features/se_statpat @@ -5,12 +5,12 @@ $details = ""; # Test #1: automatic variables. # -run_make_test(' +# bird: Had to add -j1 here earlier... +run_make_test(q! .SECONDEXPANSION: -.DEFAULT: ; @echo $@ +.DEFAULT: ; @echo '$@' foo.a foo.b: foo.%: bar.% baz.% - foo.a foo.b: foo.%: biz.% | buz.% foo.a foo.b: foo.%: $$@.1 \ @@ -19,10 +19,8 @@ foo.a foo.b: foo.%: $$@.1 \ $$(addsuffix .4,$$+) \ $$|.5 \ $$*.6 - -', -'-j1', -'bar.a +!, + '', 'bar.a baz.a biz.a buz.a @@ -41,61 +39,46 @@ a.6 # Test #2: target/pattern -specific variables. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: -.DEFAULT: ; @echo $@ +.DEFAULT: ; @echo '$@' foo.x foo.y: foo.%: $$(%_a) $$($$*_b) foo.x: x_a := bar %.x: x_b := baz - - -', -'', -'bar -baz -'); +!, + '', "bar\nbaz\n"); # Test #3: order of prerequisites. # -run_make_test(' +# bird: Had to add -j1 here earlier... +run_make_test(q! .SECONDEXPANSION: -.DEFAULT: ; @echo $@ +.DEFAULT: ; @echo '$@' all: foo.a bar.a baz.a # Subtest #1 -# foo.a foo.b: foo.%: foo.%.1; @: - foo.a foo.b: foo.%: foo.%.2 - foo.a foo.b: foo.%: foo.%.3 # Subtest #2 -# bar.a bar.b: bar.%: bar.%.2 - bar.a bar.b: bar.%: bar.%.1; @: - bar.a bar.b: bar.%: bar.%.3 # Subtest #3 -# baz.a baz.b: baz.%: baz.%.1 - baz.a baz.b: baz.%: baz.%.2 - baz.a baz.b: ; @: - -', -'-j1', -'foo.a.1 +!, + '', 'foo.a.1 foo.a.2 foo.a.3 bar.a.1 @@ -108,17 +91,15 @@ baz.a.2 # Test #4: Make sure stem triple-expansion does not happen. # -run_make_test(' +run_make_test(q! .SECONDEXPANSION: foo$$bar: f%r: % $$*.1 - @echo \'$*\' + @echo '$*' oo$$ba oo$$ba.1: - @echo \'$@\' - -', -'', -'oo$ba + @echo '$@' +!, + '', 'oo$ba oo$ba.1 oo$ba '); diff --git a/src/kmk/tests/scripts/features/targetvars b/src/kmk/tests/scripts/features/targetvars index fa365a2..ddd6c1f 100644 --- a/src/kmk/tests/scripts/features/targetvars +++ b/src/kmk/tests/scripts/features/targetvars @@ -6,9 +6,7 @@ Create a makefile containing various flavors of target-specific variable values, override and non-override, and using various variable expansion rules, semicolon interference, etc."; -open(MAKEFILE,"> $makefile"); - -print MAKEFILE <<'EOF'; +run_make_test(' SHELL = /bin/sh export FOO = foo export BAR = bar @@ -17,17 +15,17 @@ one two: ; @echo $(FOO) $(BAR) two: BAR = two three: ; BAR=1000 @echo $(FOO) $(BAR) -# Some things that shouldn't be target vars +# Some things that shouldn not be target vars funk : override funk : override adelic adelic override : ; echo $@ # Test per-target recursive variables four:FOO=x four:VAR$(FOO)=ok -four: ; @echo '$(FOO) $(VAR$(FOO)) $(VAR) $(VARx)' +four: ; @echo "$(FOO) $(VAR$(FOO)) $(VAR) $(VARx)" five:FOO=x five six : VAR$(FOO)=good -five six: ;@echo '$(FOO) $(VAR$(FOO)) $(VAR) $(VARx) $(VARfoo)' +five six: ;@echo "$(FOO) $(VAR$(FOO)) $(VAR) $(VARx) $(VARfoo)" # Test per-target variable inheritance seven: eight seven eight: ; @echo $@: $(FOO) $(BAR) @@ -41,8 +39,8 @@ nine-a: export BAZ = baz nine-a: ; @echo $$BAZ # Test = escaping EQ = = -ten: one\=two -ten: one \= two +ten: one$(EQ)two +ten: one $(EQ) two ten one$(EQ)two $(EQ):;@echo $@ .PHONY: one two three four five six seven eight nine ten $(EQ) one$(EQ)two # Test target-specific vars with pattern/suffix rules @@ -54,92 +52,58 @@ foo.q : RVAR += rvar %.r %.s %.t: ; @echo $(QVAR) $(RVAR) $(SVAR) $(TVAR) foo.r : RVAR += rvar foo.t : TVAR := $(QVAR) -EOF - -close(MAKEFILE); - -# TEST #1 - -&run_make_with_options($makefile, "-j1 one two three", &get_logfile); -$answer = "one bar\nfoo two\nBAR=1000\nfoo bar\n"; -&compare_output($answer,&get_logfile(1)); +', + "one two three", "one bar\nfoo two\nBAR=1000\nfoo bar\n"); # TEST #2 -&run_make_with_options($makefile, "-j1 one two FOO=1 BAR=2", &get_logfile); -$answer = "one 2\n1 2\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, "one two FOO=1 BAR=2", "one 2\n1 2\n"); # TEST #3 -&run_make_with_options($makefile, "-j1 four", &get_logfile); -$answer = "x ok ok\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, "four", "x ok ok\n"); # TEST #4 -&run_make_with_options($makefile, "-j1 seven", &get_logfile); -$answer = "eight: seven eight\nseven: seven seven\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, "seven", "eight: seven eight\nseven: seven seven\n"); # TEST #5 -&run_make_with_options($makefile, "-j1 nine", &get_logfile); -$answer = "wallace bar wallace bar\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, "nine", "wallace bar wallace bar\n"); # TEST #5-a -&run_make_with_options($makefile, "-j1 nine-a", &get_logfile); -$answer = "baz\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, "nine-a", "baz\n"); # TEST #6 -&run_make_with_options($makefile, "-j1 ten", &get_logfile); -$answer = "one=two\none bar\n=\nfoo two\nten\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, "ten", "one=two\none bar\n=\nfoo two\nten\n"); # TEST #6 -&run_make_with_options($makefile, "-j1 foo.q bar.q", &get_logfile); -$answer = "qvar = rvar\nqvar =\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, "foo.q bar.q", "qvar = rvar\nqvar =\n"); # TEST #7 -&run_make_with_options($makefile, "-j1 foo.t bar.s", &get_logfile); -$answer = "qvar = qvar\nqvar =\n"; -&compare_output($answer,&get_logfile(1)); +run_make_test(undef, "foo.t bar.s", "qvar = qvar\nqvar =\n"); # TEST #8 # For PR/1378: Target-specific vars don't inherit correctly -$makefile2 = &get_tmpfile; - -open(MAKEFILE,"> $makefile2"); -print MAKEFILE <<'EOF'; +run_make_test(' foo: FOO = foo bar: BAR = bar foo: bar bar: baz baz: ; @echo $(FOO) $(BAR) -EOF -close(MAKEFILE); - -&run_make_with_options("$makefile2", "", &get_logfile); -$answer = "foo bar\n"; -&compare_output($answer, &get_logfile(1)); +', "", "foo bar\n"); # TEST #9 # For PR/1380: Using += assignment in target-specific variables sometimes fails # Also PR/1831 -$makefile3 = &get_tmpfile; - -open(MAKEFILE,"> $makefile3"); -print MAKEFILE <<'EOF'; +run_make_test(' .PHONY: all one all: FOO += baz all: one; @echo $(FOO) @@ -149,43 +113,27 @@ FOO = bar one: FOO += biz one: FOO += boz one: ; @echo $(FOO) -EOF -close(MAKEFILE); - -&run_make_with_options("$makefile3", "", &get_logfile); -$answer = "bar baz biz boz\nbar baz\n"; -&compare_output($answer, &get_logfile(1)); +', + '', "bar baz biz boz\nbar baz\n"); # Test #10 -&run_make_with_options("$makefile3", "one", &get_logfile); -$answer = "bar biz boz\n"; -&compare_output($answer, &get_logfile(1)); +run_make_test(undef, 'one', "bar biz boz\n"); # Test #11 # PR/1709: Test semicolons in target-specific variable values -$makefile4 = &get_tmpfile; - -open(MAKEFILE, "> $makefile4"); -print MAKEFILE <<'EOF'; +run_make_test(' foo : FOO = ; ok -foo : ; @echo '$(FOO)' -EOF -close(MAKEFILE); - -&run_make_with_options("$makefile4", "", &get_logfile); -$answer = "; ok\n"; -&compare_output($answer, &get_logfile(1)); +foo : ; @echo "$(FOO)" +', + '', "; ok\n"); # Test #12 # PR/2020: More hassles with += target-specific vars. I _really_ think # I nailed it this time :-/. -$makefile5 = &get_tmpfile; - -open(MAKEFILE, "> $makefile5"); -print MAKEFILE <<'EOF'; +run_make_test(' .PHONY: a BLAH := foo @@ -195,20 +143,13 @@ a: ; @$(COMMAND) a: BLAH := bar a: COMMAND += snafu $(BLAH) -EOF -close(MAKEFILE); - -&run_make_with_options("$makefile5", "", &get_logfile); -$answer = "bar snafu bar\n"; -&compare_output($answer, &get_logfile(1)); +', + '', "bar snafu bar\n"); # Test #13 # Test double-colon rules with target-specific variable values -$makefile6 = &get_tmpfile; - -open(MAKEFILE, "> $makefile6"); -print MAKEFILE <<'EOF'; +run_make_test(' W = bad X = bad foo: W = ok @@ -224,48 +165,30 @@ Z = nopat ifdef PATTERN fo% : Z = pat endif - -EOF -close(MAKEFILE); - -&run_make_with_options("$makefile6", "foo", &get_logfile); -$answer = "ok ok foo nopat\nok ok foo nopat\n"; -&compare_output($answer, &get_logfile(1)); +', + 'foo', "ok ok foo nopat\nok ok foo nopat\n"); # Test #14 # Test double-colon rules with target-specific variable values and # inheritance -&run_make_with_options("$makefile6", "bar", &get_logfile); -$answer = "ok ok bar nopat\nok ok bar nopat\n"; -&compare_output($answer, &get_logfile(1)); +run_make_test(undef, 'bar', "ok ok bar nopat\nok ok bar nopat\n"); # Test #15 # Test double-colon rules with pattern-specific variable values -&run_make_with_options("$makefile6", "foo PATTERN=yes", &get_logfile); -$answer = "ok ok foo pat\nok ok foo pat\n"; -&compare_output($answer, &get_logfile(1)); - +run_make_test(undef, 'foo PATTERN=yes', "ok ok foo pat\nok ok foo pat\n"); # Test #16 # Test target-specific variables with very long command line # (> make default buffer length) -$makefile7 = &get_tmpfile; - -open(MAKEFILE, "> $makefile7"); -print MAKEFILE <<'EOF'; +run_make_test(' base_metals_fmd_reports.sun5 base_metals_fmd_reports CreateRealPositions CreateMarginFunds deals_changed_since : BUILD_OBJ=$(shell if [ -f "build_information.generate" ]; then echo "$(OBJ_DIR)/build_information.o"; else echo "no build information"; fi ) deals_changed_since: ; @echo $(BUILD_OBJ) - -EOF -close(MAKEFILE); - -&run_make_with_options("$makefile7", '', &get_logfile); -$answer = "no build information\n"; -&compare_output($answer, &get_logfile(1)); +', + '', "no build information\n"); # TEST #17 @@ -286,8 +209,7 @@ foo.x: FOOVAR = bar rules.mk : MYVAR = foo .INTERMEDIATE: foo.x rules.mk ', - '-I t1', - 'MYVAR= FOOVAR=bar ALLVAR=xxx'); + '-I t1', 'MYVAR= FOOVAR=bar ALLVAR=xxx'); rmfiles('t1/rules.mk'); rmdir('t1'); @@ -297,11 +219,45 @@ rmdir('t1'); # Test appending to a simple variable containing a "$": avoid a # double-expansion. See Savannah bug #15913. -run_make_test(" -VAR := \$\$FOO +run_make_test(' +VAR := $$FOO foo: VAR += BAR -foo: ; \@echo '\$(VAR)'", - '', - '$FOO BAR'); +foo: ; @echo '."'".'$(VAR)'."'".' +', + '', '$FOO BAR'); + +# TEST #19: Override with append variables + +run_make_test(' +a: override FOO += f1 +a: FOO += f2 +a: ; @echo "$(FOO)" +', + '', "f1\n"); + +run_make_test(undef, 'FOO=C', "C f1\n"); + +# TEST #20: Check for continuation after semicolons + +run_make_test(q! +a: A = 'hello; \ +world' +a: ; @echo $(A) +!, + '', "hello; world\n"); + +# TEST #19: Test define/endef variables as target-specific vars + +# run_make_test(' +# define b +# @echo global +# endef +# a: define b +# @echo local +# endef + +# a: ; $(b) +# ', +# '', "local\n"); 1; diff --git a/src/kmk/tests/scripts/features/vpath b/src/kmk/tests/scripts/features/vpath index 6634c90..ced58f8 100644 --- a/src/kmk/tests/scripts/features/vpath +++ b/src/kmk/tests/scripts/features/vpath @@ -1,3 +1,5 @@ +# -*-perl-*- + $description = "The following test creates a makefile to test the \n" ."vpath directive which allows you to specify a search \n" ."path for a particular class of filenames, those that\n" @@ -60,4 +62,21 @@ if (&compare_output($answer,&get_logfile(1))) unlink @files_to_touch; } +# TEST 2: after vpath lookup ensure we don't get incorrect circular dependency +# warnings due to change of struct file ptr. Savannah bug #13529. + +mkdir('vpath-d', 0777); + +run_make_test(q! +vpath %.te vpath-d/ +.SECONDARY: +default: vpath-d/a vpath-d/b +vpath-d/a: fail.te +vpath-d/b : fail.te +vpath-d/fail.te: +!, + '', "#MAKE#: Nothing to be done for `default'.\n"); + +rmdir('vpath-d'); + 1; diff --git a/src/kmk/tests/scripts/features/vpath3 b/src/kmk/tests/scripts/features/vpath3 new file mode 100644 index 0000000..978c5ee --- /dev/null +++ b/src/kmk/tests/scripts/features/vpath3 @@ -0,0 +1,50 @@ +# -*-perl-*- + +$description = "Test the interaction of the -lfoo feature and vpath"; +$details = ""; + +open(MAKEFILE,"> $makefile"); + +# The Contents of the MAKEFILE ... + +print MAKEFILE "vpath %.a a1\n"; +print MAKEFILE "vpath %.so b1\n"; +print MAKEFILE "vpath % a2 b2\n"; +print MAKEFILE "vpath % b3\n"; +print MAKEFILE "all: -l1 -l2 -l3; \@echo \$^\n"; + +# END of Contents of MAKEFILE + +close(MAKEFILE); + +mkdir("a1", 0777); +mkdir("b1", 0777); +mkdir("a2", 0777); +mkdir("b2", 0777); +mkdir("b3", 0777); + +@files_to_touch = ("a1${pathsep}lib1.a", + "b1${pathsep}lib1.so", + "a2${pathsep}lib2.a", + "b2${pathsep}lib2.so", + "lib3.a", + "b3${pathsep}lib3.so"); + +&touch(@files_to_touch); + +&run_make_with_options($makefile,"",&get_logfile); + +# Create the answer to what should be produced by this Makefile +$answer = "a1${pathsep}lib1.a a2${pathsep}lib2.a lib3.a\n"; + +if (&compare_output($answer,&get_logfile(1))) +{ + unlink @files_to_touch; + rmdir("a1"); + rmdir("b1"); + rmdir("a2"); + rmdir("b2"); + rmdir("b3"); +} + +1; diff --git a/src/kmk/tests/scripts/functions/shell b/src/kmk/tests/scripts/functions/shell index ecea4cf..723cd0e 100644 --- a/src/kmk/tests/scripts/functions/shell +++ b/src/kmk/tests/scripts/functions/shell @@ -11,6 +11,15 @@ all: ; @echo $(shell echo hi) ','','hi'); +# Test unescaped comment characters in shells. Savannah bug #20513 +if ($all_tests) { + run_make_test(q! +FOO := $(shell echo '#') +foo: ; echo '$(FOO)' +!, + '', "#\n"); +} + # Test shells inside exported environment variables. # This is the test that fails if we try to put make exported variables into # the environment for a $(shell ...) call. diff --git a/src/kmk/tests/scripts/functions/wildcard b/src/kmk/tests/scripts/functions/wildcard index d61384e..2841f5d 100644 --- a/src/kmk/tests/scripts/functions/wildcard +++ b/src/kmk/tests/scripts/functions/wildcard @@ -81,14 +81,11 @@ if ((-f "example.1")||(-f "example.two")||(-f "example.3")||(-f "example.for")) &compare_output($answer,&get_logfile(1)); +# TEST #4: Verify that failed wildcards don't return the pattern -1; - - - - - - - - +run_make_test(q! +all: ; @echo $(wildcard xz--y*.7) +!, + '', "\n"); +1; diff --git a/src/kmk/tests/scripts/misc/general4 b/src/kmk/tests/scripts/misc/general4 index b86b16b..dd9475c 100644 --- a/src/kmk/tests/scripts/misc/general4 +++ b/src/kmk/tests/scripts/misc/general4 @@ -31,20 +31,6 @@ cc foo.o -o foo' : unlink('foo.c'); -# Test other implicit rule searching - -&touch('bar'); -run_make_test(' -test.foo: -%.foo : baz ; @echo done $< -%.foo : bar ; @echo done $< -fox: baz -', - '', - 'done bar'); -unlink('bar'); - - # Test implicit rules with '$' in the name (see se_implicit) run_make_test(q! @@ -83,4 +69,17 @@ dir/subdir/%.$$a: dir/subdir/%.$$b ; @echo 'cp $< $@' !, '', "mkdir -p dir/subdir\ntouch dir/subdir/file.\$b\ncp dir/subdir/file.\$b dir/subdir/file.\$a\n"); +# Test odd whitespace at the beginning of a line + +run_make_test(" +all: + \f + + \\ + \f \\ + \013 \\ +all: ; \@echo hi +", + '', "hi\n"); + 1; diff --git a/src/kmk/tests/scripts/options/dash-B b/src/kmk/tests/scripts/options/dash-B index 864a01f..e36842e 100644 --- a/src/kmk/tests/scripts/options/dash-B +++ b/src/kmk/tests/scripts/options/dash-B @@ -70,4 +70,16 @@ all'); rmfiles('foo.x', 'blah.x'); +# Test that $? is set properly with -B; all prerequisites will be newer! + +utouch(-10, 'x.b'); +touch('x.a'); + +run_make_test(q! +x.a: x.b ; @echo $? +!, + '-B', "x.b\n"); + +unlink(qw(x.a x.b)); + 1; diff --git a/src/kmk/tests/scripts/options/eval b/src/kmk/tests/scripts/options/eval new file mode 100644 index 0000000..06a035c --- /dev/null +++ b/src/kmk/tests/scripts/options/eval @@ -0,0 +1,19 @@ +# -*-perl-*- + +$description = "Test the --eval option."; + +$details = "Verify that --eval options take effect, +and are passed to sub-makes."; + +# Verify that --eval is evaluated first +run_make_test(q! +BAR = bar +all: ; @echo all +recurse: ; @$(MAKE) -f #MAKEFILE# && echo recurse!, + '--eval=\$\(info\ eval\) FOO=\$\(BAR\)', "eval\nall"); + +# Make sure that --eval is handled correctly during recursion +run_make_test(undef, '--no-print-directory --eval=\$\(info\ eval\) recurse', + "eval\neval\nall\nrecurse"); + +1; diff --git a/src/kmk/tests/scripts/targets/ONESHELL b/src/kmk/tests/scripts/targets/ONESHELL new file mode 100644 index 0000000..997423f --- /dev/null +++ b/src/kmk/tests/scripts/targets/ONESHELL @@ -0,0 +1,69 @@ +# -*-perl-*- + +$description = "Test the behaviour of the .ONESHELL target."; + +$details = ""; + + +# Simple + +run_make_test(q! +.ONESHELL: +all: + a=$$$$ + [ 0"$$a" -eq "$$$$" ] || echo fail +!, + '', 'a=$$ +[ 0"$a" -eq "$$" ] || echo fail +'); + +# Again, but this time with inner prefix chars + +run_make_test(q! +.ONESHELL: +all: + a=$$$$ + @-+ [ 0"$$a" -eq "$$$$" ] || echo fail +!, + '', 'a=$$ +[ 0"$a" -eq "$$" ] || echo fail +'); + +# This time with outer prefix chars + +run_make_test(q! +.ONESHELL: +all: + @a=$$$$ + [ 0"$$a" -eq "$$$$" ] || echo fail +!, + '', ''); + + +# This time with outer and inner prefix chars + +run_make_test(q! +.ONESHELL: +all: + @a=$$$$ + -@ +[ 0"$$a" -eq "$$$$" ] || echo fail +!, + '', ''); + + +# Now try using a different interpreter + +run_make_test(q! +.RECIPEPREFIX = > +.ONESHELL: +SHELL = #PERL# +.SHELLFLAGS = -e +all: +> @$$a=5 +> +7; +> @y=qw(a b c); +>print "a = $$a, y = (@y)\n"; +!, + '', "a = 12, y = (a b c)\n"); + +1; diff --git a/src/kmk/tests/scripts/targets/POSIX b/src/kmk/tests/scripts/targets/POSIX new file mode 100644 index 0000000..9c30e18 --- /dev/null +++ b/src/kmk/tests/scripts/targets/POSIX @@ -0,0 +1,33 @@ +# -*-perl-*- + +$description = "Test the behaviour of the .PHONY target."; + +$details = ""; + + +# Ensure turning on .POSIX enables the -e flag for the shell +# We can't assume the exit value of "false" because on different systems it's +# different. + +my $script = 'false; true'; +my $flags = '-ec'; +my $out = `/bin/sh $flags '$script' 2>&1`; +my $err = $? >> 8; +run_make_test(qq! +.POSIX: +all: ; \@$script +!, + '', "#MAKE#: *** [all] Error $err\n", 512); + +# User settings must override .POSIX +$flags = '-xc'; +$out = `/bin/sh $flags '$script' 2>&1`; +run_make_test(qq! +.SHELLFLAGS = $flags +.POSIX: +all: ; \@$script +!, + '', $out); + +# This tells the test driver that the perl test script executed properly. +1; diff --git a/src/kmk/tests/scripts/variables/DEFAULT_GOAL b/src/kmk/tests/scripts/variables/DEFAULT_GOAL index 897bd4a..1c06506 100644 --- a/src/kmk/tests/scripts/variables/DEFAULT_GOAL +++ b/src/kmk/tests/scripts/variables/DEFAULT_GOAL @@ -73,6 +73,15 @@ $(call make-rule) '', 'foo'); +# TEST #5: .DEFAULT_GOAL containing just whitespace (Savannah bug #25697) + +run_make_test(' +N = +.DEFAULT_GOAL = $N $N # Just whitespace + +foo: ; @echo "boo" +', + '', "#MAKE#: *** No targets. Stop.\n", 512); # This tells the test driver that the perl test script executed properly. 1; diff --git a/src/kmk/tests/scripts/variables/LIBPATTERNS b/src/kmk/tests/scripts/variables/LIBPATTERNS new file mode 100644 index 0000000..826f2fa --- /dev/null +++ b/src/kmk/tests/scripts/variables/LIBPATTERNS @@ -0,0 +1,38 @@ +# -*-perl-*- + +$description = "Test .LIBPATTERNS special variable."; + +$details = ""; + +# TEST 0: basics + +touch('mtest_foo.a'); + +run_make_test(' +.LIBPATTERNS = mtest_%.a +all: -lfoo ; @echo "build $@ from $<" +', + '', "build all from mtest_foo.a\n"); + +# TEST 1: Handle elements that are not patterns. + +run_make_test(' +.LIBPATTERNS = mtest_foo.a mtest_%.a +all: -lfoo ; @echo "build $@ from $<" +', + '', "#MAKE#: .LIBPATTERNS element `mtest_foo.a' is not a pattern +build all from mtest_foo.a\n"); + +# TEST 2: target-specific override + +# Uncomment this when we add support, see Savannah bug #25703 +# run_make_test(' +# .LIBPATTERNS = mbad_%.a +# all: .LIBPATTERNS += mtest_%.a +# all: -lfoo ; @echo "build $@ from $<" +# ', +# '', "build all from mtest_foo.a\n"); + +unlink('mtest_foo.a'); + +1; diff --git a/src/kmk/tests/scripts/variables/MAKE b/src/kmk/tests/scripts/variables/MAKE index 079c57e..d1081da 100644 --- a/src/kmk/tests/scripts/variables/MAKE +++ b/src/kmk/tests/scripts/variables/MAKE @@ -1,35 +1,24 @@ # -*-perl-*- -$description = "The following test creates a makefile to test MAKE \n" - ."(very generic)"; +$description = "Test proper behavior of the MAKE variable"; $details = "DETAILS"; -open(MAKEFILE,"> $makefile"); - -# The Contents of the MAKEFILE ... - -print MAKEFILE "TMP := \$(MAKE)\n"; -print MAKEFILE "MAKE := \$(subst X=\$(X),,\$(MAKE))\n\n"; -print MAKEFILE "all:\n"; -print MAKEFILE "\t\@echo \$(TMP)\n"; -print MAKEFILE "\t\$(MAKE) -f $makefile foo\n\n"; -print MAKEFILE "foo:\n"; -print MAKEFILE "\t\@echo \$(MAKE)\n"; - -# END of Contents of MAKEFILE - -close(MAKEFILE); - -# Create the answer to what should be produced by this Makefile -$answer = "$mkpath\n$mkpath -f $makefile foo\n" - . "${make_name}[1]: Entering directory `$pwd'\n" - . "$mkpath\n${make_name}[1]: Leaving directory `$pwd'\n"; - -&run_make_with_options($makefile,"",&get_logfile,0); - -&rmfiles("foo"); -# COMPARE RESULTS -&compare_output($answer,&get_logfile(1)); +run_make_test(q! +TMP := $(MAKE) +MAKE := $(subst X=$(X),,$(MAKE)) +all: + @echo $(TMP) + $(MAKE) -f #MAKEFILE# foo + +foo: + @echo $(MAKE) +!, + '', + "#MAKEPATH#\n#MAKEPATH# -f #MAKEFILE# foo\n" + . "#MAKE#[1]: Entering directory `#PWD#'\n" + . "#MAKEPATH#\n#MAKE#[1]: Leaving directory `#PWD#'\n"); + +rmfiles("foo"); 1; diff --git a/src/kmk/tests/scripts/variables/MAKEFILES b/src/kmk/tests/scripts/variables/MAKEFILES index 3be284b..b23da8e 100644 --- a/src/kmk/tests/scripts/variables/MAKEFILES +++ b/src/kmk/tests/scripts/variables/MAKEFILES @@ -31,4 +31,23 @@ close(MAKEFILE); $answer = "DEFAULT RULE: M2=m2 M3=m3\n"; &compare_output($answer,&get_logfile(1)); +# TEST 2: Verify that included makefiles don't set the default goal. +# See Savannah bug #13401. + +create_file('xx-inc.mk', ' +include_goal: ; @echo $@ +include xx-ind.mk +'); + +create_file('xx-ind.mk', ' +indirect_goal: ; @echo $@ +'); + +run_make_test(q! +top: ; @echo $@ +!, + 'MAKEFILES=xx-inc.mk', "top\n"); + +unlink(qw(xx-inc.mk xx-ind.mk)); + 1; diff --git a/src/kmk/tests/scripts/variables/MAKEFLAGS b/src/kmk/tests/scripts/variables/MAKEFLAGS new file mode 100644 index 0000000..0b567e8 --- /dev/null +++ b/src/kmk/tests/scripts/variables/MAKEFLAGS @@ -0,0 +1,43 @@ +# -*-perl-*- + +$description = "Test proper behavior of MAKEFLAGS"; + +$details = "DETAILS"; + +# Normal flags aren't prefixed with "-" +run_make_test(q! +all: ; @echo $(MAKEFLAGS) +!, + '-e -r -R', 'Rre'); + +# Long arguments mean everything is prefixed with "-" +run_make_test(q! +all: ; @echo $(MAKEFLAGS) +!, + '--no-print-directory -e -r -R', '--no-print-directory -Rre'); + + +if ($all_tests) { + # Recursive invocations of make should accumulate MAKEFLAGS values. + # Savannah bug #2216 + run_make_test(q! +MSG = Fails +all: + @echo '$@: MAKEFLAGS=$(MAKEFLAGS)' + @MSG=Works $(MAKE) -e -f #MAKEFILE# jump +jump: + @echo '$@: MAKEFLAGS=$(MAKEFLAGS)' + @$(MAKE) -f #MAKEFILE# print +print: + @echo '$@: MAKEFLAGS=$(MAKEFLAGS)' + @echo $(MSG) +.PHONY: all jump print +!, + '--no-print-directory', + 'all: MAKEFLAGS= --no-print-directory +jump: MAKEFLAGS= --no-print-directory -e +print: MAKEFLAGS= --no-print-directory -e +Works'); +} + +1; diff --git a/src/kmk/tests/scripts/variables/SHELL b/src/kmk/tests/scripts/variables/SHELL index 005115a..ca8e084 100644 --- a/src/kmk/tests/scripts/variables/SHELL +++ b/src/kmk/tests/scripts/variables/SHELL @@ -49,9 +49,39 @@ all:;@echo "$(SHELL) $$SHELL" $extraENV{SHELL} = $mshell; -# bird: This was wrong, see Savannah bug #24655. Fixed in kBuild. -run_make_test("all: export SHELL := /./$mshell\n".' -all:;@echo "$(SHELL) $$SHELL" -', '', "/./$mshell /./$mshell"); +# bird: This was wrong at some point, see Savannah bug #24655. Was first fixed in kBuild. +run_make_test(" +SHELL := /././$mshell +one: two +two: export SHELL := /./$mshell\n".' +one two:;@echo "$@: $(SHELL) $$SHELL" +', '', "two: /./$mshell /./$mshell\none: /././$mshell $mshell\n"); + +# Test .SHELLFLAGS + +# We don't know the output here: on Solaris for example, every line printed +# by the shell in -x mode has a trailing space (!!) +my $script = 'true; true'; +my $flags = '-xc'; +my $out = `/bin/sh $flags '$script' 2>&1`; + +run_make_test(qq! +.SHELLFLAGS = $flags +all: ; \@$script +!, + '', $out); + +# We can't just use "false" because on different systems it provides a +# different exit code--once again Solaris: false exits with 255 not 1 +$script = 'true; false; true'; +$flags = '-xec'; +$out = `/bin/sh $flags '$script' 2>&1`; +my $err = $? >> 8; + +run_make_test(qq! +.SHELLFLAGS = $flags +all: ; \@$script +!, + '', "$out#MAKE#: *** [all] Error $err\n", 512); 1; diff --git a/src/kmk/tests/scripts/variables/automatic b/src/kmk/tests/scripts/variables/automatic index 62bbcc1..2304fa0 100644 --- a/src/kmk/tests/scripts/variables/automatic +++ b/src/kmk/tests/scripts/variables/automatic @@ -107,4 +107,16 @@ bar: ;', unlink('foo'); +# TEST #4: ensure prereq ordering is correct when the commmand target has none +# See Savannah bug #21198 + +run_make_test(' +all : A B +all : ; @echo $@ -- $^ -- $< +all : C D +all : E F +A B C D E F G H : ; @: +', + '', "all -- A B C D E F -- A\n"); + 1; diff --git a/src/kmk/tests/scripts/variables/define b/src/kmk/tests/scripts/variables/define new file mode 100644 index 0000000..f91519e --- /dev/null +++ b/src/kmk/tests/scripts/variables/define @@ -0,0 +1,234 @@ +# -*-perl-*- + +$description = "Test define/endef variable assignments."; + +$details = ""; + +# TEST 0: old-style basic define/endef + +run_make_test(' +define multi +@echo hi +echo there +endef + +all: ; $(multi) +', + '', "hi\necho there\nthere\n"); + +# TEST 1: Various new-style define/endef + +run_make_test(' +FOO = foo + +define multi = +echo hi +@echo $(FOO) +endef # this is the end + +define simple := +@echo $(FOO) +endef + +append = @echo a + +define append += + +@echo b +endef + +define cond ?= # this is a conditional +@echo first +endef + +define cond ?= +@echo second +endef + +FOO = there + +all: ; $(multi) + $(simple) + $(append) + $(cond) +', + '', "echo hi\nhi\nthere\nfoo\na\nb\nfirst\n"); + +# TEST 2: define in true section of conditional (containing conditional) + +run_make_test(' +FOO = foo +NAME = def +def = +ifdef BOGUS + define $(subst e,e,$(NAME)) = + ifeq (1,1) + FOO = bar + endif + endef +endif + +$(eval $(def)) +all: ; @echo $(FOO) +', + 'BOGUS=1', "bar\n"); + +# TEST 3: define in false section of conditional (containing conditional) + +run_make_test(undef, '', "foo\n"); + +# TEST 4: nested define (supported?) + +run_make_test(' +define outer + define inner + A = B + endef +endef + +$(eval $(outer)) + +outer: ; @echo $(inner) +', + '', "A = B\n"); + +# TEST 5: NEGATIVE: Missing variable name + +run_make_test(' +NAME = +define $(NAME) = +ouch +endef +all: ; @echo ouch +', + '', "#MAKEFILE#:3: *** empty variable name. Stop.\n", 512); + +# TEST 6: NEGATIVE: extra text after define + +run_make_test(' +NAME = +define NAME = $(NAME) +ouch +endef +all: ; @echo ok +', + '', "#MAKEFILE#:3: extraneous text after `define' directive\nok\n"); + +# TEST 7: NEGATIVE: extra text after endef + +run_make_test(' +NAME = +define NAME = +ouch +endef $(NAME) +all: ; @echo ok +', + '', "#MAKEFILE#:5: extraneous text after `endef' directive\nok\n"); + +# TEST 8: NEGATIVE: missing endef + +run_make_test(' +NAME = +all: ; @echo ok +define NAME = +ouch +endef$(NAME) +', + '', "#MAKEFILE#:4: *** missing `endef', unterminated `define'. Stop.\n", 512); + +# ------------------------- +# Make sure that prefix characters apply properly to define/endef values. +# +# There's a bit of oddness here if you try to use a variable to hold the +# prefix character for a define. Even though something like this: +# +# define foo +# echo bar +# endef +# +# all: ; $(V)$(foo) +# +# (where V=@) can be seen by the user to be obviously different than this: +# +# define foo +# $(V)echo bar +# endef +# +# all: ; $(foo) +# +# and the user thinks it should behave the same as when the "@" is literal +# instead of in a variable, that can't happen because by the time make +# expands the variables for the command line and sees it begins with a "@" it +# can't know anymore whether the prefix character came before the variable +# reference or was included in the first line of the variable reference. + +# TEST #5 +# ------- + +run_make_test(' +define FOO +$(V1)echo hello +$(V2)echo world +endef +all: ; @$(FOO) +', '', 'hello +world'); + +# TEST #6 +# ------- + +run_make_test(undef, 'V1=@ V2=@', 'hello +world'); + +# TEST #7 +# ------- + +run_make_test(' +define FOO +$(V1)echo hello +$(V2)echo world +endef +all: ; $(FOO) +', 'V1=@', 'hello +echo world +world'); + +# TEST #8 +# ------- + +run_make_test(undef, 'V2=@', 'echo hello +hello +world'); + +# TEST #9 +# ------- + +run_make_test(undef, 'V1=@ V2=@', 'hello +world'); + +# TEST #10 +# ------- +# Test the basics; a "@" internally to the variable applies to only one line. +# A "@" before the variable applies to the entire variable. + +run_make_test(' +define FOO +@echo hello +echo world +endef +define BAR +echo hello +echo world +endef + +all: foo bar +foo: ; $(FOO) +bar: ; @$(BAR) +', '', 'hello +echo world +world +hello +world +'); + +1; diff --git a/src/kmk/tests/scripts/variables/flavors b/src/kmk/tests/scripts/variables/flavors index 4535898..92feed6 100644 --- a/src/kmk/tests/scripts/variables/flavors +++ b/src/kmk/tests/scripts/variables/flavors @@ -4,180 +4,73 @@ $description = "Test various flavors of make variable setting."; $details = ""; -open(MAKEFILE, "> $makefile"); +# TEST 0: Recursive -# The Contents of the MAKEFILE ... - -print MAKEFILE <<'EOF'; +run_make_test(' +ugh = Goodbye foo = $(bar) bar = ${ugh} ugh = Hello +all: ; @echo $(foo) +', + '', "Hello\n"); -all: multi ; @echo $(foo) - -multi: ; $(multi) - -x := foo -y := $(x) bar -x := later - -nullstring := -space := $(nullstring) $(nullstring) - -next: ; @echo $x$(space)$y - -define multi -@echo hi -echo there -endef - -ifdef BOGUS -define -@echo error -endef -endif - -define outer - define inner - A = B - endef -endef - -$(eval $(outer)) - -outer: ; @echo $(inner) - -EOF - -# END of Contents of MAKEFILE - -close(MAKEFILE); - -# TEST #1 -# ------- - -&run_make_with_options($makefile, "", &get_logfile); -$answer = "hi\necho there\nthere\nHello\n"; -&compare_output($answer, &get_logfile(1)); - -# TEST #2 -# ------- - -&run_make_with_options($makefile, "next", &get_logfile); -$answer = "later foo bar\n"; -&compare_output($answer, &get_logfile(1)); - -# TEST #3 -# ------- - -&run_make_with_options($makefile, "BOGUS=true", &get_logfile, 512); -$answer = "$makefile:24: *** empty variable name. Stop.\n"; -&compare_output($answer, &get_logfile(1)); - -# TEST #4 -# ------- - -&run_make_with_options($makefile, "outer", &get_logfile); -$answer = "A = B\n"; -&compare_output($answer, &get_logfile(1)); - -# Clean up from "old style" testing. If all the above tests are converted to -# run_make_test() syntax than this line can be removed. -$makefile = undef; - -# ------------------------- -# Make sure that prefix characters apply properly to define/endef values. -# -# There's a bit of oddness here if you try to use a variable to hold the -# prefix character for a define. Even though something like this: -# -# define foo -# echo bar -# endef -# -# all: ; $(V)$(foo) -# -# (where V=@) can be seen by the user to be obviously different than this: -# -# define foo -# $(V)echo bar -# endef -# -# all: ; $(foo) -# -# and the user thinks it should behave the same as when the "@" is literal -# instead of in a variable, that can't happen because by the time make -# expands the variables for the command line and sees it begins with a "@" it -# can't know anymore whether the prefix character came before the variable -# reference or was included in the first line of the variable reference. - -# TEST #5 -# ------- +# TEST 1: Simple run_make_test(' -define FOO -$(V1)echo hello -$(V2)echo world -endef -all: ; @$(FOO) -', '', 'hello -world'); - -# TEST #6 -# ------- - -run_make_test(undef, 'V1=@ V2=@', 'hello -world'); +bar = Goodbye +foo := $(bar) +bar = ${ugh} +ugh = Hello +all: ; @echo $(foo) +', + '', "Goodbye\n"); -# TEST #7 -# ------- +# TEST 2: Append to recursive run_make_test(' -define FOO -$(V1)echo hello -$(V2)echo world -endef -all: ; $(FOO) -', 'V1=@', 'hello -echo world -world'); +foo = Hello +ugh = Goodbye +foo += $(bar) +bar = ${ugh} +ugh = Hello +all: ; @echo $(foo) +', + '', "Hello Hello\n"); -# TEST #8 -# ------- +# TEST 3: Append to simple -run_make_test(undef, 'V2=@', 'echo hello -hello -world'); +run_make_test(' +foo := Hello +ugh = Goodbye +bar = ${ugh} +foo += $(bar) +ugh = Hello +all: ; @echo $(foo) +', + '', "Hello Goodbye\n"); -# TEST #9 -# ------- +# TEST 4: Conditional pre-set -run_make_test(undef, 'V1=@ V2=@', 'hello -world'); +run_make_test(' +foo = Hello +ugh = Goodbye +bar = ${ugh} +foo ?= $(bar) +ugh = Hello +all: ; @echo $(foo) +', + '', "Hello\n"); -# TEST #10 -# ------- -# Test the basics; a "@" internally to the variable applies to only one line. -# A "@" before the variable applies to the entire variable. +# TEST 5: Conditional unset run_make_test(' -define FOO -@echo hello -echo world -endef -define BAR -echo hello -echo world -endef - -all: foo bar -foo: ; $(FOO) -bar: ; @$(BAR) -', '-j1', 'hello -echo world -world -hello -world -'); +ugh = Goodbye +bar = ${ugh} +foo ?= $(bar) +ugh = Hello +all: ; @echo $(foo) +', + '', "Hello\n"); 1; diff --git a/src/kmk/tests/scripts/variables/private b/src/kmk/tests/scripts/variables/private new file mode 100644 index 0000000..b4baf5f --- /dev/null +++ b/src/kmk/tests/scripts/variables/private @@ -0,0 +1,78 @@ +# -*-perl-*- + +$description = "Test 'private' variables."; + +$details = ""; + +# 1: Simple verification that private variables are not inherited +&run_make_test(' +a: +F = g +a: F = a +b: private F = b + +a b c: ; @echo $@: F=$(F) +a: b +b: c +', + '', "c: F=a\nb: F=b\na: F=a\n"); + +# 2: Again, but this time we start with "b" so "a"'s variable is not in scope +&run_make_test(undef, 'b', "c: F=g\nb: F=b\n"); + +# 3: Verification with pattern-specific variables +&run_make_test(' +t.a: + +F1 = g +F2 = g +%.a: private F1 = a +%.a: F2 = a + +t.a t.b: ; @echo $@: F1=$(F1) / F2=$(F2) +t.a: t.b +', + '', "t.b: F1=g / F2=a\nt.a: F1=a / F2=a\n"); + +# 4: Test private global variables +&run_make_test(' +a: +private F = g +G := $(F) +a: +b: F = b + +a b: ; @echo $@: F=$(F) / G=$(G) +a: b +', + '', "b: F=b / G=g\na: F= / G=g\n"); + +# 5: Multiple conditions on the same variable. Test export. +delete $ENV{'_X'}; +&run_make_test(' +_X = x +a: export override private _X = a +a: ; @echo _X=$(_X) / _X=$$_X +', + '', "_X=a / _X=a"); + +# 6: Test override. +&run_make_test(undef, '_X=c', "_X=a / _X=a\n"); + +# 7: Ensure keywords still work as targets +&run_make_test(' +a: export override private foo bar +foo bar export override private: ; @echo $@ +', + '', "export\noverride\nprivate\nfoo\nbar\n"); + +# 8: Ensure keywords still work as variables +&run_make_test(' +private = g +a: private = a +a: b +a b: ; @echo $@=$(private) +', + '', "b=a\na=a\n"); + +1; diff --git a/src/kmk/tests/scripts/variables/undefine b/src/kmk/tests/scripts/variables/undefine new file mode 100644 index 0000000..38707b8 --- /dev/null +++ b/src/kmk/tests/scripts/variables/undefine @@ -0,0 +1,73 @@ +# -*-perl-*- + +$description = "Test variable undefine."; + +$details = ""; + +# TEST 0: basic undefine functionality + +run_make_test(' +a = a +b := b +define c +c +endef + +$(info $(flavor a) $(flavor b) $(flavor c)) + +n := b + +undefine a +undefine $n +undefine c + +$(info $(flavor a) $(flavor b) $(flavor c)) + + +all: ;@: +', +'', "recursive simple recursive\nundefined undefined undefined"); + + +# TEST 1: override + +run_make_test(' +undefine a +override undefine b + +$(info $(flavor a) $(flavor b)) + + +all: ;@: +', +'a=a b=b', "recursive undefined"); + +1; + +# TEST 2: undefine in eval (make sure we undefine from the global var set) + +run_make_test(' +define undef +$(eval undefine $$1) +endef + +a := a +$(call undef,a) +$(info $(flavor a)) + + +all: ;@: +', +'', "undefined"); + + +# TEST 3: Missing variable name + +run_make_test(' +a = +undefine $a +all: ;@echo ouch +', +'', "#MAKEFILE#:3: *** empty variable name. Stop.\n", 512); + +1; diff --git a/src/kmk/tests/test_driver.pl b/src/kmk/tests/test_driver.pl index 9d90418..c4c3ea6 100644 --- a/src/kmk/tests/test_driver.pl +++ b/src/kmk/tests/test_driver.pl @@ -6,7 +6,8 @@ # Modified 92-02-11 through 92-02-22 by Chris Arthur to further generalize. # # Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, -# 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc. +# 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software +# Foundation, Inc. # This file is part of GNU Make. # # GNU Make is free software; you can redistribute it and/or modify it under @@ -29,7 +30,7 @@ # this routine controls the whole mess; each test suite sets up a few # variables and then calls &toplevel, which does all the real work. -# $Id: test_driver.pl,v 1.24 2007/11/04 21:54:02 psmith Exp $ +# $Id: test_driver.pl,v 1.30 2010/07/28 05:39:50 psmith Exp $ # The number of test categories we've run @@ -53,6 +54,8 @@ $test_passed = 1; # Timeout in seconds. If the test takes longer than this we'll fail it. $test_timeout = 5; +# Path to Perl +$perl_name = $^X; # %makeENV is the cleaned-out environment. %makeENV = (); @@ -238,9 +241,10 @@ sub toplevel sub get_osname { # Set up an initial value. In perl5 we can do it the easy way. - # $osname = defined($^O) ? $^O : ''; + # Find a path to Perl + # See if the filesystem supports long file names with multiple # dots. DOS doesn't. $short_filenames = 0; @@ -275,14 +279,14 @@ sub get_osname eval "chop (\$osname = `sh -c 'uname -nmsr 2>&1'`)"; if ($osname =~ /not found/i) { - $osname = "(something unixy with no uname)"; + $osname = "(something posixy with no uname)"; } elsif ($@ ne "" || $?) { eval "chop (\$osname = `sh -c 'uname -a 2>&1'`)"; if ($@ ne "" || $?) { - $osname = "(something unixy)"; + $osname = "(something posixy)"; } } $vos = 0; @@ -459,16 +463,19 @@ sub run_each_test $logext = 'l'; $diffext = 'd'; $baseext = 'b'; + $runext = 'r'; $extext = ''; } else { $logext = 'log'; $diffext = 'diff'; $baseext = 'base'; + $runext = 'run'; $extext = '.'; } $log_filename = "$testpath.$logext"; $diff_filename = "$testpath.$diffext"; $base_filename = "$testpath.$baseext"; + $run_filename = "$testpath.$runext"; $tmp_filename = "$testpath.$tmpfilesuffix"; &setup_for_test; # suite-defined @@ -482,6 +489,7 @@ sub run_each_test # Run the actual test! $tests_run = 0; $tests_passed = 0; + $code = do $perl_testname; $total_tests_run += $tests_run; @@ -715,6 +723,7 @@ sub compare_output print "DIFFERENT OUTPUT\n" if $debug; &create_file (&get_basefile, $answer); + &create_file (&get_runfile, $command_string); print "\nCreating Difference File ...\n" if $debug; @@ -722,6 +731,8 @@ sub compare_output local($command) = "diff -c " . &get_basefile . " " . $logfile; &run_command_with_output(&get_difffile,$command); + } else { + &rmfiles (); } $suite_passed = 0; @@ -815,7 +826,7 @@ sub _run_command eval { local $SIG{ALRM} = sub { die "timeout\n"; }; alarm $test_timeout; - $code = system @_; + $code = system(@_); alarm 0; }; if ($@) { @@ -852,7 +863,7 @@ sub run_command_with_output { my $filename = shift; - print "\nrun_command_with_output($filename): @_\n" if $debug; + print "\nrun_command_with_output($filename,$runname): @_\n" if $debug; &attach_default_output ($filename); my $code = _run_command(@_); &detach_default_output; @@ -1225,6 +1236,15 @@ sub get_difffile return ($diff_filename . &num_suffix ($num_of_logfiles)); } +# This subroutine returns a command filename with a number appended +# to the end corresponding to how many logfiles (and thus command files) +# have been created in the current running test. + +sub get_runfile +{ + return ($run_filename . &num_suffix ($num_of_logfiles)); +} + # just like logfile, only a generic tmp filename for use by the test. # they are automatically cleaned up unless -keep was used, or the test fails. # Pass an argument of 1 to return the same filename as the previous call. |