-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Calling t.Fatal inside a testscript command results in a panic #173
Comments
Another repro:
|
I think you're looking for https://pkg.go.dev/github.com/rogpeppe/[email protected]/testscript#TestScript.Fatalf. |
@bitfield this fixes your example:
|
@myitcv |
I initially filed the issue against Here you can see the failure using |
Reiterating what I said on Slack, to not lose it: the problem is that the example uses the go-internal/testscript/testscript.go Lines 247 to 250 in 2431384
|
@datacharmer - apologies, I skim read your initial description far too quickly. Ah I see. I think this probably falls outside the scope of |
Thanks @myitcv , @mvdan for your answers. What about future improvements?
|
One reason not to do it that comes to mind is that the UX will be worse; note that the current go-internal/testscript/testscript.go Lines 785 to 788 in 2431384
The same applies to I'm still not sure whether or not we should do this to be honest. My only general feeling is that I've been okay without using any testing libraries or frameworks when writing testscript commands. After all, they are little main-like programs, they aren't really meant to be tests themselves. |
Fair enough. |
Yeah, I think mentioning this in the docs is worthwhile. An alternative, to avoid the footgun entirely, would be to recommend shadowing the parent
|
This makes sense, but I can see a danger of some confusion, because custom commands in Now we know that the right way to do that is to call As ever, when you're the one in this situation making a forgivable mistake, being told that you're holding it wrong is somehow unsatisfactory. It's a good idea to mention in the docs that this won't work, as you say, but even that isn't really enough, because (sad to relate) people don't read documentation until they've already had a problem. We can't avoid the Beyond that, we probably need an executive decision: going forward, will |
When t.Fatal (or a derived quickest or testify assertion) is called on a failing comparison within a custom command in
testscript
it panics. By contrast, when usingtestscript.Fatalf
, the test exits regularly.How to reproduce:
sample run
Using
ts.Fatalf
works as expectedI don't know if this is a bug or an incorrect usage from my side.
I'd like it to know how to address it, as I plan to use quickest or a similar testing library in a larger project where this usage would be common (See this blog post for more detail.)
The text was updated successfully, but these errors were encountered: