3 # Tests for the command-line switches -0, -c, -l, -s, -m, -M, -V, -v, -h, -z
4 # Some switches have their own tests, see MANIFEST.
15 # due to a bug in VMS's piping which makes it impossible for runperl()
16 # to emulate echo -n (ie. stdin always winds up with a newline), these
17 # tests almost totally fail.
18 $TODO = "runperl() unable to emulate echo -n due to pipe bug" if $^O eq 'VMS';
22 END { unlink @tmpfiles }
27 switches => [ '-0', ],
28 stdin => 'foo\0bar\0baz\0',
29 prog => 'print qq(<$_>) while <>',
31 is( $r, "<foo\0><bar\0><baz\0>", "-0" );
34 switches => [ '-l', '-0', '-p' ],
35 stdin => 'foo\0bar\0baz\0',
38 is( $r, "foo\nbar\nbaz\n", "-0 after a -l" );
41 switches => [ '-0', '-l', '-p' ],
42 stdin => 'foo\0bar\0baz\0',
45 is( $r, "foo\0bar\0baz\0", "-0 before a -l" );
48 switches => [ sprintf("-0%o", ord 'x') ],
49 stdin => 'fooxbarxbazx',
50 prog => 'print qq(<$_>) while <>',
52 is( $r, "<foox><barx><bazx>", "-0 with octal number" );
55 switches => [ '-00', '-p' ],
56 stdin => 'abc\ndef\n\nghi\njkl\nmno\n\npq\n',
57 prog => 's/\n/-/g;$_.=q(/)',
59 is( $r, 'abc-def--/ghi-jkl-mno--/pq-/', '-00 (paragraph mode)' );
62 switches => [ '-0777', '-p' ],
63 stdin => 'abc\ndef\n\nghi\njkl\nmno\n\npq\n',
64 prog => 's/\n/-/g;$_.=q(/)',
66 is( $r, 'abc-def--ghi-jkl-mno--pq-/', '-0777 (slurp mode)' );
69 switches => [ '-066' ],
70 prog => 'BEGIN { print qq{($/)} } print qq{[$/]}',
72 is( $r, "(\066)[\066]", '$/ set at compile-time' );
76 my $filename = 'swctest.tmp';
78 local $TODO = ''; # this one works on VMS
80 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
82 BEGIN { print "block 1\n"; }
83 CHECK { print "block 2\n"; }
84 INIT { print "block 3\n"; }
86 END { print "block 5\n"; }
88 close $f or die "Could not close: $!";
91 progfile => $filename,
94 # Because of the stderr redirection, we can't tell reliably the order
95 # in which the output is given
97 $r =~ /$filename syntax OK/
98 && $r =~ /\bblock 1\b/
99 && $r =~ /\bblock 2\b/
100 && $r !~ /\bblock 3\b/
101 && $r !~ /\bblock 4\b/
102 && $r !~ /\bblock 5\b/,
105 push @tmpfiles, $filename;
111 switches => [ sprintf("-l%o", ord 'x') ],
112 prog => 'print for qw/foo bar/'
114 is( $r, 'fooxbarx', '-l with octal number' );
119 switches => [ '-s' ],
120 prog => 'for (qw/abc def ghi/) {print defined $$_ ? $$_ : q(-)}',
121 args => [ '--', '-abc=2', '-def', ],
123 is( $r, '21-', '-s switch parsing' );
125 # Bug ID 20011106.084
126 $filename = 'swstest.tmp';
128 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
131 BEGIN { print $x; exit }
133 close $f or die "Could not close: $!";
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 too much since it could change
187 like( runperl( switches => ['-V'] ), qr/(\n.*){20}/,
188 '-V generates 20+ lines' );
190 like( runperl( switches => ['-V'] ),
191 qr/\ASummary of my perl5 .*configuration:/,
194 # lookup a known config var
195 chomp( $r=runperl( switches => ['-V:osname'] ) );
196 is( $r, "osname='$^O';", 'perl -V:osname');
198 # lookup a nonexistent var
199 chomp( $r=runperl( switches => ['-V:this_var_makes_switches_test_fail'] ) );
200 is( $r, "this_var_makes_switches_test_fail='UNKNOWN';",
201 'perl -V:unknown var');
204 # platforms that don't like this quoting can either skip this test
205 # or fix test.pl _quote_args
206 $r = runperl( switches => ['"-V:i\D+size"'] );
207 # should be unlike( $r, qr/^$|not found|UNKNOWN/ );
208 like( $r, qr/^(?!.*(not found|UNKNOWN))./, 'perl -V:re got a result' );
210 # make sure each line we got matches the re
211 ok( !( grep !/^i\D+size=/, split /^/, $r ), '-V:re correct' );
217 local $TODO = ''; # these ones should work on VMS
219 my $v = sprintf "%vd", $^V;
221 like( runperl( switches => ['-v'] ),
222 qr/This is perl, v$v built for $Config{archname}.+Copyright.+Larry Wall.+Artistic License.+GNU General Public License/s,
230 local $TODO = ''; # these ones should work on VMS
232 like( runperl( switches => ['-h'] ),
233 qr/Usage: .+perl.+switches.+programfile.+arguments/,
238 # Tests for -z (which does not exist)
241 local $TODO = ''; # these ones should work on VMS
243 like( runperl( switches => ['-z'], stderr => 1 ),
244 qr/\QUnrecognized switch: -z (-h will show valid options)./,
245 '-z correctly unknown' );