1#!./perl -w 2 3# Tests for the command-line switches 4 5BEGIN { 6 chdir 't' if -d 't'; 7 @INC = '../lib'; 8 require "./test.pl"; 9 10 skip_all_without_perlio(); 11 skip_all_if_miniperl('-C and $ENV{PERL_UNICODE} are disabled on miniperl'); 12} 13 14plan(tests => 13); 15 16my $r; 17 18my $tmpfile = tempfile(); 19my $scriptfile = tempfile(); 20 21my $b = pack("C*", unpack("U0C*", pack("U",256))); 22 23$r = runperl( switches => [ '-CO', '-w' ], 24 prog => 'print chr(256)', 25 stderr => 1 ); 26like( $r, qr/^$b(?:\r?\n)?$/s, '-CO: no warning on UTF-8 output' ); 27 28SKIP: { 29 if (exists $ENV{PERL_UNICODE} && 30 ($ENV{PERL_UNICODE} eq "" || $ENV{PERL_UNICODE} =~ /[SO]/)) { 31 skip(qq[cannot test with PERL_UNICODE "" or /[SO]/], 1); 32 } 33 $r = runperl( switches => [ '-CI', '-w' ], 34 prog => 'print ord(<STDIN>)', 35 stderr => 1, 36 stdin => $b ); 37 like( $r, qr/^256(?:\r?\n)?$/s, '-CI: read in UTF-8 input' ); 38} 39 40$r = runperl( switches => [ '-CE', '-w' ], 41 prog => 'warn chr(256), qq(\n)', 42 stderr => 1 ); 43like( $r, qr/^$b(?:\r?\n)?$/s, '-CE: UTF-8 stderr' ); 44 45$r = runperl( switches => [ '-Co', '-w' ], 46 prog => "open(F, q(>$tmpfile)); print F chr(256); close F", 47 stderr => 1 ); 48like( $r, qr/^$/s, '-Co: auto-UTF-8 open for output' ); 49 50$r = runperl( switches => [ '-Ci', '-w' ], 51 prog => "open(F, q(<$tmpfile)); print ord(<F>); close F", 52 stderr => 1 ); 53like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input' ); 54 55open(S, ">$scriptfile") or die("open $scriptfile: $!"); 56print S "open(F, q(<$tmpfile)); print ord(<F>); close F"; 57close S; 58 59$r = runperl( switches => [ '-Ci', '-w' ], 60 progfile => $scriptfile, 61 stderr => 1 ); 62like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input affects the current file' ); 63 64$r = runperl( switches => [ '-Ci', '-w' ], 65 prog => "do q($scriptfile)", 66 stderr => 1 ); 67unlike( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input has file scope' ); 68 69$r = runperl( switches => [ '-CA', '-w' ], 70 prog => 'print ord shift', 71 stderr => 1, 72 args => [ chr(256) ] ); 73like( $r, qr/^256(?:\r?\n)?$/s, '-CA: @ARGV' ); 74 75$r = runperl( switches => [ '-CS', '-w' ], 76 progs => [ '#!perl -CS', 'print chr(256)'], 77 stderr => 1, ); 78like( $r, qr/^$b(?:\r?\n)?$/s, '#!perl -C' ); 79 80$r = runperl( switches => [ '-CS' ], 81 progs => [ '#!perl -CS -w', 'print chr(256), !!$^W'], 82 stderr => 1, ); 83like( $r, qr/^${b}1(?:\r?\n)?$/s, '#!perl -C followed by another switch' ); 84 85$r = runperl( switches => [ '-CS' ], 86 progs => [ '#!perl -C7 -w', 'print chr(256), !!$^W'], 87 stderr => 1, ); 88like( 89 $r, qr/^${b}1(?:\r?\n)?$/s, 90 '#!perl -C<num> followed by another switch' 91); 92 93$r = runperl( switches => [ '-CA', '-w' ], 94 progs => [ '#!perl -CS', 'print chr(256)' ], 95 stderr => 1, ); 96like( $r, qr/^Too late for "-CS" option at -e line 1\.$/s, 97 '#!perl -C with different -C on command line' ); 98 99SKIP: { 100 if (exists $ENV{PERL_UNICODE} && $ENV{PERL_UNICODE} =~ /S/) { 101 skip(qq[cannot test with PERL_UNICODE including "S"], 1); 102 } 103 $r = runperl( switches => [ '-w' ], 104 progs => [ '#!perl -CS', 'print chr(256)' ], 105 stderr => 1, ); 106 like( $r, qr/^Too late for "-CS" option at -e line 1\.$/s, 107 '#!perl -C but not command line' ); 108} 109