I have a number of tests that spawn a child process - it is a binary outside my control. I'm using processman::spawn, but it could easily be just 'exec'.anyway). And suddenly I end up with test reports like this:
This process prints something to stderr.
While I was using -singleproc 1, this wasn't a problem. However, later I realized that in this mode, global variables created by one .test script will be inherited by other .test scripts. So, I decided to switch to -singleproc 0 (that is the default
Test file error: <stderr output from my child process>
...
Tests ended at Wed Nov 23 11:30:44 CET 2022
all.tcl: Total 9 Passed 9 Skipped 0 Failed 0 Sourced 1 Test Files.
Test files exiting with errors:
pubsub.test
also $? is 1.
So, tcltest believes that some tests failed just because they happen to print something to stderr!
I looked in the source code, and it doesn't look like I can configure this behaviour, because in essence it is:
if {!$singleProcess} {
catch { open shell } error
So, apparently 'open' throws an error and then catch's handler counts the test as failed.
could somebody point me to how I can avoid this?
thanks in advance
* Emiliano Gavilán
| You can get stdout and stderr from the child process using [chan pipe].
| The magic incantation is
| lassign [chan pipe] ir iw
| lassign [chan pipe] er ew
| exec {*}[list $progname $param1 $param2 ...] >@ $iw 2>@ $ew
| chan close $iw
| chan close $ew
| Now you can use either [chan read] or [chan gets] to get the child process | data from $ir and $er handlers.
Cool trick, thanks for pointing that out!
However, if large amount of data is produced (notably more than the OS
pipes buffer) there is a chance of deadlock here, since TCL waits for
the 'exec' to finish, while the exec'd process might be blocked waiting
for the pipe to be read, no? (I think this could be avoided by using
[open |$cmd 2>@...] with only the pipe for stderr.)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 497 |
Nodes: | 16 (2 / 14) |
Uptime: | 18:31:27 |
Calls: | 9,785 |
Calls today: | 4 |
Files: | 13,749 |
Messages: | 6,187,729 |