]> git.notmuchmail.org Git - notmuch/commitdiff
test-lib.sh: add test_valid_json
authorDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Tue, 28 Apr 2020 18:57:20 +0000 (14:57 -0400)
committerDavid Bremner <david@tethera.net>
Thu, 30 Apr 2020 20:57:16 +0000 (17:57 -0300)
This test does exactly what it says on the tin.  It expects JSON data
to be parseable by Python, at least.

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
test/test-lib.sh

index cb5bb8941b52cd230e80f43a533b07bdf2ee4fec..43fffa09c639a91b9461c0faea0a6bc9bcfd1d01 100644 (file)
@@ -524,6 +524,12 @@ test_expect_equal_json () {
     test_expect_equal "$output" "$expected" "$@"
 }
 
     test_expect_equal "$output" "$expected" "$@"
 }
 
+# Ensure that the argument is valid JSON data.
+test_valid_json () {
+    PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c "import sys, json; json.load(sys.stdin)" <<<"$1"
+    test_expect_equal "$?" 0
+}
+
 # Sort the top-level list of JSON data from stdin.
 test_sort_json () {
     PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c \
 # Sort the top-level list of JSON data from stdin.
 test_sort_json () {
     PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c \