-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathrun_doc_script_tests.sh
More file actions
executable file
·79 lines (63 loc) · 1.5 KB
/
run_doc_script_tests.sh
File metadata and controls
executable file
·79 lines (63 loc) · 1.5 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env bash
set -euo pipefail
SELF_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ARIA_BUILD_CONFIG="${ARIA_BUILD_CONFIG:-dev}"
ARIA_LIB_DIR="${ARIA_LIB_DIR:-${SELF_DIR}/lib:${SELF_DIR}/lib-test}"
ARIA_TEST_DIR="${ARIA_TEST_DIR:-${SELF_DIR}/tests}"
RUST_MIN_STACK=16777216
print_help() {
cat <<'EOF'
Usage: run_doc_script_tests.sh INPUT_FILE [OUTDIR]
Extract all ```aria fenced code blocks from INPUT_FILE into numbered
OUTDIR/*.aria files, run each of them with the local 'aria' binary,
and clean up afterwards.
If OUTDIR is not provided, a temporary directory under /tmp is created
and removed automatically.
EOF
}
if [ "$#" -eq 0 ]; then
print_help
exit 1
fi
if [ "$#" -eq 1 ] && [ "${1-}" = "--help" ]; then
print_help
exit 0
fi
infile="$1"
if [ "${2-}" != "" ]; then
outdir="$2"
cleanup_outdir=0
else
outdir="$(mktemp -d /tmp/aria_manual_tests.XXXXXX)"
cleanup_outdir=1
fi
mkdir -p "$outdir"
awk -P -v outdir="$outdir" '
BEGIN { inn=0; idx=0; }
# start fence: ```aria
/^[[:space:]]*```aria[[:space:]]*$/ {
inn=1
fname = outdir "/" idx ".aria"
print "" > fname
idx++
next
}
# end fence: ```
/^[[:space:]]*```[[:space:]]*$/ {
if (inn==1) {
inn=0
close(fname)
next
}
}
inn==1 { print >> fname }
' "$infile"
[ -d "$outdir" ] || exit 0
for f in "$outdir"/*.aria; do
[ -f "$f" ] || continue
echo "Running test $f"
"${SELF_DIR}/aria" "$f"
done
if [ "$cleanup_outdir" -eq 1 ]; then
rm -rf "$outdir"
fi