This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Integrate:
[perl5.git] / t / run / switchC.t
1 #!./perl -w
2
3 # Tests for the command-line switches
4
5 BEGIN {
6     chdir 't' if -d 't';
7     @INC = '../lib';
8     unless (find PerlIO::Layer 'perlio') {
9         print "1..0 # Skip: not perlio\n";
10         exit 0;
11     }
12 }
13
14 require "./test.pl";
15
16 plan(tests => 6);
17
18 my $r;
19
20 my @tmpfiles = ();
21 END { unlink @tmpfiles }
22
23 $r = runperl( switches => [ '-CO', '-w' ],
24               prog     => 'print chr(256)',
25               stderr   => 1 );
26 like( $r, qr/^\xC4\x80(?:\r?\n)?$/s, '-CO: no warning on UTF-8 output' );
27
28 SKIP: {
29     if (exists $ENV{PERL_UNICODE} &&
30         ($ENV{PERL_UNICODE} eq "" || $ENV{PERL_UNICODE} =~ /[SO]/)) {
31         skip(qq[cannot test with PERL_UNICODE locale "" or /[SO]/], 1);
32     }
33     $r = runperl( switches => [ '-CI', '-w' ],
34                   prog     => 'print ord(<STDIN>)',
35                   stderr   => 1,
36                   stdin    => "\xC4\x80" );
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 );
43 like( $r, qr/^\xC4\x80(?:\r?\n)?$/s, '-CE: UTF-8 stderr' );
44
45 $r = runperl( switches => [ '-Co', '-w' ],
46               prog     => 'open(F, q(>out)); print F chr(256); close F',
47               stderr   => 1 );
48 like( $r, qr/^$/s, '-Co: auto-UTF-8 open for output' );
49
50 push @tmpfiles, "out";
51
52 $r = runperl( switches => [ '-Ci', '-w' ],
53               prog     => 'open(F, q(<out)); print ord(<F>); close F',
54               stderr   => 1 );
55 like( $r, qr/^256(?:\r?\n)?$/s, '-Ci: auto-UTF-8 open for input' );
56
57 $r = runperl( switches => [ '-CA', '-w' ],
58               prog     => 'print ord shift',
59               stderr   => 1,
60               args     => [ chr(256) ] );
61 like( $r, qr/^256(?:\r?\n)?$/s, '-CA: @ARGV' );
62