#!/usr/bin/env bash # # test-public-text-checks.sh # # Self-test of scripts/check-public-names.sh and scripts/check-comparative-prose.sh. # Each case feeds a check a fixture file (or a pattern list) and states the exit # status it must give: # - a hit exits 1, a clean file exits 0; # - an opt-out with a reason is honoured, and one with an empty reason (the # comment form ``, whose `-->` must not count as the # reason) is not; # - a pattern grep cannot compile exits 2, never "clean"; # - the products of WAI's maintainers are hits beside any private list, and # alone with --maintainer-products-only, which reads no private list. # The fixtures name a made-up company, never a real one, and the maintainers' # products, which check-public-names.sh lists itself. # # Exit status: 0 when every case gives its stated status, 1 otherwise. set -uo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" names="$REPO_ROOT/scripts/check-public-names.sh" prose="$REPO_ROOT/scripts/check-comparative-prose.sh" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT failures=0 in_dir() { # in_dir : run a command from another directory local d="$1" shift (cd "$d" && "$@") } names_file() { # names_file : the command exits 2 and its output names local f="$1" shift "$@" >"$tmp/named" 2>&1 local got=$? [ "$got" -eq 2 ] && grep -qF "$f" "$tmp/named" } expect() { # expect