]> git.ipfire.org Git - thirdparty/make.git/commitdiff
tests: Simplify customization of %ENV
authorPaul Smith <psmith@gnu.org>
Wed, 1 Apr 2020 05:58:33 +0000 (01:58 -0400)
committerPaul Smith <psmith@gnu.org>
Wed, 1 Apr 2020 06:02:57 +0000 (02:02 -0400)
Rather than having an %extraENV that is added to the default %ENV
and resetting %ENV _before_ each test, allow the test setup to
modify %ENV directly as needed then reset %ENV _after_ each test.

* tests/test_driver.pl: Remove unused %extraENV.
(resetENV): Don't add in %extraENV.
(_run_command): Reset after we run the command rather than before.
* tests/scripts/features/export: Convert %extraENV to %ENV
* tests/scripts/features/jobserver: Ditto
* tests/scripts/features/parallelism: Ditto
* tests/scripts/features/targetvars: Ditto
* tests/scripts/functions/eval: Ditto
* tests/scripts/functions/foreach: Ditto
* tests/scripts/functions/origin: Ditto
* tests/scripts/misc/general4: Ditto
* tests/scripts/options/dash-e: Ditto
* tests/scripts/targets/POSIX: Ditto
* tests/scripts/variables/GNUMAKEFLAGS: Ditto
* tests/scripts/variables/SHELL: Ditto

13 files changed:
tests/scripts/features/export
tests/scripts/features/jobserver
tests/scripts/features/parallelism
tests/scripts/features/targetvars
tests/scripts/functions/eval
tests/scripts/functions/foreach
tests/scripts/functions/origin
tests/scripts/misc/general4
tests/scripts/options/dash-e
tests/scripts/targets/POSIX
tests/scripts/variables/GNUMAKEFLAGS
tests/scripts/variables/SHELL
tests/test_driver.pl

index 81bff0c31e5b0ac2008c94956f38c8f19281ead4..0b07abb9b5644cf195924aec62d7aeef0860f850 100644 (file)
@@ -32,16 +32,17 @@ ifdef EXPORT_ALL_PSEUDO
 .EXPORT_ALL_VARIABLES:
 endif
 
+.RECIPEPREFIX := >
 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"
+> @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"
 ',
            '', "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;
+$ENV{FOO} = 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");
@@ -85,9 +86,10 @@ B = b
 export $(FOO)
 export $(B)ar
 
+.RECIPEPREFIX := >
 all:
-       @echo foo=$(foo) bar=$(bar)
-       @echo foo=$$foo bar=$$bar
+> @echo foo=$(foo) bar=$(bar)
+> @echo foo=$$foo bar=$$bar
 ',
              "", "foo=f-ok bar=b-ok\nfoo=f-ok bar=b-ok\n");
 
@@ -108,9 +110,10 @@ export foo bar
 unexport $(FOO)
 unexport $(B)ar
 
+.RECIPEPREFIX := >
 all:
-       @echo foo=$(foo) bar=$(bar)
-       @echo foo=$$foo bar=$$bar
+> @echo foo=$(foo) bar=$(bar)
+> @echo foo=$$foo bar=$$bar
 ',
               '', "foo=f-ok bar=b-ok\nfoo= bar=\n");
 
@@ -140,7 +143,8 @@ all: ; @echo A=$$A B=$$B C=$$C D=$$D E=$$E F=$$F G=$$G H=$$H I=$$I J=$$J
 
 # TEST 8: Test unexporting multiple variables on the same line
 
