]> git.notmuchmail.org Git - notmuch/commit
test: Uniformly canonicalize actual and expected JSON
authorAustin Clements <amdragon@MIT.EDU>
Fri, 3 Aug 2012 01:14:47 +0000 (21:14 -0400)
committerDavid Bremner <bremner@debian.org>
Fri, 3 Aug 2012 23:14:47 +0000 (20:14 -0300)
commita34bb1f9fad7c547eec5c254ce8274f190491186
tree89f47c327269cb08770cadafb6e0be38eded45fc
parent46446158fd4da1f06f6f0c00acd5fff611afaf48
test: Uniformly canonicalize actual and expected JSON

Previously, we used a variety of ad-hoc canonicalizations for JSON
output in the test suite, but were ultimately very sensitive to JSON
irrelevancies such as whitespace.  This introduces a new test
comparison function, test_expect_equal_json, that first pretty-prints
*both* the actual and expected JSON and the compares the result.

The current implementation of this simply uses Python's json.tool to
perform pretty-printing (with a fallback to the identity function if
parsing fails).  However, since the interface it introduces is
semantically high-level, we could swap in other mechanisms in the
future, such as another pretty-printer or something that does not
re-order object keys (if we decide that we care about that).

In general, this patch does not remove the existing ad-hoc
canonicalization because it does no harm.  We do have to remove the
newline-after-comma rule from notmuch_json_show_sanitize and
filter_show_json because it results in invalid JSON that cannot be
pretty-printed.

Most of this patch simply replaces test_expect_equal and
test_expect_equal_file with test_expect_equal_json.  It changes the
expected JSON in a few places where sanitizers had placed newlines
after commas inside strings.
test/crypto
test/json
test/maildir-sync
test/multipart
test/search-output
test/test-lib.sh