Skip to content

Commit 8b647d4

Browse files
jjtoltonclaude
andcommitted
Flatten nested setup_call_cleanup calls in tests
Replace nested setup_call_cleanup/3 calls with compound goals in setup and cleanup arguments, following Triska's feedback. Changed pattern from: setup_call_cleanup(A, setup_call_cleanup(B, Goal, close(Y)), close(X)) To: setup_call_cleanup((A,B), Goal, (close(Y), close(X))) Applied to tests 1-3 in src/tests/get_n_chars.pl. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 15b84f3 commit 8b647d4

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

src/tests/get_n_chars.pl

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,15 @@
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-
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)
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
2320
),
24-
close(Out1)
21+
( close(Out2),
22+
close(Out1) )
2523
)
2624
)).
2725

@@ -30,20 +28,18 @@
3028
atom_chars('/bin/echo', Echo),
3129
atom_chars('Testing', Content),
3230
iso_ext:setup_call_cleanup(
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)
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"
4540
),
46-
close(Out1)
41+
( close(Out2),
42+
close(Out1) )
4743
)
4844
)).
4945

@@ -52,18 +48,16 @@
5248
atom_chars('/bin/echo', Echo),
5349
atom_chars('NegativeTest', Content),
5450
iso_ext:setup_call_cleanup(
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)
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
6558
),
66-
close(Out1)
59+
( close(Out2),
60+
close(Out1) )
6761
)
6862
)).
6963

0 commit comments

Comments
 (0)