--- /dev/null
+#!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<SystemRoot> ],
+ 'android' => [ $ld_path ],
+ 'cygwin' => [ qw<PATH> ],
+ '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<MSWin32 android cygwin linux>) {
+ 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";
+}