test-lib.sh: add test_valid_json

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>
This commit is contained in:
Daniel Kahn Gillmor 2020-04-28 14:57:20 -04:00 committed by David Bremner
parent 92149485cb
commit 488e91f42b

View 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. # Sort the top-level list of JSON data from stdin.
test_sort_json () { test_sort_json () {
PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c \ PYTHONIOENCODING=utf-8 $NOTMUCH_PYTHON -c \