oficina / base Public

Clone
git clone https://amadan.net/oficina/base

Plain git — no account needed to clone.

Download

Download this file

1#!/usr/bin/env bash
2# Tests for fonts.sh's checks and for the release gate that uses them. None
3# needs the network: every case fails before a download would start. Run
4# directly:
5# hack/fonts_test.sh
6set -uo pipefail
7
8here=$(cd -- "$(dirname -- "$0")" && pwd)
9root=$(cd -- "$here/.." && pwd)
10work=$(mktemp -d)
11trap 'rm -rf "$work"' EXIT
12fails=0
13
14fail() { echo "FAIL: $*"; fails=$((fails + 1)); }
15
16# A copy of the script in a tree of its own, so nothing touches the real
17# font directory.
18mkdir -p "$work/hack" "$work/internal/look/static/fonts/timeless"
19cp "$here/fonts.sh" "$work/hack/fonts.sh"
20font=$work/internal/look/static/fonts/timeless/1.094/TimelessSansVF.woff2
21
22# check: a missing font fails.
23if out=$(sh "$work/hack/fonts.sh" check 2>&1); then
24 fail "check passed with no font: $out"
25elif ! printf '%s' "$out" | grep -q "not there"; then
26 fail "check without a font said: $out"
27fi
28
29# check: a file that is not the pinned font fails.
30mkdir -p "$(dirname "$font")"
31printf 'not a font' >"$font"
32if out=$(sh "$work/hack/fonts.sh" check 2>&1); then
33 fail "check passed a wrong file: $out"
34elif ! printf '%s' "$out" | grep -q "checksum mismatch"; then
35 fail "check of a wrong file said: $out"
36fi
37
38# fetch: a wrong file already there is refused, not kept as the font.
39if out=$(sh "$work/hack/fonts.sh" 2>&1); then
40 fail "fetch kept a wrong file: $out"
41elif ! printf '%s' "$out" | grep -q "checksum mismatch"; then
42 fail "fetch with a wrong file said: $out"
43fi
44
45# The real font, when this machine has fetched it, passes.
46real=$root/internal/look/static/fonts/timeless/1.094/TimelessSansVF.woff2
47if [ -f "$real" ]; then
48 cp "$real" "$font"
49 if ! out=$(sh "$work/hack/fonts.sh" check 2>&1); then
50 fail "check refused the real font: $out"
51 fi
52fi
53
54# The release target fetches and checks the font before it builds anything.
55plan=$(make -C "$root" -n release 2>/dev/null)
56fetch=$(printf '%s\n' "$plan" | grep -n 'hack/fonts.sh$' | head -1 | cut -d: -f1)
57check=$(printf '%s\n' "$plan" | grep -n 'hack/fonts.sh check' | head -1 | cut -d: -f1)
58build=$(printf '%s\n' "$plan" | grep -n 'go build' | head -1 | cut -d: -f1)
59if [ -z "$fetch" ] || [ -z "$check" ] || [ -z "$build" ] || [ "$fetch" -gt "$build" ] || [ "$check" -gt "$build" ]; then
60 fail "make release does not fetch and check the font before building:"
61 printf '%s\n' "$plan"
62fi
63
64if [ "$fails" -ne 0 ]; then
65 echo "fonts_test: $fails failed"
66 exit 1
67fi
68echo "fonts_test: ok"
69