#!/usr/bin/env bash # Tests for fonts.sh's checks and for the release gate that uses them. None # needs the network: every case fails before a download would start. Run # directly: # hack/fonts_test.sh set -uo pipefail here=$(cd -- "$(dirname -- "$0")" && pwd) root=$(cd -- "$here/.." && pwd) work=$(mktemp -d) trap 'rm -rf "$work"' EXIT fails=0 fail() { echo "FAIL: $*"; fails=$((fails + 1)); } # A copy of the script in a tree of its own, so nothing touches the real # font directory. mkdir -p "$work/hack" "$work/internal/look/static/fonts/timeless" cp "$here/fonts.sh" "$work/hack/fonts.sh" font=$work/internal/look/static/fonts/timeless/1.094/TimelessSansVF.woff2 # check: a missing font fails. if out=$(sh "$work/hack/fonts.sh" check 2>&1); then fail "check passed with no font: $out" elif ! printf '%s' "$out" | grep -q "not there"; then fail "check without a font said: $out" fi # check: a file that is not the pinned font fails. mkdir -p "$(dirname "$font")" printf 'not a font' >"$font" if out=$(sh "$work/hack/fonts.sh" check 2>&1); then fail "check passed a wrong file: $out" elif ! printf '%s' "$out" | grep -q "checksum mismatch"; then fail "check of a wrong file said: $out" fi # fetch: a wrong file already there is refused, not kept as the font. if out=$(sh "$work/hack/fonts.sh" 2>&1); then fail "fetch kept a wrong file: $out" elif ! printf '%s' "$out" | grep -q "checksum mismatch"; then fail "fetch with a wrong file said: $out" fi # The real font, when this machine has fetched it, passes. real=$root/internal/look/static/fonts/timeless/1.094/TimelessSansVF.woff2 if [ -f "$real" ]; then cp "$real" "$font" if ! out=$(sh "$work/hack/fonts.sh" check 2>&1); then fail "check refused the real font: $out" fi fi # The release target fetches and checks the font before it builds anything. plan=$(make -C "$root" -n release 2>/dev/null) fetch=$(printf '%s\n' "$plan" | grep -n 'hack/fonts.sh$' | head -1 | cut -d: -f1) check=$(printf '%s\n' "$plan" | grep -n 'hack/fonts.sh check' | head -1 | cut -d: -f1) build=$(printf '%s\n' "$plan" | grep -n 'go build' | head -1 | cut -d: -f1) if [ -z "$fetch" ] || [ -z "$check" ] || [ -z "$build" ] || [ "$fetch" -gt "$build" ] || [ "$check" -gt "$build" ]; then fail "make release does not fetch and check the font before building:" printf '%s\n' "$plan" fi if [ "$fails" -ne 0 ]; then echo "fonts_test: $fails failed" exit 1 fi echo "fonts_test: ok"