-
Notifications
You must be signed in to change notification settings - Fork 78
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
testscript: 'cmp stdout want' diff seems backwards #187
Comments
Hi @bitfield, possibly related is the update feature uses the second argument to
(Random example usage). |
Good point @thepudds. Personally, I'm not convinced that auto-updating golden files is a wise idea:
TL;DR it should be a big deal to change the golden file. We shouldn't make it easier to do things it's not a good idea to do. But that's by the by. If |
Hi @bitfield
FWIW, I do use cmp with things other than stdout, including in some cases write results to a file that is then used with cmp. Perhaps rather than keying off of stdout/stderr, it could be that -update updates whichever cmp argument is present as a file in the testscript file. It already has logic I think to check if its second argument is present in the testscript file. (And perhaps -update could be a no-op or maybe even error if both arguments to cmp are files in the testscript file, which is also not the most useful comparison, or alternatively, in that case it could favor updating the second argument as it does today). But I haven't fully thought that through, so maybe that is flawed. 🙃 All that said, there's also a cost to diverging further from the testscript version that lives in the Go project... |
That works for me! |
Works for me too. This is straying from the issue, but I found the arguments above against Personally I quite like combining golden files with other independent (and manually updated) assurances. |
Consider the familiar:
which produces:
Now compare this to what
testscript
does:produces:
When you're accustomed to using
cmp.Diff(want, got)
, this looks backwards. It looks as though we expectedhello
, but gotgoodbye
, which is the opposite of what happened.To get a diff that appears the “right” way round, we'd need to write:
But that doesn't work:
Is there a reason why
stdout
isn't allowed to be used as the second argument tocmp
?The text was updated successfully, but these errors were encountered: