8 if (ord('A') == 193 && !eval "require Convert::EBCDIC") {
9 print "1..0 # EBCDIC but no Convert::EBCDIC\n"; exit 0;
19 $ENV{HOME} = Cwd::cwd();
21 # avoid "used only once" warning
22 local (*CORE::GLOBAL::getpwuid, *CORE::GLOBAL::stat);
24 *CORE::GLOBAL::getpwuid = sub ($) {
25 ((undef) x 7, Cwd::cwd());
30 *CORE::GLOBAL::stat = sub (*) {
35 $INC{'FileHandle.pm'} = 1;
37 (my $libnet_t = __FILE__) =~ s/\w+.t$/libnet_t.pl/;
40 # now that the tricks are out of the way...
41 eval { require Net::Netrc; };
42 ok( !$@, 'should be able to require() Net::Netrc safely' );
43 ok( exists $INC{'Net/Netrc.pm'}, 'should be able to use Net::Netrc' );
46 skip('incompatible stat() handling for OS', 4), next SKIP
47 if ($^O =~ /os2|win32|macos|cygwin/i);
50 local $SIG{__WARN__} = sub {
54 # add write access for group/other
56 ok( !defined(Net::Netrc::_readrc()),
57 '_readrc() should not read world-writable file' );
58 ok( $warn =~ /^Bad permissions/, '... and should warn about it' );
60 # the owner field should still not match
62 ok( !defined(Net::Netrc::_readrc()),
63 '_readrc() should not read file owned by someone else' );
64 ok( $warn =~ /^Not owner/, '... and should warn about it' );
67 # this field must now match, to avoid the last-tested warning
70 # this curious mix of spaces and quotes tests a regex at line 79 (version 2.11)
71 FileHandle::set_lines(split(/\n/, <<LINES));
75 login nigol "password" drowssap
76 machine foo "login" l2
79 default login "baz" password p2
80 default "login" baz password p3
84 # having set several lines and the uid, this should succeed
85 is( Net::Netrc::_readrc(), 1, '_readrc() should succeed now' );
87 # on 'foo', the login is 'nigol'
88 is( Net::Netrc->lookup('foo')->{login}, 'nigol',
89 'lookup() should find value by host name' );
91 # on 'foo' with login 'l2', the password is 'p2'
92 is( Net::Netrc->lookup('foo', 'l2')->{password}, 'p2',
93 'lookup() should find value by hostname and login name' );
95 # the default password is 'p3', as later declarations have priority
96 is( Net::Netrc->lookup()->{password}, 'p3',
97 'lookup() should find default value' );
99 # lookup() ignores the login parameter when using default data
100 is( Net::Netrc->lookup('default', 'baz')->{password}, 'p3',
101 'lookup() should ignore passed login when searching default' );
103 # lookup() goes to default data if hostname cannot be found in config data
104 is( Net::Netrc->lookup('abadname')->{login}, 'baz',
105 'lookup() should use default for unknown machine name' );
107 # now test these accessors
108 my $instance = bless({}, 'Net::Netrc');
109 for my $accessor (qw( login account password )) {
110 is( $instance->$accessor(), undef,
111 "$accessor() should return undef if $accessor is not set" );
112 $instance->{$accessor} = $accessor;
113 is( $instance->$accessor(), $accessor,
114 "$accessor() should return value when $accessor is set" );
117 # and the three-for-one accessor
118 is( scalar( () = $instance->lpa()), 3,
119 'lpa() should return login, password, account');
120 is( join(' ', $instance->lpa), 'login password account',
121 'lpa() should return appropriate values for l, p, and a' );
126 tie *FH, 'FileHandle', @_;
131 my ($class, undef, $file, $mode) = @_;
132 bless({ file => $file, mode => $mode }, $class);