summaryrefslogtreecommitdiff
path: root/t/run/switchC.t
blob: ba17cb91c1a32f5991fe97755c40fee97d1eca79 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!./perl -w

# Tests for the command-line switches

BEGIN {
    chdir 't' if -d 't';
    @INC = '../lib';
    unless (find PerlIO::Layer 'perlio') {
	print "1..0 # Skip: not perlio\n";
	exit 0;
    }
}

require "./test.pl";

plan(tests => 6);

my $r;

my @tmpfiles = ();
END { unlink @tmpfiles }

$r = runperl( switches => [ '-CO', '-w' ],
	      prog     => 'print chr(256)',
              stderr   => 1 );
is( $r, "\xC4\x80", '-CO: no warning on UTF-8 output' );

SKIP: {
    for my $l (qw(LC_ALL LC_CTYPE LANG)) {
	skip("cannot easily test under UTF-8 locale", 1)
	    if $ENV{$l} =~ /utf-?8/i;
    }
    $r = runperl( switches => [ '-CI', '-w' ],
		  prog     => 'print ord(<STDIN>)',
		  stderr   => 1,
		  verbose  => 1,
		  stdin    => "\xC4\x80" );
    is( $r, 256, '-CI: read in UTF-8 input' );
}

$r = runperl( switches => [ '-CE', '-w' ],
	      prog     => 'warn chr(256), qq(\n)',
              stderr   => 1 );
chomp $r;
is( $r, "\xC4\x80", '-CE: UTF-8 stderr' );

$r = runperl( switches => [ '-Co', '-w' ],
	      prog     => 'open(F, q(>out)); print F chr(256); close F',
              stderr   => 1 );
is( $r, '', '-Co: auto-UTF-8 open for output' );

push @tmpfiles, "out";

$r = runperl( switches => [ '-Ci', '-w' ],
	      prog     => 'open(F, q(<out)); print ord(<F>); close F',
              stderr   => 1 );
is( $r, 256, '-Ci: auto-UTF-8 open for input' );

$r = runperl( switches => [ '-CA', '-w' ],
	      prog     => 'print ord shift',
              stderr   => 1,
              args     => [ chr(256) ] );
is( $r, 256, '-CA: @ARGV' );