From: Vincent Pit Date: Wed, 11 Mar 2015 14:33:51 +0000 (-0300) Subject: Test run_perl() preserving ENV vars X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=ca9da898bbed123e1c3c95814673315cfc125187;p=perl%2Fmodules%2FVPIT-TestHelpers.git Test run_perl() preserving ENV vars --- diff --git a/t/30-run_perl.t b/t/30-run_perl.t new file mode 100644 index 0000000..b71f7be --- /dev/null +++ b/t/30-run_perl.t @@ -0,0 +1,64 @@ +#!perl + +use strict; +use warnings; + +use VPIT::TestHelpers; + +use Test::More tests => 4; + +use Config; +use File::Temp; + +my $filename = '/tmp/run_perl_test'; + +my $code = "open my \$fh, q[>], q[$filename] or die \$!; for my \$key (sort keys %ENV) { print \$fh qq[\$key:\$ENV{\$key}\n] } close \$fh"; + +my $ld_path = $Config::Config{ldlibpthname}; + +my %expected_vars = ( + 'MSWin32' => [ qw ], + 'android' => [ $ld_path ], + 'cygwin' => [ qw ], + 'linux' => [ ], +); + +my @all_vars = do { + my %uniq; + grep !$uniq{$_}++, map @$_, values %expected_vars; +}; +push @all_vars, 'DUMMY'; + +my @ignored_vars = qw< + VERSIONER_PERL_PREFER_32_BIT + VERSIONER_PERL_VERSION + __CF_USER_TEXT_ENCODING +>; + +for my $os (qw) { + 1 while unlink $filename; + + local $^O = $os; + local %ENV; + + @ENV{@all_vars} = @all_vars; + + run_perl $code; + + my %subprocess_env; + + open my $fh, '<', $filename; + if ($fh) { + my @lines = <$fh>; + close $fh; + chomp for @lines; + %subprocess_env = map { split /:/, $_, 2 } @lines; + } + + delete @subprocess_env{@ignored_vars}; + + my $got = join "\n", sort keys %subprocess_env; + my $exp = join "\n", sort @{ $expected_vars{$os} || [] }; + + is $got, $exp, "run_perl preserving $os ENV vars"; +}