6 require Config; import Config;
9 use Test::More tests => 13;
11 # open::import expects 'open' as its first argument, but it clashes with open()
13 open::import( 'open', @_ );
16 # can't use require_ok() here, with a name like 'open'
17 ok( require 'open.pm', 'requiring open' );
21 like( $@, qr/needs explicit list of disciplines/,
22 'import should fail without args' );
24 # the hint bits shouldn't be set yet
25 is( $^H & $open::hint_bits, 0,
26 'hint bits should not be set in $^H before open import' );
28 # prevent it from loading I18N::Langinfo, so we can test encoding failures
30 $ENV{LC_ALL} = $ENV{LANG} = '';
31 eval { import( 'IN', 'locale' ) };
32 like( $@, qr/Cannot figure out an encoding/,
33 'no encoding should be found without $ENV{LANG} or $ENV{LC_ALL}' );
36 local $SIG{__WARN__} = sub {
40 # and it shouldn't be able to find this discipline
41 eval{ import( 'IN', 'macguffin' ) };
42 like( $warn, qr/Unknown discipline layer/,
43 'should warn about unknown discipline with bad discipline provided' );
45 # now load a real-looking locale
46 $ENV{LC_ALL} = ' .utf8';
47 import( 'IN', 'locale' );
48 is( ${^OPEN}, ":utf8\0",
49 'should set a valid locale layer' );
51 # and see if it sets the magic variables appropriately
52 import( 'IN', ':crlf' );
53 ok( $^H & $open::hint_bits,
54 'hint bits should be set in $^H after open import' );
55 is( $^H{'open_IN'}, 'crlf', 'should have set crlf layer' );
57 # it should reset them appropriately, too
58 import( 'IN', ':raw' );
59 is( $^H{'open_IN'}, 'raw', 'should have reset to raw layer' );
61 # it dies if you don't set IN, OUT, or IO
62 eval { import( 'sideways', ':raw' ) };
63 like( $@, qr/Unknown discipline class/, 'should croak with unknown class' );
65 # but it handles them all so well together
66 import( 'IO', ':raw :crlf' );
67 is( ${^OPEN}, ":raw :crlf\0:raw :crlf",
68 'should set multi types, multi disciplines' );
69 is( $^H{'open_IO'}, 'crlf', 'should record last layer set in %^H' );
72 skip("no perlio, no :utf8", 1) unless $Config{'useperlio'};
73 # the special :utf8 layer
79 is(ord(<I>), 0x100, ":utf8");
84 1 while unlink "utf8";
87 # the test cases beyond __DATA__ need to be executed separately
90 $ENV{LC_ALL} = 'nonexistent.euc';
91 eval { open::_get_locale_encoding() };
92 like( $@, qr/too ambiguous/, 'should die with ambiguous locale encoding' );
94 # the special :locale layer
95 $ENV{LANG} = 'ru_RU.KOI8-R';
96 # the :locale will probe the locale environment variables like LANG
97 use open OUT => ':locale';
99 print O chr(0x430); # Unicode CYRILLIC SMALL LETTER A = KOI8-R 0xc1
102 printf "%#x\n", ord(<I>), "\n"; # this should print 0xc1