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, these tests almost totally fail.
16 $TODO = "runperl() unable to emulate echo -n due to pipe bug" if $^O eq 'VMS';
20 END { unlink @tmpfiles }
25 switches => [ '-0', ],
26 stdin => 'foo\0bar\0baz\0',
27 prog => 'print qq(<$_>) while <>',
29 is( $r, "<foo\0><bar\0><baz\0>", "-0" );
32 switches => [ '-l', '-0', '-p' ],
33 stdin => 'foo\0bar\0baz\0',
36 is( $r, "foo\nbar\nbaz\n", "-0 after a -l" );
39 switches => [ '-0', '-l', '-p' ],
40 stdin => 'foo\0bar\0baz\0',
43 is( $r, "foo\0bar\0baz\0", "-0 before a -l" );
46 switches => [ sprintf("-0%o", ord 'x') ],
47 stdin => 'fooxbarxbazx',
48 prog => 'print qq(<$_>) while <>',
50 is( $r, "<foox><barx><bazx>", "-0 with octal number" );
53 switches => [ '-00', '-p' ],
54 stdin => 'abc\ndef\n\nghi\njkl\nmno\n\npq\n',
55 prog => 's/\n/-/g;$_.=q(/)',
57 is( $r, 'abc-def--/ghi-jkl-mno--/pq-/', '-00 (paragraph mode)' );
60 switches => [ '-0777', '-p' ],
61 stdin => 'abc\ndef\n\nghi\njkl\nmno\n\npq\n',
62 prog => 's/\n/-/g;$_.=q(/)',
64 is( $r, 'abc-def--ghi-jkl-mno--pq-/', '-0777 (slurp mode)' );
68 my $filename = 'swctest.tmp';
70 local $TODO = ''; # this one works on VMS
72 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
74 BEGIN { print "block 1\n"; }
75 CHECK { print "block 2\n"; }
76 INIT { print "block 3\n"; }
78 END { print "block 5\n"; }
80 close $f or die "Could not close: $!";
83 progfile => $filename,
86 # Because of the stderr redirection, we can't tell reliably the order
87 # in which the output is given
89 $r =~ /$filename syntax OK/
90 && $r =~ /\bblock 1\b/
91 && $r =~ /\bblock 2\b/
92 && $r !~ /\bblock 3\b/
93 && $r !~ /\bblock 4\b/
94 && $r !~ /\bblock 5\b/,
97 push @tmpfiles, $filename;
103 switches => [ sprintf("-l%o", ord 'x') ],
104 prog => 'print for qw/foo bar/'
106 is( $r, 'fooxbarx', '-l with octal number' );
111 switches => [ '-s' ],
112 prog => 'for (qw/abc def ghi/) {print defined $$_ ? $$_ : q(-)}',
113 args => [ '--', '-abc=2', '-def', ],
115 is( $r, '21-', '-s switch parsing' );
117 # Bug ID 20011106.084
118 $filename = 'swstest.tmp';
120 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!" );
125 close $f or die "Could not close: $!";
127 switches => [ '-s' ],
128 progfile => $filename,
129 args => [ '-x=foo' ],
131 is( $r, 'foo', '-s on the shebang line' );
132 push @tmpfiles, $filename;
135 # Tests for -m and -M
137 $filename = 'swtest.pm';
139 open my $f, ">$filename" or skip( "Can't write temp file $filename: $!",4 );
140 print $f <<'SWTESTPM';
142 sub import { print map "<$_>", @_ }
145 close $f or die "Could not close: $!";
147 switches => [ '-Mswtest' ],
150 is( $r, '<swtest>', '-M' );
152 switches => [ '-Mswtest=foo' ],
155 is( $r, '<swtest><foo>', '-M with import parameter' );
157 switches => [ '-mswtest' ],
162 local $TODO = ''; # this one works on VMS
166 switches => [ '-mswtest=foo,bar' ],
169 is( $r, '<swtest><foo><bar>', '-m with import parameters' );
170 push @tmpfiles, $filename;