1#!/bin/sh
2#
3# Print output of failing tests
4#
56
. ${0%/*}/lib.sh
78
# Tracing executed commands would produce too much noise in the loop below.
9set +x
1011
cd t/
1213
if ! ls test-results/*.exit >/dev/null 2>/dev/null
14then
15echo "Build job failed before the tests could have been run"
16exit
17fi
1819
case "$jobname" in
20osx-clang|osx-gcc)
21# base64 in OSX doesn't wrap its output at 76 columns by
22# default, but prints a single, very long line.
23base64_opts="-b 76"
24;;
25esac
2627
combined_trash_size=0
28for TEST_EXIT in test-results/*.exit
29do
30if [ "$(cat "$TEST_EXIT")" != "0" ]
31then
32TEST_OUT="${TEST_EXIT%exit}out"
33echo "------------------------------------------------------------------------"
34echo "$(tput setaf 1)${TEST_OUT}...$(tput sgr0)"
35echo "------------------------------------------------------------------------"
36cat "${TEST_OUT}"
3738
test_name="${TEST_EXIT%.exit}"
39test_name="${test_name##*/}"
40trash_dir="trash directory.$test_name"
41case "$CI_TYPE" in
42travis)
43;;
44azure-pipelines)
45mkdir -p failed-test-artifacts
46mv "$trash_dir" failed-test-artifacts
47continue
48;;
49*)
50echo "Unhandled CI type: $CI_TYPE" >&2
51exit 1
52;;
53esac
54trash_tgz_b64="trash.$test_name.base64"
55if [ -d "$trash_dir" ]
56then
57tar czp "$trash_dir" |base64 $base64_opts >"$trash_tgz_b64"
5859
trash_size=$(wc -c <"$trash_tgz_b64")
60if [ $trash_size -gt 1048576 ]
61then
62# larger than 1MB
63echo "$(tput setaf 1)Didn't include the trash directory of '$test_name' in the trace log, it's too big$(tput sgr0)"
64continue
65fi
6667
new_combined_trash_size=$(($combined_trash_size + $trash_size))
68if [ $new_combined_trash_size -gt 1048576 ]
69then
70echo "$(tput setaf 1)Didn't include the trash directory of '$test_name' in the trace log, there is plenty of trash in there already.$(tput sgr0)"
71continue
72fi
73combined_trash_size=$new_combined_trash_size
7475
# DO NOT modify these two 'echo'-ed strings below
76# without updating 'ci/util/extract-trash-dirs.sh'
77# as well.
78echo "$(tput setaf 1)Start of trash directory of '$test_name':$(tput sgr0)"
79cat "$trash_tgz_b64"
80echo "$(tput setaf 1)End of trash directory of '$test_name'$(tput sgr0)"
81fi
82fi
83done
8485
if [ $combined_trash_size -gt 0 ]
86then
87echo "------------------------------------------------------------------------"
88echo "Trash directories embedded in this log can be extracted by running:"
89echo
90echo " curl https://api.travis-ci.org/v3/job/$TRAVIS_JOB_ID/log.txt |./ci/util/extract-trash-dirs.sh"
91fi