Skip to content

Commit 9b28c5c

Browse files
committed
Flatten nested setup_call_cleanup calls in tests
When multiple process_create calls are needed in a test, each stream must have its own setup_call_cleanup wrapper. Previously used a single setup_call_cleanup with compound setup and cleanup goals, which is incorrect. Changed from: setup_call_cleanup( (create1, create2), test_body, (close2, close1) ) To proper nesting: setup_call_cleanup( create1, setup_call_cleanup( create2, test_body, close2 ), close1 ) This ensures proper cleanup order even if tests fail.
1 parent b57b8ef commit 9b28c5c

File tree

1 file changed

+34
-28
lines changed

1 file changed

+34
-28
lines changed

src/tests/get_n_chars.pl

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
atom_chars('/bin/echo', Echo),
1212
atom_chars('ABCDEFGHIJ', Content),
1313
iso_ext:setup_call_cleanup(
14-
( process:process_create(Echo, [Content], [stdout(pipe(Out1))]),
15-
process:process_create(Echo, [Content], [stdout(pipe(Out2))]) ),
16-
(
17-
charsio:get_n_chars(Out1, 5, Chars1),
18-
charsio:get_n_chars(Out2, 5, Chars2, 0),
19-
Chars1 = Chars2
14+
process:process_create(Echo, [Content], [stdout(pipe(Out1))]),
15+
iso_ext:setup_call_cleanup(
16+
process:process_create(Echo, [Content], [stdout(pipe(Out2))]),
17+
(
18+
charsio:get_n_chars(Out1, 5, Chars1),
19+
charsio:get_n_chars(Out2, 5, Chars2, 0),
20+
Chars1 = Chars2
21+
),
22+
close(Out2)
2023
),
21-
( close(Out2),
22-
close(Out1) )
24+
close(Out1)
2325
)
2426
)).
2527

@@ -28,18 +30,20 @@
2830
atom_chars('/bin/echo', Echo),
2931
atom_chars('Testing', Content),
3032
iso_ext:setup_call_cleanup(
31-
( process:process_create(Echo, [Content], [stdout(pipe(Out1))]),
32-
process:process_create(Echo, [Content], [stdout(pipe(Out2))]) ),
33-
(
34-
charsio:get_n_chars(Out1, N1, Chars1),
35-
charsio:get_n_chars(Out2, N2, Chars2, 0),
36-
N1 = N2,
37-
Chars1 = Chars2,
38-
N1 = 8,
39-
Chars1 = "Testing\n"
33+
process:process_create(Echo, [Content], [stdout(pipe(Out1))]),
34+
iso_ext:setup_call_cleanup(
35+
process:process_create(Echo, [Content], [stdout(pipe(Out2))]),
36+
(
37+
charsio:get_n_chars(Out1, N1, Chars1),
38+
charsio:get_n_chars(Out2, N2, Chars2, 0),
39+
N1 = N2,
40+
Chars1 = Chars2,
41+
N1 = 8,
42+
Chars1 = "Testing\n"
43+
),
44+
close(Out2)
4045
),
41-
( close(Out2),
42-
close(Out1) )
46+
close(Out1)
4347
)
4448
)).
4549

@@ -48,16 +52,18 @@
4852
atom_chars('/bin/echo', Echo),
4953
atom_chars('NegativeTest', Content),
5054
iso_ext:setup_call_cleanup(
51-
( process:process_create(Echo, [Content], [stdout(pipe(Out1))]),
52-
process:process_create(Echo, [Content], [stdout(pipe(Out2))]) ),
53-
(
54-
charsio:get_n_chars(Out1, N1, Chars1),
55-
charsio:get_n_chars(Out2, N2, Chars2, -100),
56-
N1 = N2,
57-
Chars1 = Chars2
55+
process:process_create(Echo, [Content], [stdout(pipe(Out1))]),
56+
iso_ext:setup_call_cleanup(
57+
process:process_create(Echo, [Content], [stdout(pipe(Out2))]),
58+
(
59+
charsio:get_n_chars(Out1, N1, Chars1),
60+
charsio:get_n_chars(Out2, N2, Chars2, -100),
61+
N1 = N2,
62+
Chars1 = Chars2
63+
),
64+
close(Out2)
5865
),
59-
( close(Out2),
60-
close(Out1) )
66+
close(Out1)
6167
)
6268
)).
6369

0 commit comments

Comments
 (0)