-
Notifications
You must be signed in to change notification settings - Fork 37.8k
test: Add format-dependent comparison to bctest #9032
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
Conversation
utAck, seems useful! |
Yes, makes sense. I should have included something like this when I added the json tests. I think #9023 (which outputs a contextual diff for failing test cases) should make it much easier to track down formatting errors, since it'll point you to the exact line that's different. However, I think this is still useful for verifying that the output is indeed valid json. Only nit is that
It'd be nice to wrap the json calls in try/except, and maybe have the final else branch of |
Yea, that error 'Invalid control character at: line 3 column 14 (char 95)" is actually very good and specific. The only thing missing is context of what file it occurs in. Would make sense to print it with the filename.
I too think #9023 is useful, and we should do that too, however this solves a different issue: say the JSON library is changed to pretty-print slightly differently. JSON itself is defined by a standard, but pretty-printing is not. This verifies separately that the functional part (the data) still matches. Once you now that, you can harmlessly copy the new formatting if you agree with it. |
if fmt == 'json': # json: compare parsed data | ||
match = (json.loads(a) == json.loads(b)) | ||
elif fmt == 'hex': # hex: parse and compare binary data | ||
match = (binascii.a2b_hex(a.rstrip()) == binascii.a2b_hex(b.rstrip())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this rstripped rather than stripped? Is there a case where you want to fail here if leading whitespace differs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leading whitespace is much harder to accidentally introduce than trailing whitespace (e.g. trailing spaces, newlines etc). But I'm fine with changing this to strip() instead.
c481fcf
to
1b431c4
Compare
|
This splits the output comparison for `bitcoin-tx` into two steps: - First, check for data mismatch, parsing the data as json or hex depending on the extension of the output file - Then, check if the literal string matches For either of these cases give a different error. This prevents wild goose chases when e.g. a trailing space doesn't match exactly, and makes sure that both test output and examples are valid data of the purported format.
1b431c4
to
6c5cd9d
Compare
Looks good. Tested ACK |
utACK 6c5cd9d |
6c5cd9d test: Add format-dependent comparison to bctest (Wladimir J. van der Laan)
6c5cd9d test: Add format-dependent comparison to bctest (Wladimir J. van der Laan)
6c5cd9d test: Add format-dependent comparison to bctest (Wladimir J. van der Laan)
6c5cd9d test: Add format-dependent comparison to bctest (Wladimir J. van der Laan)
bitcoin-util-test.py backports Cherry-picked from the following upstream PRs: - bitcoin/bitcoin#8829 - bitcoin/bitcoin#8830 - bitcoin/bitcoin#8836 - bitcoin/bitcoin#8881 - bitcoin/bitcoin#9032 - bitcoin/bitcoin#9023 - bitcoin/bitcoin#9069 - bitcoin/bitcoin#9945
This splits the output comparison for
bitcoin-tx
into two steps:For either of these cases give a different error.
This prevents wild goose chases when e.g. a trailing space doesn't match exactly (by helping narrow down the problem), and makes sure that both test output and examples are valid data of the purported format.