Merge pull request #1290 from blueyed/tests-run-shellcheck-etc
tests/run.sh: shellcheck and other fixes
This commit is contained in:
commit
d5b3fa8be0
65
tests/run.sh
65
tests/run.sh
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
#
|
#
|
||||||
# Test runner.
|
# Test runner.
|
||||||
#
|
#
|
||||||
|
@ -34,9 +34,9 @@ fi
|
||||||
|
|
||||||
# Get test files: test*, or the ones provided as args (relative to tests/).
|
# Get test files: test*, or the ones provided as args (relative to tests/).
|
||||||
if [ $# != 0 ]; then
|
if [ $# != 0 ]; then
|
||||||
tests="$@"
|
tests="$*"
|
||||||
else
|
else
|
||||||
tests=$this_dir/test*.lua
|
tests="$this_dir/test*.lua"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Travis.
|
# Travis.
|
||||||
|
@ -68,31 +68,26 @@ export GDK_SCALE=1
|
||||||
export NO_AT_BRIDGE=1
|
export NO_AT_BRIDGE=1
|
||||||
|
|
||||||
if [ $HEADLESS = 1 ]; then
|
if [ $HEADLESS = 1 ]; then
|
||||||
"$XVFB" $D -noreset -screen 0 ${SIZE}x24 &
|
"$XVFB" $D -noreset -screen 0 "${SIZE}x24" &
|
||||||
xserver_pid=$!
|
xserver_pid=$!
|
||||||
else
|
else
|
||||||
# export XEPHYR_PAUSE=1000
|
# export XEPHYR_PAUSE=1000
|
||||||
"$XEPHYR" $D -ac -name xephyr_$D -noreset -screen "$SIZE" $XEPHYR_OPTIONS &
|
"$XEPHYR" $D -ac -name xephyr_$D -noreset -screen "$SIZE" &
|
||||||
xserver_pid=$!
|
xserver_pid=$!
|
||||||
# Toggles debugging mode, using XEPHYR_PAUSE.
|
# Toggles debugging mode, using XEPHYR_PAUSE.
|
||||||
# ( sleep 1; kill -USR1 $xserver_pid ) &
|
# ( sleep 1; kill -USR1 $xserver_pid ) &
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cd $build_dir
|
|
||||||
|
|
||||||
AWESOME_OPTIONS="$AWESOME_OPTIONS --search lib"
|
|
||||||
# Add test dir (for _runner.lua).
|
# Add test dir (for _runner.lua).
|
||||||
AWESOME_OPTIONS="$AWESOME_OPTIONS --search $this_dir"
|
awesome_options=($AWESOME_OPTIONS --search lib --search $this_dir)
|
||||||
export XDG_CONFIG_HOME="./"
|
export XDG_CONFIG_HOME="$build_dir"
|
||||||
|
|
||||||
cd - >/dev/null
|
|
||||||
|
|
||||||
# Cleanup on errors / aborting.
|
# Cleanup on errors / aborting.
|
||||||
cleanup() {
|
cleanup() {
|
||||||
for p in $awesome_pid $xserver_pid; do
|
for p in $awesome_pid $xserver_pid; do
|
||||||
kill -TERM $p 2>/dev/null || true
|
kill -TERM "$p" 2>/dev/null || true
|
||||||
done
|
done
|
||||||
rm -rf $tmp_files || true
|
rm -rf "$tmp_files" || true
|
||||||
}
|
}
|
||||||
trap "cleanup" 0 2 3 15
|
trap "cleanup" 0 2 3 15
|
||||||
|
|
||||||
|
@ -113,13 +108,14 @@ wait_until_success() {
|
||||||
if [ $ret = 0 ]; then
|
if [ $ret = 0 ]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
wait_count=$(expr $wait_count - 1 || true)
|
wait_count=$((wait_count - 1))
|
||||||
if [ "$wait_count" -lt 0 ]; then
|
if [ "$wait_count" -lt 0 ]; then
|
||||||
echo "Error: failed to $1!"
|
echo "Error: failed to $1!" >&2
|
||||||
echo "Last reply: $reply."
|
# shellcheck disable=SC2154
|
||||||
|
echo "Last reply: $reply." >&2
|
||||||
if [ -f "$awesome_log" ]; then
|
if [ -f "$awesome_log" ]; then
|
||||||
echo "Log:"
|
echo "Log:" >&2
|
||||||
cat "$awesome_log"
|
cat "$awesome_log" >&2
|
||||||
fi
|
fi
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
@ -159,29 +155,28 @@ wait_until_success "setup xrdb" "printf 'Xft.dpi: 96
|
||||||
*.color9: #dc322f' | DISPLAY='$D' xrdb 2>&1"
|
*.color9: #dc322f' | DISPLAY='$D' xrdb 2>&1"
|
||||||
|
|
||||||
# Use a separate D-Bus session; sets $DBUS_SESSION_BUS_PID.
|
# Use a separate D-Bus session; sets $DBUS_SESSION_BUS_PID.
|
||||||
eval $(DISPLAY="$D" dbus-launch --sh-syntax --exit-with-session)
|
eval "$(DISPLAY="$D" dbus-launch --sh-syntax --exit-with-session)"
|
||||||
|
|
||||||
# Not in Travis?
|
# Not in Travis?
|
||||||
if [ "$CI" != true ]; then
|
if [ "$CI" != true ]; then
|
||||||
# Prepare a config file pointing to a working theme
|
# Prepare a config file pointing to a working theme
|
||||||
# Handle old filename of config files (useful for git-bisect).
|
# Handle old filename of config files (useful for git-bisect).
|
||||||
if [ -f $source_dir/awesomerc.lua.in ]; then
|
if [ -f "$source_dir/awesomerc.lua.in" ]; then
|
||||||
SED_IN=.in
|
SED_IN=.in
|
||||||
fi
|
fi
|
||||||
RC_FILE=$tmp_files/awesomerc.lua
|
RC_FILE=$tmp_files/awesomerc.lua
|
||||||
THEME_FILE=$tmp_files/theme.lua
|
THEME_FILE=$tmp_files/theme.lua
|
||||||
sed -e "s:.*beautiful.init(.*default/theme.lua.*:beautiful.init('$THEME_FILE'):" $source_dir/awesomerc.lua$SED_IN > $RC_FILE
|
sed -e "s:.*beautiful.init(.*default/theme.lua.*:beautiful.init('$THEME_FILE'):" "$source_dir/awesomerc.lua$SED_IN" > "$RC_FILE"
|
||||||
sed -e "s:@AWESOME_THEMES_PATH@/default/titlebar:$build_dir/themes/default/titlebar:" \
|
sed -e "s:@AWESOME_THEMES_PATH@/default/titlebar:$build_dir/themes/default/titlebar:" \
|
||||||
-e "s:@AWESOME_THEMES_PATH@:$source_dir/themes/:" \
|
-e "s:@AWESOME_THEMES_PATH@:$source_dir/themes/:" \
|
||||||
-e "s:@AWESOME_ICON_PATH@:$source_dir/icons:" $source_dir/themes/default/theme.lua$SED_IN > $THEME_FILE
|
-e "s:@AWESOME_ICON_PATH@:$source_dir/icons:" "$source_dir/themes/default/theme.lua$SED_IN" > "$THEME_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start awesome.
|
# Start awesome.
|
||||||
start_awesome() {
|
start_awesome() {
|
||||||
export DISPLAY="$D"
|
cd "$build_dir"
|
||||||
cd $build_dir
|
|
||||||
# Kill awesome after $timeout_stale seconds (e.g. for errors during test setup).
|
# Kill awesome after $timeout_stale seconds (e.g. for errors during test setup).
|
||||||
DISPLAY="$D" timeout $timeout_stale "$AWESOME" -c "$RC_FILE" $AWESOME_OPTIONS > $awesome_log 2>&1 &
|
DISPLAY="$D" timeout "$timeout_stale" "$AWESOME" -c "$RC_FILE" "${awesome_options[@]}" > "$awesome_log" 2>&1 &
|
||||||
awesome_pid=$!
|
awesome_pid=$!
|
||||||
cd - >/dev/null
|
cd - >/dev/null
|
||||||
|
|
||||||
|
@ -200,17 +195,17 @@ for f in $tests; do
|
||||||
|
|
||||||
start_awesome
|
start_awesome
|
||||||
|
|
||||||
if [ ! -r $f ]; then
|
if [ ! -r "$f" ]; then
|
||||||
echo "===> ERROR $f is not readable! <==="
|
echo "===> ERROR $f is not readable! <==="
|
||||||
errors=$(expr $errors + 1)
|
((errors + 1))
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Send the test file to awesome.
|
# Send the test file to awesome.
|
||||||
cat $f | DISPLAY=$D "$AWESOME_CLIENT" 2>&1
|
DISPLAY=$D "$AWESOME_CLIENT" 2>&1 < "$f"
|
||||||
|
|
||||||
# Tail the log and quit, when awesome quits.
|
# Tail the log and quit, when awesome quits.
|
||||||
tail -n 100000 -f --pid $awesome_pid $awesome_log
|
tail -n 100000 -f --pid "$awesome_pid" "$awesome_log"
|
||||||
|
|
||||||
set +e
|
set +e
|
||||||
wait $awesome_pid
|
wait $awesome_pid
|
||||||
|
@ -222,18 +217,18 @@ for f in $tests; do
|
||||||
*) echo "Awesome exited with status code $code" ;;
|
*) echo "Awesome exited with status code $code" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if ! grep -q -E '^Test finished successfully$' $awesome_log ||
|
if ! grep -q -E '^Test finished successfully$' "$awesome_log" ||
|
||||||
grep -q -E '[Ee]rror|assertion failed' $awesome_log; then
|
grep -q -E '[Ee]rror|assertion failed' "$awesome_log"; then
|
||||||
echo "===> ERROR running $f! <==="
|
echo "===> ERROR running $f! <==="
|
||||||
grep --color -o --binary-files=text -E '.*[Ee]rror.*|.*assertion failed.*' $awesome_log || true
|
grep --color -o --binary-files=text -E '.*[Ee]rror.*|.*assertion failed.*' "$awesome_log" || true
|
||||||
errors=$(expr $errors + 1)
|
((errors + 1))
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
if ! [ $errors = 0 ]; then
|
if ! [ $errors = 0 ]; then
|
||||||
if [ "$TEST_PAUSE_ON_ERRORS" = 1 ]; then
|
if [ "$TEST_PAUSE_ON_ERRORS" = 1 ]; then
|
||||||
echo "Pausing... press Enter to continue."
|
echo "Pausing... press Enter to continue."
|
||||||
read enter
|
read -r
|
||||||
fi
|
fi
|
||||||
echo "There were $errors errors!"
|
echo "There were $errors errors!"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
Loading…
Reference in New Issue