1#!/usr/bin/perl 2 3use strict; 4use warnings; 5 6use Test::More; 7 8plan tests => 3; 9 10use Errno qw( EINVAL ); 11 12# Keep this unit test in a file of its own because we need to override 13# connect() globally 14BEGIN { 15 *CORE::GLOBAL::connect = sub { $! = EINVAL; return undef }; 16} 17 18my $EINVAL_STR = do { local $! = EINVAL; "$!" }; 19 20use IO::Socket; 21 22# test that error strings turn up in both places 23my $sock = IO::Socket::INET->new( 24 PeerHost => "localhost", 25 PeerPort => 1, 26); 27my $e = $@; 28 29ok(!defined $sock, 'fails to connect with CORE::GLOBAL::connect override'); 30 31is($IO::Socket::errstr, "IO::Socket::INET: connect: $EINVAL_STR", 32 'error message appears in $IO::Socket::errstr'); 33is($e, "IO::Socket::INET: connect: $EINVAL_STR", 34 'error message appeared in $@'); 35