summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <leonerd@leonerd.org.uk>2021-01-04 15:07:10 +0000
committerTony Cook <tony@develop-help.com>2021-01-04 21:46:42 +0000
commit8f107e8c8a9c7f9ab50acb269e4ea25c203279d9 (patch)
tree22c75c5134e83de0b41f566f072665d68ad0e999
parentaaedda86bf3baa31f82437e706c3bdb86b7db464 (diff)
downloadperl-8f107e8c8a9c7f9ab50acb269e4ea25c203279d9.tar.gz
Add a unit test that IO::Socket constructor uses error variables as specified
-rw-r--r--MANIFEST1
-rw-r--r--dist/IO/t/io_sock_errstr.t34
2 files changed, 35 insertions, 0 deletions
diff --git a/MANIFEST b/MANIFEST
index 53c500da8d..dcd03aa938 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -3716,6 +3716,7 @@ dist/IO/t/io_pipe.t See if pipe()-related methods from IO work
dist/IO/t/io_poll.t See if poll()-related methods from IO work
dist/IO/t/io_sel.t See if select()-related methods from IO work
dist/IO/t/io_sock.t See if INET socket-related methods from IO work
+dist/IO/t/io_sock_errstr.t See if socket constructors put error string in the right place
dist/IO/t/io_taint.t See if the untaint method from IO works
dist/IO/t/io_tell.t See if seek()/tell()-related methods from IO work
dist/IO/t/io_udp.t See if UDP socket-related methods from IO work
diff --git a/dist/IO/t/io_sock_errstr.t b/dist/IO/t/io_sock_errstr.t
new file mode 100644
index 0000000000..dc75c44fad
--- /dev/null
+++ b/dist/IO/t/io_sock_errstr.t
@@ -0,0 +1,34 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More;
+
+plan tests => 3;
+
+use Errno qw( EINVAL );
+
+# Keep this unit test in a file of its own because we need to override
+# connect() globally
+BEGIN {
+ *CORE::GLOBAL::connect = sub { $! = EINVAL; return undef };
+}
+
+my $EINVAL_STR = do { local $! = EINVAL; "$!" };
+
+use IO::Socket;
+
+# test that error strings turn up in both places
+my $sock = IO::Socket::INET->new(
+ PeerHost => "localhost",
+ PeerPort => 1,
+);
+my $e = $@;
+
+ok(!defined $sock, 'fails to connect with CORE::GLOBAL::connect override');
+
+is($IO::Socket::errstr, "IO::Socket::INET: connect: $EINVAL_STR",
+ 'error message appears in $IO::Socket::errstr');
+is($e, "IO::Socket::INET: connect: $EINVAL_STR",
+ 'error message appeared in $@');