Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve test suite portability #609

Closed
wants to merge 10 commits into from
2 changes: 1 addition & 1 deletion test/tools/libgit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ git_commit()
GIT_COMMITTER_EMAIL="$0"

export GIT_AUTHOR_DATE="$author_date"
author_date="$(expr $author_date + $author_date_delta)"
author_date="$(expr "$author_date" + "$author_date_delta")"
[ -z "${GIT_COMMITTER_DATE:-}" ] &&
export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"

Expand Down
40 changes: 26 additions & 14 deletions test/tools/libtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ tig_script() {
# Ensure that the steps finish by quitting
printf '%s\n:quit\n' "$@" \
| sed -e 's/^[ ]*//' -e '/^$/d' \
| sed "s|:save-display\s\+\(\S*\)|:save-display $HOME/\1|" \
| sed "s|:save-display[ ]\{1,\}\([^ ]\{1,\}\)|:save-display $HOME/\1|" \
> "$TIG_SCRIPT"
}

Expand All @@ -166,7 +166,7 @@ gitconfig() {

in_work_dir()
{
(cd "$work_dir" && $@)
(cd "$work_dir" && "$@")
}

auto_detect_debugger() {
Expand Down Expand Up @@ -195,7 +195,7 @@ debugger=
trace=
valgrind=

set -- $TIG_TEST_OPTS $TEST_OPTS
set -- ${TIG_TEST_OPTS:-} ${TEST_OPTS:-}

while [ $# -gt 0 ]; do
arg="$1"; shift
Expand Down Expand Up @@ -283,10 +283,10 @@ show_test_results()
sed "s/^/$indent[skipped] /" < .test-skipped
return
fi
if [ -n "$trace" -a -n "$TIG_TRACE" -a -e "$TIG_TRACE" ]; then
if [ -n "$trace" ] && [ -n "$TIG_TRACE" ] && [ -e "$TIG_TRACE" ]; then
sed "s/^/$indent[trace] /" < "$TIG_TRACE"
fi
if [ -n "$valgrind" -a -e "$valgrind" ]; then
if [ -n "$valgrind" ] && [ -e "$valgrind" ]; then
sed "s/^/$indent[valgrind] /" < "$valgrind"
fi
if [ ! -d "$HOME" ] || [ ! -e .test-result ]; then
Expand All @@ -299,7 +299,7 @@ show_test_results()
failed="$(grep FAIL < .test-result | wc -l)"
count="$(sed -n '/\(FAIL\|OK\)/p' < .test-result | wc -l)"

printf "Failed %d out of %d test(s)%s\n" $failed $count
printf "Failed %d out of %d test(s)\n" "$failed" "$count"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch.


# Show output from stderr if no output is expected
if [ -e stderr ]; then
Expand All @@ -311,7 +311,7 @@ show_test_results()
tr '\r' '\n' < .test-result
elif [ "$verbose" ]; then
count="$(sed -n '/\(OK\)/p' < .test-result | wc -l)"
printf "Passed %d assertions\n" $count
printf "Passed %d assertions\n" "$count"
fi | sed "s/^/$indent| /"
}

Expand Down Expand Up @@ -355,6 +355,10 @@ test_require()
;;
diff-highlight)
diff_highlight_path="$(git --exec-path)/../../share/git-core/contrib/diff-highlight/diff-highlight"
if [ ! -e "$diff_highlight_path" ]; then
# alt path
diff_highlight_path="$(git --exec-path)/../../share/git/contrib/diff-highlight/diff-highlight"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

fi
if [ ! -e "$diff_highlight_path" ]; then
test_skip "The test requires diff-highlight, usually found in share/git-core-contrib"
fi
Expand Down Expand Up @@ -443,18 +447,26 @@ test_tig()
if [ "$#" -gt 0 ]; then
echo "*** - This test expects the following arguments: $@"
fi
(cd "$work_dir" && $debugger tig "$@")
(cd "$work_dir" && "$debugger" tig "$@")
else
set +e
runner=
# FIXME: Tell Valgrind to forward status code
if [ "$expected_status_code" = 0 -a -n "$valgrind" ]; then
if [ "$expected_status_code" = 0 ] && [ -n "$valgrind" ]; then
runner=valgrind_exec
fi
if [ -s "${prefix}stdin" ]; then
(cd "$work_dir" && $runner tig "$@") < "${prefix}stdin" > "${prefix}stdout" 2> "${prefix}stderr.orig"
if [ -n "$runner" ]; then
if [ -s "${prefix}stdin" ]; then
(cd "$work_dir" && "$runner" tig "$@") < "${prefix}stdin" > "${prefix}stdout" 2> "${prefix}stderr.orig"
else
(cd "$work_dir" && "$runner" tig "$@") > "${prefix}stdout" 2> "${prefix}stderr.orig"
fi
else
(cd "$work_dir" && $runner tig "$@") > "${prefix}stdout" 2> "${prefix}stderr.orig"
if [ -s "${prefix}stdin" ]; then
(cd "$work_dir" && tig "$@") < "${prefix}stdin" > "${prefix}stdout" 2> "${prefix}stderr.orig"
else
(cd "$work_dir" && tig "$@") > "${prefix}stdout" 2> "${prefix}stderr.orig"
fi
fi
status_code="$?"
if [ "$status_code" != "$expected_status_code" ]; then
Expand Down Expand Up @@ -482,7 +494,7 @@ test_tig()

test_graph()
{
test-graph $@ > stdout 2> stderr.orig
test-graph "$@" > stdout 2> stderr.orig
}

test_case()
Expand Down Expand Up @@ -526,7 +538,7 @@ run_test_cases()
work_dir="$work_dir/$(cat "$name-cwd")"
fi
ORIG_IFS="$IFS"
IFS=$' '
IFS=' '
test_tig $(if [ -e "$name-args" ]; then cat "$name-args"; fi)
IFS="$ORIG_IFS"
work_dir="$old_work_dir"
Expand Down
6 changes: 3 additions & 3 deletions test/tools/show-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ asserts="$(find test/ -name ".test-result" | xargs sed -n '/\[\(OK\|FAIL\)\]/p'
failures="$(find test/ -name ".test-result" | xargs grep FAIL | wc -l || true)"
skipped="$(find test/ -name ".test-skipped" | wc -l || true)"

if [ $failures = 0 ]; then
if [ "$failures" = 0 ]; then
printf "Passed %d assertions in %d tests" "$asserts" "$tests"
else
printf "Failed %d of %d assertions in %d tests" "$failures" "$asserts" "$tests"
fi

if [ $skipped != 0 ]; then
if [ "$skipped" != 0 ]; then
printf " (%d skipped)" "$skipped"
fi

echo
exit $failures
exit "$failures"