summaryrefslogtreecommitdiff
path: root/devtools
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-03-31 07:28:29 -0400
committerEric S. Raymond <esr@thyrsus.com>2015-03-31 07:28:29 -0400
commite1357f361f8ac8c8a915e8714031b232b7677b7c (patch)
tree9befa8d6e75baa84f2d8fcf4de15b0bfe500fae0 /devtools
parente8f3294206741dd41a2302c4fef30af34f2c9822 (diff)
downloadgpsd-e1357f361f8ac8c8a915e8714031b232b7677b7c.tar.gz
Move a test utility where it belongs, and document it.
Diffstat (limited to 'devtools')
-rw-r--r--devtools/README5
-rwxr-xr-xdevtools/test_json_validity.py23
2 files changed, 28 insertions, 0 deletions
diff --git a/devtools/README b/devtools/README
index 0d482055..ebed2da4 100644
--- a/devtools/README
+++ b/devtools/README
@@ -108,3 +108,8 @@ this itself now, so this script has a lot of dust on it.
Generate most of the code required to support a message type from
AIVDM message layout tables. Also, redo their bit offsets to be
conformant with field lengths.
+
+== test_json_validity.py ==
+
+Test a file full of lines containing GPSD-JSON reports to verify that each
+line is in fact well-formed JSON.
diff --git a/devtools/test_json_validity.py b/devtools/test_json_validity.py
new file mode 100755
index 00000000..7423c553
--- /dev/null
+++ b/devtools/test_json_validity.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python
+#
+# Christian Gagneraud - 2012
+# Simple python script that will parse json dictionaries on its input,
+# If it fails, it will print the offending line and an error message.
+# The goal is to check that GPSD outputs valid JSON.
+#
+
+import json, sys
+
+success = True
+lc = 0
+for line in sys.stdin.readlines():
+ lc += 1
+ try:
+ # Load the json dictionary, it should raise an error if it is malformed
+ item = json.loads(line)
+ except ValueError as e:
+ success = False
+ print "%d: %s" % (lc, line.strip())
+ print "%d: %s" % (lc, e)
+
+exit(0 if success else 1)