-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcram
51 lines (43 loc) · 1.6 KB
/
cram
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
#!/usr/bin/env bash
if [[ ${BASH_ENV-} == "${BASH_SOURCE[0]}" ]]; then # being run as BASH_ENV
if [[ ${TESTDIR-} && ${TESTFILE-} ]]; then # about to run a test
unset BASH_ENV # don't run in subshells
if [[ -f "$TESTDIR/cram-setup.sh" ]]; then # test has a setup script?
source "$TESTDIR/cram-setup.sh" # load it
fi
fi
return # continue shell execution
fi
dk use: tty
[[ -f .cramrc ]] || export CRAM="${CRAM-"--indent=4 --shell=bash --verbose"}"
cram.files() { ls specs/*.cram.md; }
cram.setupfiles() { [[ ! -d specs ]] || find specs -name cram-setup.sh; }
on "test_files" run cram_files
on "watch_files" cram.setupfiles
on "cram_files" cram.files
on "boot" require cram install-cram
on "test" dk cram
paged-command cram
dk.cram() {
local cramfiles=()
IFS=$'\n' read -rd '' -a cramfiles < <(run cram_files) || true
for REPLY in ${cramfiles[@]+"${cramfiles[@]}"}; do
[[ -s "$REPLY" ]] || abort "Empty file: $REPLY" 66 # EX_NOINPUT
done
tty slurpify diffcolor -- env BASH_ENV="${BASH_SOURCE[0]}" \
cram "$@" ${cramfiles[@]+"${cramfiles[@]}"}
}
install-cram() {
require-any python
github pjeby/cram indent-fix
catbin cram <(
echo '#!/usr/bin/env bash'
echo 'PYTHONPATH=$BASHER_PACKAGES_PATH/pjeby/cram python3 -m cram "$@"'
)
}
slurpy() {
# Read the entire output of a pipe, and forward it on (minus NUL bytes)
# This keeps cram and pygmentize happy and SIGPIPE-free!
while read -rd ''; do printf "%s" "$REPLY"; done; printf "%s" "$REPLY";
}
slurpify() { REPLY=slurpy; }