diff options
author | EuAndreh <eu@euandre.org> | 2021-08-02 11:10:57 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2021-08-02 13:44:56 -0300 |
commit | ba19418091917ff3bf6d5047ca098c96ede8ffc3 (patch) | |
tree | 498e8847ce8d9a2873d706aeb45f3f2ff2d6dd6a /aux | |
parent | src/gistatic.c: WIP implementation of repo_write_snapshots() (diff) | |
download | gistatic-ba19418091917ff3bf6d5047ca098c96ede8ffc3.tar.gz gistatic-ba19418091917ff3bf6d5047ca098c96ede8ffc3.tar.xz |
aux/assert-catgets.sh: Add, include in "check" target on Makefile; update gistatic.msg
Diffstat (limited to 'aux')
-rw-r--r-- | aux/assert-catgets.sh | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/aux/assert-catgets.sh b/aux/assert-catgets.sh new file mode 100644 index 0000000..885e186 --- /dev/null +++ b/aux/assert-catgets.sh @@ -0,0 +1,67 @@ +#!/bin/sh +set -eu + +assert_sequential_ids() { + awk ' + BEGIN { + n = 0 + } + + /^#define MSG_/ { + if (++n != $3) { + print "Bad sequential ID:" + printf "%s:%s:%s\n", FILENAME, NR, $0 + printf "expected: %s\ngot: %s\n", n, $3 + exit 1 + } + } + ' "$1" +} + +assert_consistent_msg_definitions() { + awk ' + BEGIN { + i = 0 + j = 0 + } + + /^#define MSG_/ { + defines[i++] = $2 + } + + /^\t\[MSG_/ { + msgs[j++] = substr($0, 3, index($0, "]") - 3) + } + + END { + for (n in defines) { + if (defines[n] != msgs[n]) { + printf "Order mismatch between #define" + printf " and usage in MSGS[]:\n" + printf "#define: %s\nMSGS[]: %s\n", + defines[n], msgs[n] + exit 1 + } + } + } + ' "$1" +} + +assert_no_unused_msgs() { + DEFINES="$(mktemp)" + USAGES="$(mktemp)" + awk '/^#define MSG_/ { print $2 }' "$f" | sort > "$DEFINES" + awk -F'_\\(' ' + /_\(MSG_/ { print substr($2, 0, index($2, ")") - 1) } + ' "$f" | sort | uniq > "$USAGES" + if ! diff "$DEFINES" "$USAGES"; then + echo 'Some defined MSG_ items not being used' >&2 + exit 1 + fi +} + +for f in "$@"; do + assert_sequential_ids "$f" + assert_consistent_msg_definitions "$f" + assert_no_unused_msgs "$f" +done |