Skip to content

Commit fd2cdc2

Browse files
committed
Tests for reading from $*IN from threads.
Covers RT #124005.
1 parent 858b2e0 commit fd2cdc2

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

S16-io/handles-between-threads.t

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use v6;
22
use Test;
3+
use lib 't/spec/packages';
4+
use Test::Util;
35

4-
plan 6;
6+
plan 8;
57

68
my $filename = $*TMPDIR ~ '/tmp.' ~ $*PID ~ '-' ~ time;
79

@@ -14,3 +16,27 @@ my $rfh = await start { open($filename, :r) };
1416
is $rfh.get, 'abc', 'Can read handle in main thread opened in another thread';
1517
is (await start $rfh.get), 'def', 'Can read handle on thread pool';
1618
lives-ok { $rfh.close }, 'Can close handle on main thread after opening on another thread';
19+
20+
is_run('await start { say $*IN.get.uc for ^3 }',
21+
"foo\nbar\nbaz\n",
22+
{
23+
status => 0,
24+
out => "FOO\nBAR\nBAZ\n",
25+
err => "",
26+
},
27+
'reading from $*IN from another thread works (file)');
28+
29+
# RT #124005
30+
{
31+
my $temp-file = 'handle-between-threads-' ~ $*PID;
32+
spurt $temp-file, "foo";
33+
LEAVE unlink $temp-file;
34+
35+
my $cat = $*DISTRO.is-win ?? 'type' !! 'cat';
36+
my $quote = $*DISTRO.is-win ?? '"' !! "'";
37+
my $proc = shell(
38+
Q:s"$cat $temp-file | $*EXECUTABLE -e $quote await start { say get().uc } $quote",
39+
:out);
40+
is $proc.out.get, "FOO", 'reading from $*IN from another thread works (pipe)';
41+
so $proc.out.close;
42+
}

0 commit comments

Comments
 (0)