Skip to content

Commit d9b90c3

Browse files
committed
t/test.pl: Make /dev/null available for portability
This creates a variable containing the string to use to specify /dev/null portably; and documents the package variables it sets
1 parent c3fe880 commit d9b90c3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

t/test.pl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#
22
# t/test.pl - most of Test::More functionality without the fuss
33

4-
54
# NOTE:
65
#
76
# Do not rely on features found only in more modern Perls here, as some CPAN
@@ -19,6 +18,10 @@
1918
# In this file, we use the latter "Baby Perl" approach, and increment
2019
# will be worked over by t/op/inc.t
2120

21+
# This file sets for its caller $::IS_ASCII and $::IS_EBCDIC appropriately;
22+
# and $::devnull to be the string to use to specify /dev/null on this
23+
# platform.
24+
2225
$| = 1;
2326
our $Level = 1;
2427
my $test = 1;
@@ -697,6 +700,9 @@ ($)
697700
my $is_vms = $^O eq 'VMS';
698701
my $is_cygwin = $^O eq 'cygwin';
699702

703+
# /dev/null appears to be surprisingly portable.
704+
$::devnull = ($is_mswin ? 'nul' : '/dev/null');
705+
700706
sub _quote_args {
701707
my ($runperl, $args) = @_;
702708

@@ -798,14 +804,13 @@ sub _create_runperl { # Create the string to qx in runperl().
798804
# needing a pipeline, so that the fork tests have a sane environment
799805
# without these surprises.
800806

801-
# /dev/null appears to be surprisingly portable.
802-
$runperl = $runperl . ($is_mswin ? ' <nul' : ' </dev/null');
807+
$runperl = "$runperl <$::devnull";
803808
}
804809
if (defined $args{args}) {
805810
$runperl = _quote_args($runperl, $args{args});
806811
}
807812
if (exists $args{stderr} && $args{stderr} eq 'devnull') {
808-
$runperl = $runperl . ($is_mswin ? ' 2>nul' : ' 2>/dev/null');
813+
$runperl = "$runperl 2>$::devnull";
809814
}
810815
elsif ($args{stderr}) {
811816
$runperl = $runperl . ' 2>&1';

0 commit comments

Comments
 (0)