@@ -8,6 +8,9 @@ import host.os
88import host.file
99import semver
1010
11+ import .utils
12+
13+ tt [block ]: block .call
1114main args :
1215 if args .size < 1 :
1316 print "Usage: block_std_test.toit <toit_exe>"
@@ -17,51 +20,47 @@ main args:
1720 print "Cannot find toit file 'block_stdout_child.toit' in tests directory"
1821 exit 1
1922
20- if not file .is-file "tests/block_stdin_child.toit" :
21- print "Cannot find toit file 'block_stdin_child.toit' in tests directory"
22- exit 1
23-
2423 toit-exe := args [ 0 ]
2524
26- // Try to run the toit executable.
27- exception := catch : pipe .backticks toit-exe "--version"
28- if exception :
29- print "Running the given toit executable '$ toit-exe ' failed: $ exception "
30- exit 1
25+ // check-toit-exe toit-exe
26+
27+ with-compiled --toit-exe = toit-exe "tests/block_stdout_child.toit" : | compiled-path / string |
28+ // We use an executable, so that we don't see compilation warnings of the child program.
3129
32- [ "close" , "write" ] .do : | action |
33- subprocess := pipe .fork
34- --create-stdout
35- --create-stderr
36- toit-exe
37- [ toit-exe , "tests/block_stdout_child.toit" , action ]
30+ [ "close" , "write" ] .do : | action |
31+ print "Running $ compiled-path $ action "
32+ subprocess := pipe .fork
33+ --create-stdout
34+ --create-stderr
35+ compiled-path
36+ [ compiled-path , action ]
3837
39- subprocess-stdout := subprocess .stdout
40- subprocess-stderr := subprocess .stderr
38+ subprocess-stdout := subprocess .stdout
39+ subprocess-stderr := subprocess .stderr
4140
42- // Get the stderr first even though the subproces is blocking on stdout.
43- print "Waiting for read of child stderr."
44- line := subprocess-stderr .in .read
45- // If this gets the wrong message then the buffer on stdout is too big and
46- // we need to increase the size of the loop in block_stdout_child.toit.
47- if action == "close" :
48- if line != null : print "<$ line.to-string >"
49- expect-equals null line
50- print "Close woke up the task."
51- else:
52- expect-equals "Message through stderr." line .to-string
53- print "$ line.to-string "
54- task ::
55- while read := subprocess-stdout .in .read :
56- null
57- if action != "close" :
58- line = subprocess-stderr .in .read
59- expect-equals "Done with stdout." line .to-string
60- print "$ line.to-string "
41+ // Get the stderr first even though the subproces is blocking on stdout.
42+ print "Waiting for read of child stderr."
43+ line := subprocess-stderr .in .read
44+ // If this gets the wrong message then the buffer on stdout is too big and
45+ // we need to increase the size of the loop in block_stdout_child.toit.
46+ if action == "close" :
47+ if line != null : print "<$ line.to-string >"
48+ expect-equals null line
49+ print "Close woke up the task."
50+ else:
51+ expect-equals "Message through stderr." line .to-string
52+ print "$ line.to-string "
53+ task ::
54+ while read := subprocess-stdout .in .read :
55+ null
56+ if action != "close" :
57+ line = subprocess-stderr .in .read
58+ expect-equals "Done with stdout." line .to-string
59+ print "$ line.to-string "
6160
62- exit-value := subprocess .wait
63- expect-equals 0
64- pipe .exit-code exit-value
65- expect-equals null
66- pipe .exit-signal exit-value
67- print "OK exit"
61+ exit-value := subprocess .wait
62+ expect-equals 0
63+ pipe .exit-code exit-value
64+ expect-equals null
65+ pipe .exit-signal exit-value
66+ print "OK exit"
0 commit comments