-@extraENV{qw(A B C D E F G H I J)} = qw(1 2 3 4 5 6 7 8 9 10);
+@args{qw(A B C D E F G H I J)} = qw(1 2 3 4 5 6 7 8 9 10);
+%ENV = (%ENV, %args);
 
 &run_make_test('
 A = a
index 2d61e3f48e52bcff7d5ddac8dcd305246766335d..35b5696250e6a0a43b2fbf4d95fde2f0ada5113a 100644 (file)
@@ -25,17 +25,16 @@ all:;@echo $@: "/$(SHOW)/"
 
 # Setting parallelism with the environment
 # Command line should take precedence over the environment
-$extraENV{MAKEFLAGS} = "-j2 $np";
+$ENV{MAKEFLAGS} = "-j2 $np";
 run_make_test(q!
 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
 all:;@echo $@: "/$(SHOW)/"
 !,
               '', "recurse: /-j2 --jobserver-auth=<auth> $np/\nall: /-j2 --jobserver-auth=<auth> $np/\n");
-delete $extraENV{MAKEFLAGS};
 
 # Test override of -jN
-$extraENV{MAKEFLAGS} = "-j9 $np";
+$ENV{MAKEFLAGS} = "-j9 $np";
 run_make_test(q!
 SHOW = $(patsubst --jobserver-auth=%,--jobserver-auth=<auth>,$(MAKEFLAGS))
 recurse: ; @echo $@: "/$(SHOW)/"; $(MAKE) -j3 -f #MAKEFILE# recurse2
@@ -43,7 +42,6 @@ recurse2: ; @echo $@: "/$(SHOW)/"; $(MAKE) -f #MAKEFILE# all
 all:;@echo $@: "/$(SHOW)/"
 !,
               "-j2 $np", "recurse: /-j2 --jobserver-auth=<auth> $np/\n#MAKE#[1]: warning: -j3 forced in submake: resetting jobserver mode.\nrecurse2: /-j3 --jobserver-auth=<auth> $np/\nall: /-j3 --jobserver-auth=<auth> $np/\n");
-delete $extraENV{MAKEFLAGS};
 
 # Test override of -jN with -j
 run_make_test(q!
index 08f94a6b6307a8f1e00a60f454795396641f9719..e9935b4b398e0dfb983c0991e1c99c4447df4918 100644 (file)
@@ -148,7 +148,7 @@ rmfiles('target');
 # TEST #11: Make sure -jN from MAKEFLAGS is processed even when we re-exec
 # See Savannah bug #33873
 
-$extraENV{MAKEFLAGS} = '-j4';
+$ENV{MAKEFLAGS} = '-j4';
 
 run_make_test(q!
 things = thing1 thing2
@@ -160,7 +160,6 @@ inc.mk: ; @touch $@
 !,
               '', "file thing2start\nwait thing2start\nfile thing1start\nwait thing1start\nfile thing2end\nwait thing2end\nthing1end\n");
 
-delete $extraENV{MAKEFLAGS};
 rmfiles(qw(inc.mk thing1start thing1end thing2start thing2end));
 
 # Ensure intermediate/secondary files are not pruned incorrectly.
index 2929b2cc523d2b4800f5ce0be2bc430cca4c6a23..edc90b81381b9b078b8ce81e44fe1c823b490157 100644 (file)
@@ -270,7 +270,7 @@ all: ; $sname >/dev/null
 
 # Don't use the general PATH if not found on the target path
 
-$extraENV{PATH} = "$ENV{PATH}:sd";
+$ENV{PATH} = "$ENV{PATH}:sd";
 
 run_make_test(qq!
 all: PATH := ..
index 90513bdd29277ce51a5650bd27d1f4e96611bd63..a3fba87a5db5187c5413c2a0b4d247c42fb2c371 100644 (file)
@@ -127,7 +127,7 @@ EOF
 
 close(MAKEFILE);
 
-$extraENV{EVAR} = '1';
+$ENV{EVAR} = '1';
 &run_make_with_options($makefile4, "", &get_logfile);
 $answer = "OK\n";
 &compare_output($answer,&get_logfile(1));
index 9badc52e49c0f4de8720ad450899a7c6f1c36a37..6a06109a582b2217336028c14b59a70799f69394 100644 (file)
@@ -14,7 +14,7 @@ types of foreach loops are tested\n";
 # TEST 0
 
 # Set an environment variable that we can test in the makefile.
-$extraENV{FOOFOO} = 'foo foo';
+$ENV{FOOFOO} = 'foo foo';
 
 run_make_test("space = ' '".'
 null :=
@@ -31,8 +31,6 @@ for2: ; @echo $(fe)',
               "undefined file default file environment default file command line override automatic automatic
 foo.o bletch.o null.o @.o garf.o .o    .o undefined.o file.o default.o file.o environment.o default.o file.o command.o line.o override.o automatic.o automatic.o");
 
-delete $extraENV{FOOFOO};
-
 # TEST 1: Test that foreach variables take precedence over global
 # variables in a global scope (like inside an eval).  Tests bug #11913
 
index f7b7eb84823b70d2a8b74d99918f293b0b1e9a13..9b9fd56a16c18bf5af3f9ac3d12d704d12890a8c 100644 (file)
@@ -16,26 +16,27 @@ defined per the following list:
 'automatic'            Automatic variable\n";
 
 # Set an environment variable
-$extraENV{MAKETEST} = 1;
+$ENV{MAKETEST} = 1;
 
 run_make_test('
 foo := bletch garf
 auto_var = undefined CC MAKETEST MAKE foo CFLAGS WHITE @
 av = $(foreach var, $(auto_var), $(origin $(var)) )
 override WHITE := BLACK
+.RECIPEPREFIX = >
 all: auto
-       @echo $(origin undefined)
-       @echo $(origin CC)
-       @echo $(origin MAKETEST)
-       @echo $(origin MAKE)
-       @echo $(origin foo)
-       @echo $(origin CFLAGS)
-       @echo $(origin WHITE)
-       @echo $(origin @)
+> @echo $(origin undefined)
+> @echo $(origin CC)
+> @echo $(origin MAKETEST)
+> @echo $(origin MAKE)
+> @echo $(origin foo)
+> @echo $(origin CFLAGS)
+> @echo $(origin WHITE)
+> @echo $(origin @)
 auto :
-       @echo $(av)',
-             '-e WHITE=WHITE CFLAGS=',
-             'undefined default environment default file command line override automatic
+> @echo $(av)',
+    '-e WHITE=WHITE CFLAGS=',
+    'undefined default environment default file command line override automatic
 undefined
 default
 environment
@@ -45,7 +46,4 @@ command line
 override
 automatic');
 
-# Reset an environment variable
-delete $extraENV{MAKETEST};
-
 1;
index eeb8d106754122f0996f09f48d426d2429cbea60..263505e492f7b6d120504994e8d0bb79bb9558dd 100644 (file)
@@ -94,7 +94,7 @@ all: ; $sname >/dev/null
 
 # Don't use the general PATH if not found on the target path
 
-$extraENV{PATH} = "$ENV{PATH}:sd";
+$ENV{PATH} = "$ENV{PATH}:sd";
 
 run_make_test(qq!
 PATH := ..
index 17c3fc865346c58a58f40edffecdced6177d4cfb..944c39dfd525eaf27e7e80eb65b39312b7197266 100644 (file)
@@ -4,21 +4,12 @@ $description = "The following test creates a makefile to ...";
 
 $details = "";
 
-$extraENV{GOOGLE} = 'boggle';
+$ENV{GOOGLE} = 'boggle';
 
-open(MAKEFILE,"> $makefile");
-
-print MAKEFILE <<'EOF';
+run_make_test(q!
 GOOGLE = bazzle
 all:; @echo "$(GOOGLE)"
-EOF
-
-close(MAKEFILE);
-
-&run_make_with_options($makefile, '-e' ,&get_logfile);
-
-$answer = "boggle\n";
-
-&compare_output($answer,&get_logfile(1));
+!,
+              '-e', "boggle\n");
 
 1;
index c44cc500111e76896a4343084fa70fbb2aa38a2d..d69b8bbdabb3931c566d8db599ebb19d6a90526d 100644 (file)
@@ -47,7 +47,7 @@ $make
               '', $r);
 
 # Make sure that local settings take precedence
-%extraENV = map { $_ => "xx-$_" } keys %POSIX;
+%ENV = (%ENV, map { $_ => "xx-$_" } keys %POSIX);
 $r = join('', map { "$_=xx-$_\n"} sort keys %POSIX);
 run_make_test(undef, '', $r);
 
index 62a68bd9cfdfefd28ab19ea75ad39a82bf50900d..063c256dfbcd6d3aecf3c6583f68db954fc9d920 100644 (file)
@@ -5,7 +5,7 @@ $description = "Test proper behavior of GNUMAKEFLAGS";
 # Accept flags from GNUMAKEFLAGS as well as MAKEFLAGS
 # Results always go in MAKEFLAGS
 
-$extraENV{'GNUMAKEFLAGS'} = '-e -r -R';
+$ENV{'GNUMAKEFLAGS'} = '-e -r -R';
 
 run_make_test(q!
 all: ; @echo $(MAKEFLAGS)
@@ -14,7 +14,7 @@ all: ; @echo $(MAKEFLAGS)
 
 # Long arguments mean everything is prefixed with "-"
 
-$extraENV{'GNUMAKEFLAGS'} = '--no-print-directory -e -r -R --trace';
+$ENV{'GNUMAKEFLAGS'} = '--no-print-directory -e -r -R --trace';
 
 run_make_test(q!
 all: ; @echo $(MAKEFLAGS)
@@ -27,7 +27,7 @@ erR --trace --no-print-directory");
 
 unlink('x.mk');
 
-$extraENV{GNUMAKEFLAGS} = '-Itst/bad';
+$ENV{GNUMAKEFLAGS} = '-Itst/bad';
 
 run_make_test(q!
 recurse: ; @echo $@; echo MAKEFLAGS = $$MAKEFLAGS; echo GNUMAKEFLAGS = $$GNUMAKEFLAGS; #MAKEPATH# -f #MAKEFILE# all
index 4ff1ac256f4ebfaaf310e82e258a3265b40af9a2..34e72be435da81c091616e9172e898ba4c696cb6 100644 (file)
@@ -14,9 +14,8 @@ $mshell = $sh_name;
 
 # According to POSIX, the value of SHELL in the environment has no impact on
 # the value in the makefile.
-# Note %extraENV takes precedence over the default value for the shell.
 
-$extraENV{SHELL} = '/dev/null';
+$ENV{SHELL} = '/dev/null';
 run_make_test('all:;@echo "$(SHELL)"', '', $mshell);
 
 # According to POSIX, any value of SHELL set in the makefile should _NOT_ be
@@ -25,7 +24,7 @@ run_make_test('all:;@echo "$(SHELL)"', '', $mshell);
 # all when $(SHELL) is perl :-/.  So, we just add an extra initial /./ which
 # works well on UNIX and seems to work OK on at least some non-UNIX systems.
 
-$extraENV{SHELL} = $mshell;
+$ENV{SHELL} = $mshell;
 
 my $altshell = "/./$mshell";
 my $altshell2 = "/././$mshell";
@@ -41,7 +40,7 @@ all:;@echo "$(SHELL) $$SHELL"
 # As a GNU make extension, if make's SHELL variable is explicitly exported,
 # then we really _DO_ export it.
 
-$extraENV{SHELL} = $mshell;
+$ENV{SHELL} = $mshell;
 
 run_make_test("export SHELL := $altshell\n".'
 all:;@echo "$(SHELL) $$SHELL"
@@ -51,13 +50,13 @@ all:;@echo "$(SHELL) $$SHELL"
 # Test out setting of SHELL, both exported and not, as a target-specific
 # variable.
 
-$extraENV{SHELL} = $mshell;
+$ENV{SHELL} = $mshell;
 
 run_make_test("all: SHELL := $altshell\n".'
 all:;@echo "$(SHELL) $$SHELL"
 ', '', "$altshell $mshell");
 
-$extraENV{SHELL} = $mshell;
+$ENV{SHELL} = $mshell;
 
 run_make_test("
 SHELL := $altshell2
index ccd43c5f73799cb401115c5235dfa2ccb3bc6a2e..ec17be1feb6477eb8969c5799dafc964058579ca 100644 (file)
@@ -83,13 +83,9 @@ if ($^O ne 'VMS') {
 # in recipes
 $perl_name =~ tr,\\,/,;
 
-# %makeENV is the cleaned-out environment.
+# %makeENV is the cleaned-out environment.  Tests must not modify it.
 %makeENV = ();
 
-# %extraENV are any extra environment variables the tests might want to set.
-# These are RESET AFTER EVERY TEST!
-%extraENV = ();
-
 sub vms_get_process_logicals {
   # Sorry for the long note here, but to keep this test running on
   # VMS, it is needed to be understood.
@@ -150,11 +146,6 @@ sub resetENV
       }
     }
   }
-
-  foreach $v (keys %extraENV) {
-    $ENV{$v} = $extraENV{$v};
-    delete $extraENV{$v};
-  }
 }
 
 sub toplevel
@@ -1059,15 +1050,13 @@ sub _run_with_timeout
 # This runs a command without any debugging info.
 sub _run_command
 {
-  # We reset this before every invocation.  On Windows I think there is only
-  # one environment, not one per process, so I think that variables set in
-  # test scripts might leak into subsequent tests if this isn't reset--???
-  resetENV();
-
   my $orig = $SIG{ALRM};
   my $code = eval { _run_with_timeout(@_); };
   $SIG{ALRM} = $orig;
 
+  # Reset then environment so that it's clean for the next test.
+  resetENV();
+
   if ($@) {
     # The eval failed.  If it wasn't SIGALRM then die.
     $@ eq "timeout\n" or die "Command failed: $@";