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', 'requiring open' );
20 like( $@, qr/needs explicit list of disciplines/,
21 'import should fail without args' );
23 # the hint bits shouldn't be set yet
24 is( $^H & $open::hint_bits, 0,
25 'hint bits should not be set in $^H before open import' );
27 # prevent it from loading I18N::Langinfo, so we can test encoding failures
29 $ENV{LC_ALL} = $ENV{LANG} = '';
30 eval { import( 'IN', 'locale' ) };
31 like( $@, qr/Cannot figure out an encoding/,
32 'no encoding should be found without $ENV{LANG} or $ENV{LC_ALL}' );
35 local $SIG{__WARN__} = sub {
39 # and it shouldn't be able to find this discipline
40 eval{ import( 'IN', 'macguffin' ) };
41 like( $warn, qr/Unknown discipline layer/,
42 'should warn about unknown discipline with bad discipline provided' );
44 # now load a real-looking locale
45 $ENV{LC_ALL} = ' .utf8';
46 import( 'IN', 'locale' );
47 is( ${^OPEN}, ':utf8\0',
48 'should set a valid locale layer' );
50 # and see if it sets the magic variables appropriately
51 import( 'IN', ':crlf' );
52 ok( $^H & $open::hint_bits,
53 'hint bits should be set in $^H after open import' );
54 is( $^H{'open_IN'}, 'crlf', 'should have set crlf layer' );
56 # it should reset them appropriately, too
57 import( 'IN', ':raw' );
58 is( $^H{'open_IN'}, 'raw', 'should have reset to raw layer' );
60 # it dies if you don't set IN, OUT, or INOUT
61 eval { import( 'sideways', ':raw' ) };
62 like( $@, qr/Unknown discipline class/, 'should croak with unknown class' );
64 # but it handles them all so well together
65 import( 'INOUT', ':raw :crlf' );
66 is( ${^OPEN}, ':raw :crlf\0:raw :crlf',
67 'should set multi types, multi disciplines' );
68 is( $^H{'open_INOUT'}, 'crlf', 'should record last layer set in %^H' );
71 # this one won't run as $locale_encoding is already set
72 # perhaps qx{} it, if it's important to run
73 $ENV{LC_ALL} = 'nonexistent.euc';
74 eval { open::_get_locale_encoding() };
75 like( $@, qr/too ambiguous/, 'should die with ambiguous locale encoding' );