Skip to content

Commit

Permalink
cram: port recent changes from barney's cram.sh
Browse files Browse the repository at this point in the history
This adds the ability to skip tests and fixes an infinite loop issue
when files are not executable.
  • Loading branch information
Snaipe committed Jul 14, 2022
1 parent f84358b commit f26e01b
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion test/cram.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ if [ -f "$what" -a -x "$what" ]; then
function maybe_exec() {
if (cmd != "") {
while ( ( "( set -eu\n" cmd "\n) 2>&1 || echo \\[$?\\]" | getline ln ) > 0 ) {
if (ln == "[80]") {
print what ":" NR ": [skipped]" | "cat 1>&2"
cmd = ""
exit 80
}
print indent ln
}
cmd = ""
Expand Down Expand Up @@ -143,6 +148,15 @@ if [ -f "$what" -a -x "$what" ]; then
maybe_exec()
}
'
status=$?
set -e

if [ "$status" -eq 80 ]; then
# skip file
exit 0
elif [ "$status" -ne 0 ]; then
exit "$status"
fi

# git diff complains when there are differences on the x bit
# busybox doesn't support --reference
Expand All @@ -151,7 +165,7 @@ if [ -f "$what" -a -x "$what" ]; then
fi

set +e
git diff --exit-code --no-index "$what" "$what.err"
git diff --exit-code --text --no-index "$what" "$what.err"
status=$?
set -e

Expand All @@ -164,5 +178,12 @@ if [ -f "$what" -a -x "$what" ]; then
exit "$status"
fi

# Avoid going into an infinite recursive loop if $what is a
# non-directory non-executable.
if [ -n "$what" -a ! -d "$what" ]; then
echo "cram.sh: expecting argument to be either an executable file, or a directory" 1>&2
exit 1
fi

# $what can be empty, in which case this defaults to cwd.
find $what -name '*.t' -print0 | xargs -0 -n1 --no-run-if-empty $0

0 comments on commit f26e01b

Please sign in to comment.