testscript: support writing to stdio from inside a custom command#140
testscript: support writing to stdio from inside a custom command#140matthewmueller wants to merge 2 commits intorogpeppe:masterfrom
Conversation
|
One thing that somewhat surprised me during testing was the need to do: ts.Stderr("")This was to make sure the previous command's stderr didn't linger. Another idea would be to adjust the API to: ts.Stdio(stdout, stderr)This would be slightly more cumbersome but ensure you don't forget to reset the other stream. |
|
Sorry for the silence; this package is effectively maintained by three people, so sometimes none of us takes the initiative with new features like this :) I agree that this is a limitation of the current API, and with @rogpeppe we've talked about this in the past. So I find it to be an entirely reasonable feature request to want to write to stdout - moving the command to the top level via As for the patch itself: first, I wonder if we need I also think the behavior of I think we have two options:
|
|
Also FYI @twpayne as we quite literally talked about this last week at the Go meetup in Zurich - how you can't move a top-level |
|
Hey, thanks for your response! I'm not actively using this fork anymore, so feel free to close. I no longer have the right context to know if allowing up to one or multiple calls makes more sense. Intuitively, I think your second option makes more sense, but I don't want you to make API decisions based on hunches :) |
|
Thanks for your response! I'll leave this open for now then, to see if someone else needs this. I personally don't have a need for it, so I don't have an urge to get it done, but I also don't think we need to close the issue and PR right away. |
|
Deciding to close this one to cleanup my open PRs view a bit. If someone needs this feel free to use this PR as a base! |
This PR allows you to write to stderr and stdout from within a custom command. For example,
Allowing you to have a test like this:
render 'index.gohtml' stdout '<h1>' ! stderr . -- index.gohtml -- <html> <body> <h1>{{.}}</h1> </body> </html>And
Closes #139