From 67bf19f2f55f3ed5c5674a48edb21fc1554a2217 Mon Sep 17 00:00:00 2001 From: Ben Davies Date: Wed, 1 Apr 2020 07:49:29 -0300 Subject: [PATCH] Update tests WRT IO::Socket::INET bind before connect --- S32-io/IO-Socket-INET-UNIX.t | 75 ++++++++++++++++------------- S32-io/socket-fail-invalid-values.t | 13 ++--- 2 files changed, 46 insertions(+), 42 deletions(-) diff --git a/S32-io/IO-Socket-INET-UNIX.t b/S32-io/IO-Socket-INET-UNIX.t index 8e74e2891b..988aee23d8 100644 --- a/S32-io/IO-Socket-INET-UNIX.t +++ b/S32-io/IO-Socket-INET-UNIX.t @@ -1,43 +1,52 @@ use v6; use Test; -plan 8; +plan 9; if $*DISTRO.is-win { skip-rest 'UNIX socket support on Windows NYI'; } else { - my IO::Socket::INET:_ $server; - my IO::Socket::INET:_ $client; - my IO::Socket::INET:_ $accepted; - my Str:D $host = $?FILE.IO.sibling('test.sock').Str; - my Str:D $sent = 'Hello, world!'; - my Str:_ $received; - LEAVE $host.IO.unlink if $host.IO.e; - - lives-ok { - $server = IO::Socket::INET.listen: $host, 0, family => PF_UNIX; - }, 'can create TCP UNIX socket servers'; - lives-ok { - $client = IO::Socket::INET.connect: $host, $server.localport, family => PF_UNIX; - }, 'can create TCP UNIX socket clients'; - lives-ok { - $accepted = $server.accept; - }, 'can accept connections to TCP UNIX socket servers'; - - lives-ok { - $client.print: $sent; - }, 'can write data to TCP UNIX sockets'; - lives-ok { - $received = $accepted.recv; - }, 'can receive data from TCP UNIX sockets...'; - is $received, $sent, '...which matches the original data sent'; - - lives-ok { - $client.close; - }, 'can close TCP UNIX socket clients'; - lives-ok { - $server.close; - }, 'can close TCP UNIX socket servers'; + my Str:D $host = $?FILE.IO.sibling('test.sock').Str; + + { + my IO::Socket::INET:_ $server; + my IO::Socket::INET:_ $client; + my IO::Socket::INET:_ $accepted; + my Str:D $sent = 'Hello, world!'; + my Str:_ $received; + LEAVE $host.IO.unlink if $host.IO.e; + + lives-ok { + $server = IO::Socket::INET.listen: $host, 0, family => PF_UNIX; + }, 'can create TCP UNIX socket servers'; + lives-ok { + $client = IO::Socket::INET.connect: $host, $server.localport, family => PF_UNIX; + }, 'can create TCP UNIX socket clients'; + lives-ok { + $accepted = $server.accept; + }, 'can accept connections to TCP UNIX socket servers'; + + lives-ok { + $client.print: $sent; + }, 'can write data to TCP UNIX sockets'; + lives-ok { + $received = $accepted.recv; + }, 'can receive data from TCP UNIX sockets...'; + is $received, $sent, '...which matches the original data sent'; + + lives-ok { + $client.close; + }, 'can close TCP UNIX socket clients'; + lives-ok { + $server.close; + }, 'can close TCP UNIX socket servers'; + } + + fails-like { + LEAVE $host.IO.unlink if $host.IO.e; + IO::Socket::INET.connect: $host, 0, :localhost, :family(PF_UNIX) + }, X::IO::Socket::Unsupported, + 'attempting to bind before connect with UNIX sockets fails'; } # vim: ft=perl6 diff --git a/S32-io/socket-fail-invalid-values.t b/S32-io/socket-fail-invalid-values.t index b8e0d83e00..265a63083f 100644 --- a/S32-io/socket-fail-invalid-values.t +++ b/S32-io/socket-fail-invalid-values.t @@ -14,15 +14,10 @@ constant PORT_VALUE_TOO_HIGH = 65_536; plan 4; -dies-ok &port-too-low, 'Fails when port is too low'; - -dies-ok &port-too-high, 'Fails when port is too high'; - -dies-ok &family-too-low, 'Fails when family is too low'; - -dies-ok &family-too-high, 'Fails when family is too high'; - -done-testing; +fails-like &port-too-low, X::AdHoc, 'Fails when port is too low'; +fails-like &port-too-high, X::AdHoc, 'Fails when port is too high'; +fails-like &family-too-low, X::AdHoc, 'Fails when family is too low'; +fails-like &family-too-high, X::AdHoc, 'Fails when family is too high'; sub port-too-low() { my $listen = IO::Socket::INET.new(