8 use Test::More tests => 12;
10 # open::import expects 'open' as its first argument, but it clashes with open()
12 open::import( 'open', @_ );
15 # can't use require_ok() here, with a name like 'open'
16 ok( require 'open.pm', 'require' );
20 like( $@, qr/needs explicit list of disciplines/, 'import fails without args' );
22 # the hint bits shouldn't be set yet
23 is( $^H & $open::hint_bits, 0, '$^H is okay before open import runs' );
25 # prevent it from loading I18N::Langinfo, so we can test encoding failures
27 undef @ENV{qw(LC_ALL LANG LANGUAGE)};
28 eval { import( 'IN', 'locale' ) };
29 like( $@, qr/Cannot figure out an encoding/, 'no encoding found' );
32 local $SIG{__WARN__} = sub {
36 # and it shouldn't be able to find this discipline
37 eval{ import( 'IN', 'macguffin' ) };
38 like( $warn, qr/Unknown discipline layer/, 'warned about unknown discipline' );
40 # now load a real-looking locale
41 $ENV{LC_ALL} = ' .utf8';
42 import( 'IN', 'locale' );
43 is( ${^OPEN}, ':utf8\0', 'set locale layer' );
45 # and see if it sets the magic variables appropriately
46 import( 'IN', ':crlf' );
47 ok( $^H & $open::hint_bits, '$^H is set after open import runs' );
48 is( $^H{'open_IN'}, 'crlf', 'set crlf layer' );
50 # it should reset them appropriately, too
51 import( 'IN', ':raw' );
52 is( $^H{'open_IN'}, 'raw', 'set raw layer' );
54 # it dies if you don't set IN, OUT, or INOUT
55 eval { import( 'sideways', ':raw' ) };
56 like( $@, qr/Unknown discipline class/, 'croaked with unknown class' );
58 # but it handles them all so well together
59 import( 'INOUT', ':raw :crlf' );
60 is( ${^OPEN}, ':raw :crlf\0:raw :crlf', 'multi types, multi disciplines' );
61 is( $^H{'open_INOUT'}, 'crlf', 'last layer set in %^H' );
64 # this one won't run as $locale_encoding is already set
65 # perhaps qx{} it, if it's important to run
66 $ENV{LC_ALL} = 'nonexistent.euc';
67 eval { open::_get_locale_encoding() };
68 like( $@, qr/too ambiguous/, 'died with ambiguous locale encoding' );