Repository navigation
Expand file tree
/
Copy pathtest.sh
More file actions
executable file
·53 lines (46 loc) · 1.58 KB
/
Copy pathtest.sh
File metadata and controls
executable file
·53 lines (46 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/sh
#
# Two checks. Each rule has its cases in tests/, run in isolation by `vale
# test`, which with `--coverage` also requires every rule to fire in some
# case. The cases stay out of the rule files so that a Vale older than the
# `tests:` key can still load the style. Then one page is checked and compared to a golden
# file, and its rewrite in fixtures/clean/ is required to produce nothing:
# the scores have to agree about which paragraph reads hard, and land on it.
#
# `./test.sh -u` rewrites the golden file instead of comparing.
set -eu
update=0
[ "${1:-}" = "-u" ] && update=1
status=0
root=$(cd "$(dirname "$0")" && pwd)
vale=${VALE:-vale}
mkdir -p "$root/testdata"
(cd "$root" && "$vale" test --coverage tests Readability) || status=1
run() { # <fixture path, relative to root> -> alerts on stdout, sorted
(cd "$root" && "$vale" --output=line --no-global "$1" 2>&1 || true) |
sort -t: -k2,2n -k3,3n -k4,4
}
golden=$root/testdata/page.md.txt
got=$(run fixtures/page.md)
if [ "$update" -eq 1 ]; then
printf '%s\n' "$got" > "$golden"
elif [ ! -f "$golden" ]; then
echo "FAIL page.md: no golden file; run ./test.sh -u"
status=1
elif [ "$got" != "$(cat "$golden")" ]; then
echo "FAIL page.md"
printf '%s\n' "$got" | diff -u "$golden" - || true
status=1
else
echo "ok page.md ($(printf '%s' "$got" | grep -c . || true) alerts)"
fi
clean=$(run fixtures/clean/page.md)
if [ -n "$clean" ]; then
echo "FAIL clean/page.md: the rewrite still reads hard"
printf '%s\n' "$clean"
status=1
else
echo "ok clean/page.md (clean)"
fi
[ "$update" -eq 1 ] && echo "golden file rewritten"
exit $status