summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/color.sh12
-rw-r--r--tests/getopts.sh10
-rw-r--r--tests/run.sh73
-rw-r--r--tests/util.sh8
4 files changed, 50 insertions, 53 deletions
diff --git a/tests/color.sh b/tests/color.sh
index 0d6ef68..805d2b8 100644
--- a/tests/color.sh
+++ b/tests/color.sh
@@ -24,20 +24,14 @@ color_fd() {
color_fd 1 && COLOR_STDOUT=1 || COLOR_STDOUT=0
color_fd 2 && COLOR_STDERR=1 || COLOR_STDERR=0
-# Save these in case the tests unset PATH
-CAT=$(command -v cat)
+# Save this in case the tests unset PATH
SED=$(command -v sed)
# Filter out escape sequences if necessary
color() {
if color_fd 1; then
- "$CAT"
+ "$@"
else
- "$SED" $'s/\e\\[[^m]*m//g'
+ "$@" | "$SED" $'s/\e\\[[^m]*m//g'
fi
}
-
-# printf with auto-detected color support
-cprintf() {
- printf "$@" | color
-}
diff --git a/tests/getopts.sh b/tests/getopts.sh
index 6616a4a..7d3ef4b 100644
--- a/tests/getopts.sh
+++ b/tests/getopts.sh
@@ -8,7 +8,7 @@
# Print usage information
usage() {
local pad=$(printf "%*s" ${#0} "")
- color <<EOF
+ color cat <<EOF
Usage: ${GRN}$0${RST} [${BLU}--bfs${RST}=${MAG}path/to/bfs${RST}] [${BLU}--sudo${RST}[=${BLD}COMMAND${RST}]] [${BLU}--stop${RST}]
$pad [${BLU}--no-clean${RST}] [${BLU}--update${RST}] [${BLU}--verbose${RST}[=${BLD}LEVEL${RST}]] [${BLU}--help${RST}]
$pad [${BLU}--posix${RST}] [${BLU}--bsd${RST}] [${BLU}--gnu${RST}] [${BLU}--all${RST}] [${BLD}TEST${RST} [${BLD}TEST${RST} ...]]
@@ -117,7 +117,7 @@ parse_args() {
exit 0
;;
-*)
- cprintf "${RED}error:${RST} Unrecognized option '%s'.\n\n" "$arg" >&2
+ color printf "${RED}error:${RST} Unrecognized option '%s'.\n\n" "$arg" >&2
usage >&2
exit 1
;;
@@ -149,9 +149,9 @@ parse_args() {
done
if ((${#TEST_CASES[@]} == 0)); then
- cprintf "${RED}error:${RST} No tests matched" >&2
- cprintf " ${BLD}%s${RST}" "${PATTERNS[@]}" >&2
- cprintf ".\n\n" >&2
+ color printf "${RED}error:${RST} No tests matched" >&2
+ color printf " ${BLD}%s${RST}" "${PATTERNS[@]}" >&2
+ color printf ".\n\n" >&2
usage >&2
exit 1
fi
diff --git a/tests/run.sh b/tests/run.sh
index 70c9cc2..5fcccad 100644
--- a/tests/run.sh
+++ b/tests/run.sh
@@ -93,7 +93,7 @@ run_tests() {
else
((++failed))
((VERBOSE_ERRORS)) || cat "$TMP/$TEST.err" >&2
- cprintf "${BOL}${RED}%s failed!${RST}\n" "$TEST"
+ color printf "${BOL}${RED}%s failed!${RST}\n" "$TEST"
((STOP)) && break
fi
done
@@ -101,13 +101,13 @@ run_tests() {
printf "${BOL}"
if ((passed > 0)); then
- cprintf "${GRN}tests passed: %d${RST}\n" "$passed"
+ color printf "${GRN}tests passed: %d${RST}\n" "$passed"
fi
if ((skipped > 0)); then
- cprintf "${CYN}tests skipped: %s${RST}\n" "$skipped"
+ color printf "${CYN}tests skipped: %s${RST}\n" "$skipped"
fi
if ((failed > 0)); then
- cprintf "${RED}tests failed: %s${RST}\n" "$failed"
+ color printf "${RED}tests failed: %s${RST}\n" "$failed"
exit 1
fi
}
@@ -126,7 +126,7 @@ skip() {
debug "$file" $line "${CYN}$TEST skipped!${RST}" "$(awk "NR == $line" "$file")" >&3
}
elif ((VERBOSE_TESTS)); then
- cprintf "${BOL}${CYN}%s skipped!${RST}\n" "$TEST"
+ color printf "${BOL}${CYN}%s skipped!${RST}\n" "$TEST"
fi
exit $EX_SKIP
@@ -175,39 +175,42 @@ set_acl() {
}
# Print a bfs invocation for --verbose=commands
-bfs_verbose() (
- if ((!VERBOSE_COMMANDS)); then
- return
+bfs_verbose() {
+ if ((VERBOSE_COMMANDS)); then
+ (
+ # Close some fds to make room for the pipe,
+ # even with extremely low ulimit -n
+ exec >&- 4>&-
+ exec >&3 3>&-
+ color bfs_verbose_impl "$@"
+ )
fi
+}
- # Free up an fd for the pipe
- exec 4>&-
-
- {
- printf "${GRN}%q${RST} " "${BFS[@]}"
-
- local expr_started=
- for arg; do
- if [[ $arg == -[A-Z]* ]]; then
- printf "${CYN}%q${RST} " "$arg"
- elif [[ $arg == [\(!] || $arg == -[ao] || $arg == -and || $arg == -or || $arg == -not ]]; then
- expr_started=yes
- printf "${RED}%q${RST} " "$arg"
- elif [[ $expr_started && $arg == [\),] ]]; then
- printf "${RED}%q${RST} " "$arg"
- elif [[ $arg == -?* ]]; then
- expr_started=yes
- printf "${BLU}%q${RST} " "$arg"
- elif [ "$expr_started" ]; then
- printf "${BLD}%q${RST} " "$arg"
- else
- printf "${MAG}%q${RST} " "$arg"
- fi
- done
+bfs_verbose_impl() {
+ printf "${GRN}%q${RST} " "${BFS[@]}"
+
+ local expr_started=
+ for arg; do
+ if [[ $arg == -[A-Z]* ]]; then
+ printf "${CYN}%q${RST} " "$arg"
+ elif [[ $arg == [\(!] || $arg == -[ao] || $arg == -and || $arg == -or || $arg == -not ]]; then
+ expr_started=yes
+ printf "${RED}%q${RST} " "$arg"
+ elif [[ $expr_started && $arg == [\),] ]]; then
+ printf "${RED}%q${RST} " "$arg"
+ elif [[ $arg == -?* ]]; then
+ expr_started=yes
+ printf "${BLU}%q${RST} " "$arg"
+ elif [ "$expr_started" ]; then
+ printf "${BLD}%q${RST} " "$arg"
+ else
+ printf "${MAG}%q${RST} " "$arg"
+ fi
+ done
- printf '\n'
- } | color >&3
-)
+ printf '\n'
+}
# Run the bfs we're testing
invoke_bfs() {
diff --git a/tests/util.sh b/tests/util.sh
index efc24b0..31a7b6c 100644
--- a/tests/util.sh
+++ b/tests/util.sh
@@ -76,14 +76,14 @@ drop_root() {
if command -v capsh &>/dev/null; then
if capsh --has-p=cap_dac_override &>/dev/null || capsh --has-p=cap_dac_read_search &>/dev/null; then
if [ -n "${BFS_TRIED_DROP:-}" ]; then
- color >&2 <<EOF
+ color cat >&2 <<EOF
${RED}error:${RST} Failed to drop capabilities.
EOF
exit 1
fi
- color >&2 <<EOF
+ color cat >&2 <<EOF
${YLW}warning:${RST} Running as ${BLD}$(id -un)${RST} is not recommended. Dropping ${BLD}cap_dac_override${RST} and
${BLD}cap_dac_read_search${RST}.
@@ -100,7 +100,7 @@ EOF
UNLESS=" unless ${GRN}capsh${RST} is installed"
fi
- color >&2 <<EOF
+ color cat >&2 <<EOF
${RED}error:${RST} These tests expect filesystem permissions to be enforced, and therefore
will not work when run as ${BLD}$(id -un)${RST}${UNLESS}.
EOF
@@ -122,7 +122,7 @@ callers() {
debug() {
local file="${1/#*\/tests\//tests\/}"
set -- "$file" "${@:2}"
- cprintf "${BLD}%s:%d:${RST} %s\n %s\n" "$@"
+ color printf "${BLD}%s:%d:${RST} %s\n %s\n" "$@"
}
## Deferred cleanup