Skip to content

Commit

Permalink
Use Test::Util's &make-temp-path for socket tests
Browse files Browse the repository at this point in the history
This deduplicates some temporary file logic (and probably generates
"better" file names).

The main part of the patch was written by @Kaiepi -- see
Raku#732. The only difference in this
commit is the usage of an absolute path, instead of changing to
$*TMPDIR and using a relative path. That's necessary because the
C code that actually creates the socket file doesn't get its
current working directory changed.
  • Loading branch information
usev6 committed Feb 5, 2023
1 parent 0d696f4 commit 9da735c
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions S32-io/IO-Socket-INET-UNIX.t
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use v6;
use lib $?FILE.IO.parent.sibling: 'packages/Test-Helpers/lib';
use Test;
use Test::Util;

plan 8;

Expand All @@ -9,10 +11,9 @@ if $*DISTRO.is-win {
my IO::Socket::INET:_ $server;
my IO::Socket::INET:_ $client;
my IO::Socket::INET:_ $accepted;
my Str:D $host = $*TMPDIR.add("test-$*PID.sock").Str;
my Str:D $host = make-temp-path.absolute;
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;
Expand All @@ -38,6 +39,8 @@ if $*DISTRO.is-win {
lives-ok {
$server.close;
}, 'can close TCP UNIX socket servers';

# Test::Util takes care of cleanup.
}

# vim: expandtab shiftwidth=4

0 comments on commit 9da735c

Please sign in to comment.