3 # Tests for the command-line switches
10 skip_all_without_perlio();
11 skip_all_if_miniperl('-C and $ENV{PERL_UNICODE} are disabled on miniperl');
18 my $tmpfile = tempfile();
19 my $scriptfile = tempfile();
21 my $b = chr 256; utf8::encode $b;
23 $r = runperl( switches => [ '-CO', '-w' ],
24 prog => 'print chr(256)',
26 like( $r, qr/^$b(?:\r?\n)?$/s, '-CO: no warning on UTF-8 output' );
28 $r = runperl( switches => [ '-C2', '-w' ],
29 prog => 'print chr(256)',
31 like( $r, qr/^$b(?:\r?\n)?$/s, '-C2: no warning on UTF-8 output' );
34 if (exists $ENV{PERL_UNICODE} &&
35 ($ENV{PERL_UNICODE} eq "" || $ENV{PERL_UNICODE} =~ /[SO]/)) {
36 skip(qq[cannot test with PERL_UNICODE "" or /[SO]/], 1);
38 $r = runperl( switches => [ '-CI', '-w' ],
39 prog => 'print ord(<STDIN>)',
42 like( $r, qr/^256(?:\r?\n)?$/s, '-CI: read in UTF-8 input' );
45 $r = runperl( switches => [ '-CE', '-w' ],
46 prog => 'warn chr(256), qq(\n)',
48 like( $r, qr/^$b(?:\r?\n)?$/s, '-CE: UTF-8 stderr' );
50 $r = runperl( switches => [ '-Co', '-w' ],
51 prog => "open(F, q(>$tmpfile)); print F chr(256); close F",
53 like( $r, qr/^$/s, '-Co: auto-UTF-8 open for output' );
55 $r = runperl( switches => [ '-Ci', '-w' ],
56 prog => "open(F, q(<$tmpfile)); print ord(<F>); close F",
58 like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input' );
60 open(S, ">$scriptfile") or die("open $scriptfile: $!");
61 print S "open(F, q(<$tmpfile)); print ord(<F>); close F";
64 $r = runperl( switches => [ '-Ci', '-w' ],
65 progfile => $scriptfile,
67 like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input affects the current file' );
69 $r = runperl( switches => [ '-Ci', '-w' ],
70 prog => "do q($scriptfile)",
72 unlike( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input has file scope' );
74 $r = runperl( switches => [ '-CA', '-w' ],
75 prog => 'print ord shift',
77 args => [ chr(256) ] );
78 like( $r, qr/^256(?:\r?\n)?$/s, '-CA: @ARGV' );
80 $r = runperl( switches => [ '-CS', '-w' ],
81 progs => [ '#!perl -CS', 'print chr(256)'],
83 like( $r, qr/^$b(?:\r?\n)?$/s, '#!perl -C' );
85 $r = runperl( switches => [ '-CS' ],
86 progs => [ '#!perl -CS -w', 'print chr(256), !!$^W'],
88 like( $r, qr/^${b}1(?:\r?\n)?$/s, '#!perl -C followed by another switch' );
90 $r = runperl( switches => [ '-CS' ],
91 progs => [ '#!perl -C7 -w', 'print chr(256), !!$^W'],
94 $r, qr/^${b}1(?:\r?\n)?$/s,
95 '#!perl -C<num> followed by another switch'
98 $r = runperl( switches => [ '-CA', '-w' ],
99 progs => [ '#!perl -CS', 'print chr(256)' ],
101 like( $r, qr/^Too late for "-CS" option at -e line 1\.$/s,
102 '#!perl -C with different -C on command line' );
105 if (exists $ENV{PERL_UNICODE} && $ENV{PERL_UNICODE} =~ /S/) {
106 skip(qq[cannot test with PERL_UNICODE including "S"], 1);
108 $r = runperl( switches => [ '-w' ],
109 progs => [ '#!perl -CS', 'print chr(256)' ],
111 like( $r, qr/^Too late for "-CS" option at -e line 1\.$/s,
112 '#!perl -C but not command line' );
115 $r = runperl ( switches => [ '-C00' ],
118 like($r, qr/^Invalid number '00' for -C option\.$/s,
119 "perl -C00 [perl #123991]");