This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl5db] Extract $obj->_handle_dash_command.
[perl5.git] / t / io / nargv.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require "./test.pl";
7 }
8
9 print "1..5\n";
10
11 my $j = 1;
12 for $i ( 1,2,5,4,3 ) {
13     $file = mkfiles($i);
14     open(FH, "> $file") || die "can't create $file: $!";
15     print FH "not ok " . $j++ . "\n";
16     close(FH) || die "Can't close $file: $!";
17 }
18
19
20 {
21     local *ARGV;
22     local $^I = '.bak';
23     local $_;
24     @ARGV = mkfiles(1..3);
25     $n = 0;
26     while (<>) {
27         print STDOUT "# initial \@ARGV: [@ARGV]\n";
28         if ($n++ == 2) {
29             other();
30         }
31         show();
32     }
33 }
34
35 $^I = undef;
36 @ARGV = mkfiles(1..3);
37 $n = 0;
38 while (<>) {
39     print STDOUT "#final \@ARGV: [@ARGV]\n";
40     if ($n++ == 2) {
41         other();
42     }
43     show();
44 }
45
46 sub show {
47     #warn "$ARGV: $_";
48     s/^not //;
49     print;
50 }
51
52 sub other {
53     no warnings 'once';
54     print STDOUT "# Calling other\n";
55     local *ARGV;
56     local *ARGVOUT;
57     local $_;
58     @ARGV = mkfiles(5, 4);
59     while (<>) {
60         print STDOUT "# inner \@ARGV: [@ARGV]\n";
61         show();
62     }
63 }
64
65 my @files;
66 sub mkfiles {
67     foreach (@_) {
68         $files[$_] ||= tempfile();
69     }
70     my @results = @files[@_];
71     return wantarray ? @results : @results[-1];
72 }
73
74 END { unlink_all map { ($_, "$_.bak") } mkfiles(1..5) }