3 # Tests for the command-line switches
14 # due to a bug in VMS's piping which makes it impossible for runperl()
15 # to emulate echo -n (ie. stdin always winds up with a newline), these
16 # tests almost totally fail.
17 $TODO = "runperl() unable to emulate echo -n due to pipe bug" if $^O eq 'VMS';
21 END { unlink @tmpfiles }
26 switches => [ '-0', ],
27 stdin => 'foo\0bar\0baz\0',
28 prog => 'print qq(<$_>) while <>',
30 is( $r, "<foo\0><bar\0><baz\0>", "-0" );
33 switches => [ '-l', '-0', '-p' ],
34 stdin => 'foo\0bar\0baz\0',
37 is( $r, "foo\nbar\nbaz\n", "-0 after a -l" );
40 switches => [ '-0', '-l', '-p' ],
41 stdin => 'foo\0bar\0baz\0',
44 is( $r, "foo\0bar\0baz\0", "-0 before a -l" );
47 switches => [ sprintf("-0%o", ord 'x') ],
48 stdin => 'fooxbarxbazx',
49 prog => 'print qq(<$_>) while <>',
51 is( $r, "<foox><barx><bazx>", "-0 with octal number" );
54 switches => [ '-00', '-p' ],
55 stdin => 'abc\ndef\n\nghi\njkl\nmno\n\npq\n',
56 prog => 's/\n/-/g;$_.=q(/)',
58 is( $r, 'abc-def--/ghi-jkl-mno--/pq-/', '-00 (paragraph mode)' );
61 switches => [ '-0777', '-p' ],
62 stdin => 'abc\ndef\n\nghi\njkl\nmno\n\npq\n',
63 prog => 's/\n/-/g;$_.=q(/)',
65 is( $r, 'abc-def--ghi-jkl-mno--pq-/', '-0777 (slurp mode)' );
68 switches => [ '-066' ],
69 prog => 'BEGIN { print qq{($/)} } print qq{[$/]}',
71 is( $r, "(\066)[\066]", '$/ set at compile-time' );
75 my $filename = 'swctest.tmp';
77 local $TODO = ''; # this one works on VMS
79 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
81 BEGIN { print "block 1\n"; }
82 CHECK { print "block 2\n"; }
83 INIT { print "block 3\n"; }
85 END { print "block 5\n"; }
87 close $f or die "Could not close: $!";
90 progfile => $filename,
93 # Because of the stderr redirection, we can't tell reliably the order
94 # in which the output is given
96 $r =~ /$filename syntax OK/
97 && $r =~ /\bblock 1\b/
98 && $r =~ /\bblock 2\b/
99 && $r !~ /\bblock 3\b/
100 && $r !~ /\bblock 4\b/
101 && $r !~ /\bblock 5\b/,
104 push @tmpfiles, $filename;
110 switches => [ sprintf("-l%o", ord 'x') ],
111 prog => 'print for qw/foo bar/'
113 is( $r, 'fooxbarx', '-l with octal number' );
118 switches => [ '-s' ],
119 prog => 'for (qw/abc def ghi/) {print defined $$_ ? $$_ : q(-)}',
120 args => [ '--', '-abc=2', '-def', ],
122 is( $r, '21-', '-s switch parsing' );
124 # Bug ID 20011106.084
125 $filename = 'swstest.tmp';
127 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
132 close $f or die "Could not close: $!";
134 switches => [ '-s' ],
135 progfile => $filename,
136 args => [ '-x=foo' ],
138 is( $r, 'foo', '-s on the shebang line' );
139 push @tmpfiles, $filename;
142 # Tests for -m and -M
144 $filename = 'swtest.pm';
146 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!",4 );
147 print $f <<'SWTESTPM';
149 sub import { print map "<$_>", @_ }
152 close $f or die "Could not close: $!";
154 switches => [ '-Mswtest' ],
157 is( $r, '<swtest>', '-M' );
159 switches => [ '-Mswtest=foo' ],
162 is( $r, '<swtest><foo>', '-M with import parameter' );
164 switches => [ '-mswtest' ],
169 local $TODO = ''; # this one works on VMS
173 switches => [ '-mswtest=foo,bar' ],
176 is( $r, '<swtest><foo><bar>', '-m with import parameters' );
177 push @tmpfiles, $filename;
183 local $TODO = ''; # these ones should work on VMS
185 # basic perl -V should generate significant output.
186 # we don't test actual format since it could change
187 like( runperl( switches => ['-V'] ), qr/(\n.*){20}/,
188 '-V generates 20+ lines' );
190 # lookup a known config var
191 chomp( $r=runperl( switches => ['-V:osname'] ) );
192 is( $r, "osname='$^O';", 'perl -V:osname');
194 # lookup a nonexistent var
195 chomp( $r=runperl( switches => ['-V:this_var_makes_switches_test_fail'] ) );
196 is( $r, "this_var_makes_switches_test_fail='UNKNOWN';",
197 'perl -V:unknown var');
200 # platforms that don't like this quoting can either skip this test
201 # or fix test.pl _quote_args
202 $r = runperl( switches => ['"-V:i\D+size"'] );
203 # should be unlike( $r, qr/^$|not found|UNKNOWN/ );
204 like( $r, qr/^(?!.*(not found|UNKNOWN))./, 'perl -V:re got a result' );
206 # make sure each line we got matches the re
207 ok( !( grep !/^i\D+size=/, split /^/, $r ), '-V:re correct' );