summaryrefslogtreecommitdiff
path: root/t/test-lib.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-02-07 06:05:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-02-07 06:05:26 (GMT)
commit57cbc53d3e0567d630b3e08be41e555efb06f616 (patch)
tree97fbb06114350cebe37f5f68e41206e53e43c7f8 /t/test-lib.sh
parente7b120bfa5783970c7b270052bd9d2ba31d1c6fd (diff)
parentba285a712d8bc036d8f0d4625710305711b3c2cb (diff)
downloadgit-57cbc53d3e0567d630b3e08be41e555efb06f616.zip
git-57cbc53d3e0567d630b3e08be41e555efb06f616.tar.gz
git-57cbc53d3e0567d630b3e08be41e555efb06f616.tar.bz2
Merge branch 'js/vsts-ci'
Prepare to run test suite on Azure Pipeline. * js/vsts-ci: (22 commits) test-date: drop unused parameter to getnanos() ci: parallelize testing on Windows ci: speed up Windows phase tests: optionally skip bin-wrappers/ t0061: workaround issues with --with-dashes and RUNTIME_PREFIX tests: add t/helper/ to the PATH with --with-dashes mingw: try to work around issues with the test cleanup tests: include detailed trace logs with --write-junit-xml upon failure tests: avoid calling Perl just to determine file sizes README: add a build badge (status of the Azure Pipelines build) mingw: be more generous when wrapping up the setitimer() emulation ci: use git-sdk-64-minimal build artifact ci: add a Windows job to the Azure Pipelines definition Add a build definition for Azure DevOps ci/lib.sh: add support for Azure Pipelines tests: optionally write results as JUnit-style .xml test-date: add a subcommand to measure times in shell scripts ci: use a junction on Windows instead of a symlink ci: inherit --jobs via MAKEFLAGS in run-build-and-tests ci/lib.sh: encapsulate Travis-specific things ...
Diffstat (limited to 't/test-lib.sh')
-rw-r--r--t/test-lib.sh138
1 files changed, 130 insertions, 8 deletions
diff --git a/t/test-lib.sh b/t/test-lib.sh
index 9876b4b..42b1a0a 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -111,6 +111,8 @@ do
test -z "$HARNESS_ACTIVE" && quiet=t ;;
--with-dashes)
with_dashes=t ;;
+ --no-bin-wrappers)
+ no_bin_wrappers=t ;;
--no-color)
color= ;;
--va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind)
@@ -139,6 +141,9 @@ do
verbose_log=t
tee=t
;;
+ --write-junit-xml)
+ write_junit_xml=t
+ ;;
--stress)
stress=t ;;
--stress=*)
@@ -622,11 +627,35 @@ trap 'exit $?' INT TERM HUP
# the test_expect_* functions instead.
test_ok_ () {
+ if test -n "$write_junit_xml"
+ then
+ write_junit_xml_testcase "$*"
+ fi
test_success=$(($test_success + 1))
say_color "" "ok $test_count - $@"
}
test_failure_ () {
+ if test -n "$write_junit_xml"
+ then
+ junit_insert="<failure message=\"not ok $test_count -"
+ junit_insert="$junit_insert $(xml_attr_encode "$1")\">"
+ junit_insert="$junit_insert $(xml_attr_encode \
+ "$(if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
+ then
+ test-tool path-utils skip-n-bytes \
+ "$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET
+ else
+ printf '%s\n' "$@" | sed 1d
+ fi)")"
+ junit_insert="$junit_insert</failure>"
+ if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
+ then
+ junit_insert="$junit_insert<system-err>$(xml_attr_encode \
+ "$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>"
+ fi
+ write_junit_xml_testcase "$1" " $junit_insert"
+ fi
test_failure=$(($test_failure + 1))
say_color error "not ok $test_count - $1"
shift
@@ -635,11 +664,19 @@ test_failure_ () {
}
test_known_broken_ok_ () {
+ if test -n "$write_junit_xml"
+ then
+ write_junit_xml_testcase "$* (breakage fixed)"
+ fi
test_fixed=$(($test_fixed+1))
say_color error "ok $test_count - $@ # TODO known breakage vanished"
}
test_known_broken_failure_ () {
+ if test -n "$write_junit_xml"
+ then
+ write_junit_xml_testcase "$* (known breakage)"
+ fi
test_broken=$(($test_broken+1))
say_color warn "not ok $test_count - $@ # TODO known breakage"
}
@@ -897,12 +934,21 @@ test_start_ () {
test_count=$(($test_count+1))
maybe_setup_verbose
maybe_setup_valgrind
+ if test -n "$write_junit_xml"
+ then
+ junit_start=$(test-tool date getnanos)
+ fi
}
test_finish_ () {
echo >&3 ""
maybe_teardown_valgrind
maybe_teardown_verbose
+ if test -n "$GIT_TEST_TEE_OFFSET"
+ then
+ GIT_TEST_TEE_OFFSET=$(test-tool path-utils file-size \
+ "$GIT_TEST_TEE_OUTPUT_FILE")
+ fi
}
test_skip () {
@@ -934,6 +980,13 @@ test_skip () {
case "$to_skip" in
t)
+ if test -n "$write_junit_xml"
+ then
+ message="$(xml_attr_encode "$skipped_reason")"
+ write_junit_xml_testcase "$1" \
+ " <skipped message=\"$message\" />"
+ fi
+
say_color skip >&3 "skipping test: $@"
say_color skip "ok $test_count # skip $1 ($skipped_reason)"
: true
@@ -949,9 +1002,51 @@ test_at_end_hook_ () {
:
}
+write_junit_xml () {
+ case "$1" in
+ --truncate)
+ >"$junit_xml_path"
+ junit_have_testcase=
+ shift
+ ;;
+ esac
+ printf '%s\n' "$@" >>"$junit_xml_path"
+}
+
+xml_attr_encode () {
+ printf '%s\n' "$@" | test-tool xml-encode
+}
+
+write_junit_xml_testcase () {
+ junit_attrs="name=\"$(xml_attr_encode "$this_test.$test_count $1")\""
+ shift
+ junit_attrs="$junit_attrs classname=\"$this_test\""
+ junit_attrs="$junit_attrs time=\"$(test-tool \
+ date getnanos $junit_start)\""
+ write_junit_xml "$(printf '%s\n' \
+ " <testcase $junit_attrs>" "$@" " </testcase>")"
+ junit_have_testcase=t
+}
+
test_done () {
GIT_EXIT_OK=t
+ if test -n "$write_junit_xml" && test -n "$junit_xml_path"
+ then
+ test -n "$junit_have_testcase" || {
+ junit_start=$(test-tool date getnanos)
+ write_junit_xml_testcase "all tests skipped"
+ }
+
+ # adjust the overall time
+ junit_time=$(test-tool date getnanos $junit_suite_start)
+ sed "s/<testsuite [^>]*/& time=\"$junit_time\"/" \
+ <"$junit_xml_path" >"$junit_xml_path.new"
+ mv "$junit_xml_path.new" "$junit_xml_path"
+
+ write_junit_xml " </testsuite>" "</testsuites>"
+ fi
+
if test -z "$HARNESS_ACTIVE"
then
mkdir -p "$TEST_RESULTS_DIR"
@@ -1011,7 +1106,11 @@ test_done () {
error "Tests passed but trash directory already removed before test cleanup; aborting"
cd "$TRASH_DIRECTORY/.." &&
- rm -fr "$TRASH_DIRECTORY" ||
+ rm -fr "$TRASH_DIRECTORY" || {
+ # try again in a bit
+ sleep 5;
+ rm -fr "$TRASH_DIRECTORY"
+ } ||
error "Tests passed but test cleanup failed; aborting"
fi
test_at_end_hook_
@@ -1117,20 +1216,25 @@ then
PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR/t/helper:$PATH
GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH}
else # normal case, use ../bin-wrappers only unless $with_dashes:
- git_bin_dir="$GIT_BUILD_DIR/bin-wrappers"
- if ! test -x "$git_bin_dir/git"
+ if test -n "$no_bin_wrappers"
then
- if test -z "$with_dashes"
+ with_dashes=t
+ else
+ git_bin_dir="$GIT_BUILD_DIR/bin-wrappers"
+ if ! test -x "$git_bin_dir/git"
then
- say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
+ if test -z "$with_dashes"
+ then
+ say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH"
+ fi
+ with_dashes=t
fi
- with_dashes=t
+ PATH="$git_bin_dir:$PATH"
fi
- PATH="$git_bin_dir:$PATH"
GIT_EXEC_PATH=$GIT_BUILD_DIR
if test -n "$with_dashes"
then
- PATH="$GIT_BUILD_DIR:$PATH"
+ PATH="$GIT_BUILD_DIR:$GIT_BUILD_DIR/t/helper:$PATH"
fi
fi
GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt
@@ -1178,6 +1282,7 @@ then
else
mkdir -p "$TRASH_DIRECTORY"
fi
+
# Use -P to resolve symlinks in our working directory so that the cwd
# in subprocesses like git equals our $PWD (for pathname comparisons).
cd -P "$TRASH_DIRECTORY" || exit 1
@@ -1191,6 +1296,23 @@ then
test_done
fi
+if test -n "$write_junit_xml"
+then
+ junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out"
+ mkdir -p "$junit_xml_dir"
+ junit_xml_base=${0##*/}
+ junit_xml_path="$junit_xml_dir/TEST-${junit_xml_base%.sh}.xml"
+ junit_attrs="name=\"${junit_xml_base%.sh}\""
+ junit_attrs="$junit_attrs timestamp=\"$(TZ=UTC \
+ date +%Y-%m-%dT%H:%M:%S)\""
+ write_junit_xml --truncate "<testsuites>" " <testsuite $junit_attrs>"
+ junit_suite_start=$(test-tool date getnanos)
+ if test -n "$GIT_TEST_TEE_OUTPUT_FILE"
+ then
+ GIT_TEST_TEE_OFFSET=0
+ fi
+fi
+
# Provide an implementation of the 'yes' utility
yes () {
if test $# = 0