From a34bb1f9fad7c547eec5c254ce8274f190491186 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 2 Aug 2012 21:14:47 -0400 Subject: 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/search-output | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/search-output') diff --git a/test/search-output b/test/search-output index 8b57a43..c2a87eb 100755 --- a/test/search-output +++ b/test/search-output @@ -62,7 +62,7 @@ cat <EXPECTED "THREADID", "THREADID"] EOF -test_expect_equal_file OUTPUT EXPECTED +test_expect_equal_json "$(cat OUTPUT)" "$(cat EXPECTED)" test_begin_subtest "--output=messages" notmuch search --output=messages '*' >OUTPUT -- cgit v1.2.3