From 29f453739f0059f632ce2963ca0c68f8bf6c5991 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sat, 31 Dec 2022 10:31:24 -0500 Subject: Avoid using false(1) in regression tests The POSIX standard only requires false(1) to return a "non-zero" exit code; almost all systems return 1 but some (Solaris!!!) return 255 or possibly even other values. Use our helper "fail" instead. * tests/thelp.pl: Have the "fail" command obey -q. * tests/scripts/features/parallelism: Helper -q no longer prints fail. * tests/scripts/targets/POSIX: Replace false with #HELPER# -q fail 1. * tests/scripts/variables/MAKEFLAGS: Ditto. * tests/scripts/variables/SHELL: Ditto. --- tests/scripts/features/parallelism | 6 +++--- tests/scripts/targets/POSIX | 18 +++++------------ tests/scripts/variables/MAKEFLAGS | 40 +++++++++++++++++++------------------- tests/scripts/variables/SHELL | 13 +++---------- tests/thelp.pl | 2 +- 5 files changed, 32 insertions(+), 47 deletions(-) (limited to 'tests') diff --git a/tests/scripts/features/parallelism b/tests/scripts/features/parallelism index 98ee8a30..8c3e8294 100644 --- a/tests/scripts/features/parallelism +++ b/tests/scripts/features/parallelism @@ -100,12 +100,12 @@ fail.2: ; @#HELPER# -q sleep 2 out $@ wait fail.1 file fail.2 fail 1 fail.3: ; @#HELPER# -q sleep 3 out $@ wait fail.2 file fail.3 fail 1 ok: ; @#HELPER# -q sleep 4 wait fail.3 out OK!, - '-rR -j5', "fail.1\nfail 1 + '-rR -j5', "fail.1 #MAKE#: *** [#MAKEFILE#:5: fail.1] Error 1 #MAKE#: *** Waiting for unfinished jobs.... -fail.2\nfail 1 +fail.2 #MAKE#: *** [#MAKEFILE#:6: fail.2] Error 1 -fail.3\nfail 1 +fail.3 #MAKE#: *** [#MAKEFILE#:7: fail.3] Error 1 OK", 512); diff --git a/tests/scripts/targets/POSIX b/tests/scripts/targets/POSIX index c40b8dbe..55adbc4d 100644 --- a/tests/scripts/targets/POSIX +++ b/tests/scripts/targets/POSIX @@ -6,30 +6,22 @@ $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 = `$sh_name $flags '$script' 2>&1`; -my $err = $? >> 8; run_make_test(qq! .POSIX: -all: ; \@$script +all: ; \@#HELPER# -q fail 1; true !, - '', "#MAKE#: *** [#MAKEFILE#:3: all] Error $err\n", 512); + '', "#MAKE#: *** [#MAKEFILE#:3: all] Error 1\n", 512); # User settings must override .POSIX # In the standard .POSIX must be the first thing in the makefile # but we relax that rule in GNU make. -$flags = '-xc'; -$out = `$sh_name $flags '$script' 2>&1`; run_make_test(qq! -.SHELLFLAGS = $flags +.SHELLFLAGS = -xc .POSIX: -all: ; \@$script +all: ; \@#HELPER# -q fail 1; true !, - '', $out); + '', "+ #HELPER# -q fail 1\n+ true\n"); # Test the default value of various POSIX-specific variables my %POSIX = (AR => 'ar', ARFLAGS => '-rv', diff --git a/tests/scripts/variables/MAKEFLAGS b/tests/scripts/variables/MAKEFLAGS index 24264c23..0d0e896f 100644 --- a/tests/scripts/variables/MAKEFLAGS +++ b/tests/scripts/variables/MAKEFLAGS @@ -539,12 +539,12 @@ $(info $(MAKEFLAGS)) all: one two one: $(info $(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; $(info $@) !, '', "S S -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:6: one] Error 1", 512); # -S in env, -k on the command line. @@ -554,12 +554,12 @@ $(info $(MAKEFLAGS)) all: one two one: $(info $(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; $(info $@) !, '-k', "k k -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:6: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); @@ -571,12 +571,12 @@ $(info $(MAKEFLAGS)) all: one two one: $(info $(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; $(info $@) !, '', "k k -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:6: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); @@ -588,12 +588,12 @@ $(info $(MAKEFLAGS)) all: one two one: $(info $(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; $(info $@) !, '-S', "S S -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:6: one] Error 1", 512); delete $ENV{'MAKEFLAGS'}; @@ -606,12 +606,12 @@ MAKEFLAGS${fl}-k all: one two one: \$(info \$(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; \$(info \$@) ", '', "k k -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); @@ -626,12 +626,12 @@ MAKEFLAGS${fl}-k all: one two one: \$(info \$(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; \$(info \$@) ", '-S', "S S -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1", 512); } @@ -645,12 +645,12 @@ MAKEFLAGS${fl}-k all: one two one: \$(info \$(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; \$(info \$@) ", '', "S S -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1", 512); } @@ -665,12 +665,12 @@ MAKEFLAGS${fl}-S all: one two one: \$(info \$(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; \$(info \$@) ", '', "S S -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1", 512); } @@ -682,12 +682,12 @@ MAKEFLAGS${fl}-S all: one two one: \$(info \$(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; \$(info \$@) ", '-k', "k k -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); @@ -703,12 +703,12 @@ MAKEFLAGS${fl}-S all: one two one: \$(info \$(MAKEFLAGS)) - false + #HELPER# -q fail 1 two:; \$(info \$@) ", '', "k k -false +#HELPER# -q fail 1 #MAKE#: *** [#MAKEFILE#:7: one] Error 1 two #MAKE#: Target 'all' not remade because of errors.", 512); diff --git a/tests/scripts/variables/SHELL b/tests/scripts/variables/SHELL index 78d887c5..9334c040 100644 --- a/tests/scripts/variables/SHELL +++ b/tests/scripts/variables/SHELL @@ -94,17 +94,10 @@ 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 = `$sh_name $flags '$script' 2>&1`; -my $err = $? >> 8; - run_make_test(qq! -.SHELLFLAGS = $flags -all: ; \@$script +.SHELLFLAGS = -xec +all: ; \@true; #HELPER# -q fail 1; true !, - '', "$out#MAKE#: *** [#MAKEFILE#:3: all] Error $err\n", 512); + '', "+ true\n+ #HELPER# -q fail 1\n#MAKE#: *** [#MAKEFILE#:3: all] Error 1\n", 512); 1; diff --git a/tests/thelp.pl b/tests/thelp.pl index c243bcb8..8d29e5c3 100755 --- a/tests/thelp.pl +++ b/tests/thelp.pl @@ -103,7 +103,7 @@ sub op { } if ($op eq 'fail') { - print "fail $nm\n"; + print "fail $nm\n" unless $quiet; exit($nm); } -- cgit v1.2.1