Skip to content

Commit 8b5d139

Browse files
committed
Add test.
1 parent 7fa0bfe commit 8b5d139

3 files changed

Lines changed: 42 additions & 0 deletions

File tree

src/pipe.toit

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ class OpenPipe_ implements Stream:
152152

153153
read_ -> ByteArray?:
154154
while true:
155+
if not state_: return null
155156
state_.wait-for-state READ-EVENT_ | CLOSE-EVENT_
156157
if not state_: return null
157158
result := read-from-pipe_ resource_

tests/pipe3_exe.toit

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (C) 2025 Toit contributors.
2+
// Use of this source code is governed by a Zero-Clause BSD license that can
3+
// be found in the tests/TESTS_LICENSE file.
4+
5+
import host.pipe
6+
7+
main:
8+
// Just wait for a message.
9+
pipe.stdin.in.read

tests/pipe3_test.toit

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (C) 2025 Toit contributors.
2+
// Use of this source code is governed by a Zero-Clause BSD license that can
3+
// be found in the tests/TESTS_LICENSE file.
4+
5+
import expect show *
6+
7+
import host.pipe
8+
import system
9+
10+
main args:
11+
toit-exe := args[0]
12+
13+
my-path := system.program-path
14+
end := my-path.index-of --last "test.toit"
15+
if end == -1: throw "UNEXPECTED"
16+
input := "$my-path[..end]input.toit"
17+
18+
process := pipe.fork
19+
--create-stdout
20+
--create-stdin
21+
toit-exe
22+
[toit-exe, input]
23+
24+
to-process := process.stdin
25+
from-process := process.stdout
26+
27+
from-process.close
28+
29+
expect-null from-process.in.read
30+
to-process.out.write "done"
31+
32+
process.wait

0 commit comments

Comments
 (0)