3 # Tests for the command-line switches
16 END { unlink @tmpfiles }
21 switches => [ '-0', ],
22 stdin => 'foo\0bar\0baz\0',
23 prog => 'print qq(<$_>) while <>',
25 is( $r, "<foo\0><bar\0><baz\0>", "-0" );
28 switches => [ '-l', '-0', '-p' ],
29 stdin => 'foo\0bar\0baz\0',
32 is( $r, "foo\nbar\nbaz\n", "-0 after a -l" );
35 switches => [ '-0', '-l', '-p' ],
36 stdin => 'foo\0bar\0baz\0',
39 is( $r, "foo\0bar\0baz\0", "-0 before a -l" );
42 switches => [ sprintf("-0%o", ord 'x') ],
43 stdin => 'fooxbarxbazx',
44 prog => 'print qq(<$_>) while <>',
46 is( $r, "<foox><barx><bazx>", "-0 with octal number" );
49 switches => [ '-00', '-p' ],
50 stdin => 'abc\ndef\n\nghi\njkl\nmno\n\npq\n',
51 prog => 's/\n/-/g;$_.=q(/)',
53 is( $r, 'abc-def--/ghi-jkl-mno--/pq-/', '-00 (paragraph mode)' );
56 switches => [ '-0777', '-p' ],
57 stdin => 'abc\ndef\n\nghi\njkl\nmno\n\npq\n',
58 prog => 's/\n/-/g;$_.=q(/)',
60 is( $r, 'abc-def--ghi-jkl-mno--pq-/', '-0777 (slurp mode)' );
64 my $filename = 'swctest.tmp';
66 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
68 BEGIN { print "block 1\n"; }
69 CHECK { print "block 2\n"; }
70 INIT { print "block 3\n"; }
72 END { print "block 5\n"; }
77 progfile => $filename,
80 # Because of the stderr redirection, we can't tell reliably the order
81 # in which the output is given
83 $r =~ /$filename syntax OK/
84 && $r =~ /\bblock 1\b/
85 && $r =~ /\bblock 2\b/
86 && $r !~ /\bblock 3\b/
87 && $r !~ /\bblock 4\b/
88 && $r !~ /\bblock 5\b/,
91 push @tmpfiles, $filename;
97 switches => [ sprintf("-l%o", ord 'x') ],
98 prog => 'print for qw/foo bar/'
100 is( $r, 'fooxbarx', '-l with octal number' );
105 switches => [ '-s' ],
106 prog => 'for (qw/abc def ghi/) {print defined $$_ ? $$_ : q(-)}',
107 args => [ '--', '-abc=2', '-def', ],
109 is( $r, '21-', '-s switch parsing' );
111 # Bug ID 20011106.084
112 $filename = 'swstest.tmp';
114 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
121 switches => [ '-s' ],
122 progfile => $filename,
123 args => [ '-x=foo' ],
125 is( $r, 'foo', '-s on the #! line' );
126 push @tmpfiles, $filename;
129 # Tests for -m and -M
131 $filename = 'swtest.pm';
133 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!",4 );
134 print $f <<'SWTESTPM';
136 sub import { print map "<$_>", @_ }
141 switches => [ '-Mswtest' ],
144 is( $r, '<swtest>', '-M' );
146 switches => [ '-Mswtest=foo' ],
149 is( $r, '<swtest><foo>', '-M with import parameter' );
151 switches => [ '-mswtest' ],
156 switches => [ '-mswtest=foo,bar' ],
159 is( $r, '<swtest><foo><bar>', '-m with import parameters' );
160 push @tmpfiles, $filename;