Jonathan Nieder | c74c720 | 2013-11-25 13:03:06 -0800 | [diff] [blame] | 1 | # Test framework for git. See t/README for usage. |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
Michal Sojka | 64b9032 | 2010-04-16 15:53:59 +0200 | [diff] [blame] | 5 | # This program is free software: you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License as published by |
| 7 | # the Free Software Foundation, either version 2 of the License, or |
| 8 | # (at your option) any later version. |
| 9 | # |
| 10 | # This program is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU General Public License |
| 16 | # along with this program. If not, see http://www.gnu.org/licenses/ . |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 17 | |
Junio C Hamano | 3c8f12c | 2012-06-24 22:01:35 -0700 | [diff] [blame] | 18 | # Test the binaries we have just built. The tests are kept in |
| 19 | # t/ subdirectory and are run in 'trash directory' subdirectory. |
| 20 | if test -z "$TEST_DIRECTORY" |
| 21 | then |
| 22 | # We allow tests to override this, in case they want to run tests |
| 23 | # outside of t/, e.g. for running tests on the test library |
| 24 | # itself. |
| 25 | TEST_DIRECTORY=$(pwd) |
Felipe Contreras | 85176d7 | 2013-11-17 23:12:43 -0500 | [diff] [blame] | 26 | else |
| 27 | # ensure that TEST_DIRECTORY is an absolute path so that it |
| 28 | # is valid even if the current working directory is changed |
| 29 | TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1 |
Junio C Hamano | 3c8f12c | 2012-06-24 22:01:35 -0700 | [diff] [blame] | 30 | fi |
| 31 | if test -z "$TEST_OUTPUT_DIRECTORY" |
| 32 | then |
| 33 | # Similarly, override this to store the test-results subdir |
| 34 | # elsewhere |
| 35 | TEST_OUTPUT_DIRECTORY=$TEST_DIRECTORY |
| 36 | fi |
| 37 | GIT_BUILD_DIR="$TEST_DIRECTORY"/.. |
| 38 | |
Jeff King | d0cc579 | 2017-07-10 09:24:35 -0400 | [diff] [blame] | 39 | # If we were built with ASAN, it may complain about leaks |
| 40 | # of program-lifetime variables. Disable it by default to lower |
| 41 | # the noise level. This needs to happen at the start of the script, |
| 42 | # before we even do our "did we build git yet" check (since we don't |
| 43 | # want that one to complain to stderr). |
Jeff King | bf1ce90 | 2017-07-10 09:24:39 -0400 | [diff] [blame] | 44 | : ${ASAN_OPTIONS=detect_leaks=0:abort_on_error=1} |
Jeff King | d0cc579 | 2017-07-10 09:24:35 -0400 | [diff] [blame] | 45 | export ASAN_OPTIONS |
| 46 | |
Jeff King | 85b81b3 | 2017-09-05 09:04:04 -0400 | [diff] [blame] | 47 | # If LSAN is in effect we _do_ want leak checking, but we still |
| 48 | # want to abort so that we notice the problems. |
| 49 | : ${LSAN_OPTIONS=abort_on_error=1} |
| 50 | export LSAN_OPTIONS |
| 51 | |
Johannes Schindelin | 8abfdf4 | 2018-11-14 08:32:11 -0800 | [diff] [blame] | 52 | if test ! -f "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS |
Ramkumar Ramachandra | 2006f0a | 2012-09-17 22:36:19 +0530 | [diff] [blame] | 53 | then |
Johannes Schindelin | 8abfdf4 | 2018-11-14 08:32:11 -0800 | [diff] [blame] | 54 | echo >&2 'error: GIT-BUILD-OPTIONS missing (has Git been built?).' |
Ramkumar Ramachandra | 2006f0a | 2012-09-17 22:36:19 +0530 | [diff] [blame] | 55 | exit 1 |
| 56 | fi |
Junio C Hamano | 3c8f12c | 2012-06-24 22:01:35 -0700 | [diff] [blame] | 57 | . "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS |
| 58 | export PERL_PATH SHELL_PATH |
| 59 | |
Patrick Steinhardt | ade1552 | 2021-07-20 08:32:26 +0200 | [diff] [blame] | 60 | # In t0000, we need to override test directories of nested testcases. In case |
| 61 | # the developer has TEST_OUTPUT_DIRECTORY part of his build options, then we'd |
| 62 | # reset this value to instead contain what the developer has specified. We thus |
| 63 | # have this knob to allow overriding the directory. |
| 64 | if test -n "${TEST_OUTPUT_DIRECTORY_OVERRIDE}" |
| 65 | then |
| 66 | TEST_OUTPUT_DIRECTORY="${TEST_OUTPUT_DIRECTORY_OVERRIDE}" |
| 67 | fi |
| 68 | |
Johannes Schindelin | b02e7d5 | 2019-04-12 02:37:24 -0700 | [diff] [blame] | 69 | # Disallow the use of abbreviated options in the test suite by default |
| 70 | if test -z "${GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS}" |
| 71 | then |
| 72 | GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=true |
| 73 | export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS |
| 74 | fi |
| 75 | |
Ævar Arnfjörð Bjarmason | 97c8aac | 2021-05-10 16:19:09 +0200 | [diff] [blame] | 76 | # Explicitly set the default branch name for testing, to avoid the |
| 77 | # transitory "git init" warning under --verbose. |
| 78 | : ${GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME:=master} |
| 79 | export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME |
| 80 | |
Junio C Hamano | c2116a1 | 2008-03-06 19:04:26 -0800 | [diff] [blame] | 81 | ################################################################ |
| 82 | # It appears that people try to run tests without building... |
Johannes Schindelin | 8abfdf4 | 2018-11-14 08:32:11 -0800 | [diff] [blame] | 83 | "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 84 | if test $? != 1 |
| 85 | then |
Johannes Schindelin | ed306e4 | 2018-11-14 08:32:10 -0800 | [diff] [blame] | 86 | if test -n "$GIT_TEST_INSTALLED" |
| 87 | then |
| 88 | echo >&2 "error: there is no working Git at '$GIT_TEST_INSTALLED'" |
| 89 | else |
| 90 | echo >&2 'error: you do not seem to have built git yet.' |
| 91 | fi |
Pavel Roskin | d9bdd39 | 2005-08-10 22:10:01 -0400 | [diff] [blame] | 92 | exit 1 |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 93 | fi |
Junio C Hamano | c2116a1 | 2008-03-06 19:04:26 -0800 | [diff] [blame] | 94 | |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 95 | store_arg_to= |
Matheus Tavares | 78dc088 | 2020-03-22 12:58:57 -0300 | [diff] [blame] | 96 | opt_required_arg= |
| 97 | # $1: option string |
| 98 | # $2: name of the var where the arg will be stored |
| 99 | mark_option_requires_arg () { |
| 100 | if test -n "$opt_required_arg" |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 101 | then |
Matheus Tavares | 78dc088 | 2020-03-22 12:58:57 -0300 | [diff] [blame] | 102 | echo "error: options that require args cannot be bundled" \ |
| 103 | "together: '$opt_required_arg' and '$1'" >&2 |
| 104 | exit 1 |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 105 | fi |
Matheus Tavares | 78dc088 | 2020-03-22 12:58:57 -0300 | [diff] [blame] | 106 | opt_required_arg=$1 |
| 107 | store_arg_to=$2 |
| 108 | } |
| 109 | |
| 110 | parse_option () { |
| 111 | local opt="$1" |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 112 | |
| 113 | case "$opt" in |
| 114 | -d|--d|--de|--deb|--debu|--debug) |
| 115 | debug=t ;; |
| 116 | -i|--i|--im|--imm|--imme|--immed|--immedi|--immedia|--immediat|--immediate) |
| 117 | immediate=t ;; |
| 118 | -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) |
| 119 | GIT_TEST_LONG=t; export GIT_TEST_LONG ;; |
| 120 | -r) |
Matheus Tavares | 78dc088 | 2020-03-22 12:58:57 -0300 | [diff] [blame] | 121 | mark_option_requires_arg "$opt" run_list |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 122 | ;; |
| 123 | --run=*) |
| 124 | run_list=${opt#--*=} ;; |
| 125 | -h|--h|--he|--hel|--help) |
| 126 | help=t ;; |
| 127 | -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) |
| 128 | verbose=t ;; |
| 129 | --verbose-only=*) |
| 130 | verbose_only=${opt#--*=} |
| 131 | ;; |
| 132 | -q|--q|--qu|--qui|--quie|--quiet) |
| 133 | # Ignore --quiet under a TAP::Harness. Saying how many tests |
| 134 | # passed without the ok/not ok details is always an error. |
| 135 | test -z "$HARNESS_ACTIVE" && quiet=t ;; |
| 136 | --with-dashes) |
| 137 | with_dashes=t ;; |
Johannes Schindelin | dd167a3 | 2019-01-29 06:19:37 -0800 | [diff] [blame] | 138 | --no-bin-wrappers) |
| 139 | no_bin_wrappers=t ;; |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 140 | --no-color) |
| 141 | color= ;; |
| 142 | --va|--val|--valg|--valgr|--valgri|--valgrin|--valgrind) |
| 143 | valgrind=memcheck |
| 144 | tee=t |
| 145 | ;; |
| 146 | --valgrind=*) |
| 147 | valgrind=${opt#--*=} |
| 148 | tee=t |
| 149 | ;; |
| 150 | --valgrind-only=*) |
| 151 | valgrind_only=${opt#--*=} |
| 152 | tee=t |
| 153 | ;; |
| 154 | --tee) |
| 155 | tee=t ;; |
| 156 | --root=*) |
| 157 | root=${opt#--*=} ;; |
| 158 | --chain-lint) |
| 159 | GIT_TEST_CHAIN_LINT=1 ;; |
| 160 | --no-chain-lint) |
| 161 | GIT_TEST_CHAIN_LINT=0 ;; |
| 162 | -x) |
| 163 | trace=t ;; |
| 164 | -V|--verbose-log) |
| 165 | verbose_log=t |
| 166 | tee=t |
| 167 | ;; |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 168 | --write-junit-xml) |
| 169 | write_junit_xml=t |
| 170 | ;; |
SZEDER Gábor | fb7d1e3 | 2019-01-05 02:08:59 +0100 | [diff] [blame] | 171 | --stress) |
| 172 | stress=t ;; |
| 173 | --stress=*) |
Johannes Schindelin | f545737 | 2019-03-03 06:44:55 -0800 | [diff] [blame] | 174 | echo "error: --stress does not accept an argument: '$opt'" >&2 |
| 175 | echo "did you mean --stress-jobs=${opt#*=} or --stress-limit=${opt#*=}?" >&2 |
| 176 | exit 1 |
| 177 | ;; |
| 178 | --stress-jobs=*) |
| 179 | stress=t; |
SZEDER Gábor | 134768c | 2021-01-26 23:05:33 +0100 | [diff] [blame] | 180 | stress_jobs=${opt#--*=} |
| 181 | case "$stress_jobs" in |
SZEDER Gábor | 7d661e5 | 2019-02-11 20:58:03 +0100 | [diff] [blame] | 182 | *[!0-9]*|0*|"") |
Johannes Schindelin | f545737 | 2019-03-03 06:44:55 -0800 | [diff] [blame] | 183 | echo "error: --stress-jobs=<N> requires the number of jobs to run" >&2 |
SZEDER Gábor | fb7d1e3 | 2019-01-05 02:08:59 +0100 | [diff] [blame] | 184 | exit 1 |
| 185 | ;; |
| 186 | *) # Good. |
| 187 | ;; |
| 188 | esac |
| 189 | ;; |
SZEDER Gábor | 76e27fb | 2019-02-08 12:50:45 +0100 | [diff] [blame] | 190 | --stress-limit=*) |
Johannes Schindelin | de69e6f | 2019-03-03 06:44:54 -0800 | [diff] [blame] | 191 | stress=t; |
SZEDER Gábor | 76e27fb | 2019-02-08 12:50:45 +0100 | [diff] [blame] | 192 | stress_limit=${opt#--*=} |
| 193 | case "$stress_limit" in |
SZEDER Gábor | 7d661e5 | 2019-02-11 20:58:03 +0100 | [diff] [blame] | 194 | *[!0-9]*|0*|"") |
SZEDER Gábor | 76e27fb | 2019-02-08 12:50:45 +0100 | [diff] [blame] | 195 | echo "error: --stress-limit=<N> requires the number of repetitions" >&2 |
| 196 | exit 1 |
| 197 | ;; |
| 198 | *) # Good. |
| 199 | ;; |
| 200 | esac |
| 201 | ;; |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 202 | *) |
| 203 | echo "error: unknown test option '$opt'" >&2; exit 1 ;; |
| 204 | esac |
Matheus Tavares | 78dc088 | 2020-03-22 12:58:57 -0300 | [diff] [blame] | 205 | } |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 206 | |
Matheus Tavares | 78dc088 | 2020-03-22 12:58:57 -0300 | [diff] [blame] | 207 | # Parse options while taking care to leave $@ intact, so we will still |
| 208 | # have all the original command line options when executing the test |
| 209 | # script again for '--tee' and '--verbose-log' later. |
| 210 | for opt |
| 211 | do |
| 212 | if test -n "$store_arg_to" |
| 213 | then |
| 214 | eval $store_arg_to=\$opt |
| 215 | store_arg_to= |
| 216 | opt_required_arg= |
| 217 | continue |
| 218 | fi |
| 219 | |
| 220 | case "$opt" in |
| 221 | --*|-?) |
| 222 | parse_option "$opt" ;; |
| 223 | -?*) |
| 224 | # bundled short options must be fed separately to parse_option |
| 225 | opt=${opt#-} |
| 226 | while test -n "$opt" |
| 227 | do |
| 228 | extra=${opt#?} |
| 229 | this=${opt%$extra} |
| 230 | opt=$extra |
| 231 | parse_option "-$this" |
| 232 | done |
| 233 | ;; |
| 234 | *) |
| 235 | echo "error: unknown test option '$opt'" >&2; exit 1 ;; |
| 236 | esac |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 237 | done |
| 238 | if test -n "$store_arg_to" |
| 239 | then |
Matheus Tavares | 78dc088 | 2020-03-22 12:58:57 -0300 | [diff] [blame] | 240 | echo "error: $opt_required_arg requires an argument" >&2 |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 241 | exit 1 |
| 242 | fi |
| 243 | |
| 244 | if test -n "$valgrind_only" |
| 245 | then |
| 246 | test -z "$valgrind" && valgrind=memcheck |
| 247 | test -z "$verbose" && verbose_only="$valgrind_only" |
| 248 | elif test -n "$valgrind" |
| 249 | then |
| 250 | test -z "$verbose_log" && verbose=t |
| 251 | fi |
| 252 | |
SZEDER Gábor | fb7d1e3 | 2019-01-05 02:08:59 +0100 | [diff] [blame] | 253 | if test -n "$stress" |
| 254 | then |
| 255 | verbose=t |
| 256 | trace=t |
| 257 | immediate=t |
| 258 | fi |
| 259 | |
| 260 | TEST_STRESS_JOB_SFX="${GIT_TEST_STRESS_JOB_NR:+.stress-$GIT_TEST_STRESS_JOB_NR}" |
SZEDER Gábor | 62c379b | 2019-01-05 02:08:56 +0100 | [diff] [blame] | 261 | TEST_NAME="$(basename "$0" .sh)" |
SZEDER Gábor | ffe1afe | 2019-08-05 23:04:47 +0200 | [diff] [blame] | 262 | TEST_NUMBER="${TEST_NAME%%-*}" |
| 263 | TEST_NUMBER="${TEST_NUMBER#t}" |
SZEDER Gábor | 62c379b | 2019-01-05 02:08:56 +0100 | [diff] [blame] | 264 | TEST_RESULTS_DIR="$TEST_OUTPUT_DIRECTORY/test-results" |
SZEDER Gábor | fb7d1e3 | 2019-01-05 02:08:59 +0100 | [diff] [blame] | 265 | TEST_RESULTS_BASE="$TEST_RESULTS_DIR/$TEST_NAME$TEST_STRESS_JOB_SFX" |
| 266 | TRASH_DIRECTORY="trash directory.$TEST_NAME$TEST_STRESS_JOB_SFX" |
SZEDER Gábor | 61f292d | 2019-01-05 02:08:57 +0100 | [diff] [blame] | 267 | test -n "$root" && TRASH_DIRECTORY="$root/$TRASH_DIRECTORY" |
| 268 | case "$TRASH_DIRECTORY" in |
| 269 | /*) ;; # absolute path is good |
| 270 | *) TRASH_DIRECTORY="$TEST_OUTPUT_DIRECTORY/$TRASH_DIRECTORY" ;; |
| 271 | esac |
SZEDER Gábor | 62c379b | 2019-01-05 02:08:56 +0100 | [diff] [blame] | 272 | |
SZEDER Gábor | fb7d1e3 | 2019-01-05 02:08:59 +0100 | [diff] [blame] | 273 | # If --stress was passed, run this test repeatedly in several parallel loops. |
| 274 | if test "$GIT_TEST_STRESS_STARTED" = "done" |
| 275 | then |
| 276 | : # Don't stress test again. |
| 277 | elif test -n "$stress" |
| 278 | then |
SZEDER Gábor | 134768c | 2021-01-26 23:05:33 +0100 | [diff] [blame] | 279 | if test -n "$stress_jobs" |
SZEDER Gábor | fb7d1e3 | 2019-01-05 02:08:59 +0100 | [diff] [blame] | 280 | then |
SZEDER Gábor | 134768c | 2021-01-26 23:05:33 +0100 | [diff] [blame] | 281 | job_count=$stress_jobs |
SZEDER Gábor | fb7d1e3 | 2019-01-05 02:08:59 +0100 | [diff] [blame] | 282 | elif test -n "$GIT_TEST_STRESS_LOAD" |
| 283 | then |
| 284 | job_count="$GIT_TEST_STRESS_LOAD" |
| 285 | elif job_count=$(getconf _NPROCESSORS_ONLN 2>/dev/null) && |
| 286 | test -n "$job_count" |
| 287 | then |
| 288 | job_count=$((2 * $job_count)) |
| 289 | else |
| 290 | job_count=8 |
| 291 | fi |
| 292 | |
| 293 | mkdir -p "$TEST_RESULTS_DIR" |
| 294 | stressfail="$TEST_RESULTS_BASE.stress-failed" |
| 295 | rm -f "$stressfail" |
| 296 | |
| 297 | stress_exit=0 |
| 298 | trap ' |
| 299 | kill $job_pids 2>/dev/null |
| 300 | wait |
| 301 | stress_exit=1 |
| 302 | ' TERM INT HUP |
| 303 | |
| 304 | job_pids= |
| 305 | job_nr=0 |
| 306 | while test $job_nr -lt "$job_count" |
| 307 | do |
| 308 | ( |
| 309 | GIT_TEST_STRESS_STARTED=done |
| 310 | GIT_TEST_STRESS_JOB_NR=$job_nr |
| 311 | export GIT_TEST_STRESS_STARTED GIT_TEST_STRESS_JOB_NR |
| 312 | |
| 313 | trap ' |
| 314 | kill $test_pid 2>/dev/null |
| 315 | wait |
| 316 | exit 1 |
| 317 | ' TERM INT |
| 318 | |
SZEDER Gábor | 76e27fb | 2019-02-08 12:50:45 +0100 | [diff] [blame] | 319 | cnt=1 |
| 320 | while ! test -e "$stressfail" && |
| 321 | { test -z "$stress_limit" || |
| 322 | test $cnt -le $stress_limit ; } |
SZEDER Gábor | fb7d1e3 | 2019-01-05 02:08:59 +0100 | [diff] [blame] | 323 | do |
| 324 | $TEST_SHELL_PATH "$0" "$@" >"$TEST_RESULTS_BASE.stress-$job_nr.out" 2>&1 & |
| 325 | test_pid=$! |
| 326 | |
| 327 | if wait $test_pid |
| 328 | then |
| 329 | printf "OK %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt |
| 330 | else |
| 331 | echo $GIT_TEST_STRESS_JOB_NR >>"$stressfail" |
| 332 | printf "FAIL %2d.%d\n" $GIT_TEST_STRESS_JOB_NR $cnt |
| 333 | fi |
| 334 | cnt=$(($cnt + 1)) |
| 335 | done |
| 336 | ) & |
| 337 | job_pids="$job_pids $!" |
| 338 | job_nr=$(($job_nr + 1)) |
| 339 | done |
| 340 | |
| 341 | wait |
| 342 | |
| 343 | if test -f "$stressfail" |
| 344 | then |
SZEDER Gábor | 76e27fb | 2019-02-08 12:50:45 +0100 | [diff] [blame] | 345 | stress_exit=1 |
SZEDER Gábor | fb7d1e3 | 2019-01-05 02:08:59 +0100 | [diff] [blame] | 346 | echo "Log(s) of failed test run(s):" |
| 347 | for failed_job_nr in $(sort -n "$stressfail") |
| 348 | do |
| 349 | echo "Contents of '$TEST_RESULTS_BASE.stress-$failed_job_nr.out':" |
| 350 | cat "$TEST_RESULTS_BASE.stress-$failed_job_nr.out" |
| 351 | done |
| 352 | rm -rf "$TRASH_DIRECTORY.stress-failed" |
| 353 | # Move the last one. |
| 354 | mv "$TRASH_DIRECTORY.stress-$failed_job_nr" "$TRASH_DIRECTORY.stress-failed" |
| 355 | fi |
| 356 | |
| 357 | exit $stress_exit |
| 358 | fi |
| 359 | |
Ramkumar Ramachandra | 4cde519 | 2012-09-22 10:25:10 +0530 | [diff] [blame] | 360 | # if --tee was passed, write the output not only to the terminal, but |
| 361 | # additionally to the file test-results/$BASENAME.out, too. |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 362 | if test "$GIT_TEST_TEE_STARTED" = "done" |
| 363 | then |
| 364 | : # do not redirect again |
| 365 | elif test -n "$tee" |
| 366 | then |
SZEDER Gábor | 62c379b | 2019-01-05 02:08:56 +0100 | [diff] [blame] | 367 | mkdir -p "$TEST_RESULTS_DIR" |
Jeff King | 452320f | 2016-10-21 06:48:00 -0400 | [diff] [blame] | 368 | |
| 369 | # Make this filename available to the sub-process in case it is using |
| 370 | # --verbose-log. |
SZEDER Gábor | 62c379b | 2019-01-05 02:08:56 +0100 | [diff] [blame] | 371 | GIT_TEST_TEE_OUTPUT_FILE=$TEST_RESULTS_BASE.out |
Jeff King | 452320f | 2016-10-21 06:48:00 -0400 | [diff] [blame] | 372 | export GIT_TEST_TEE_OUTPUT_FILE |
| 373 | |
| 374 | # Truncate before calling "tee -a" to get rid of the results |
| 375 | # from any previous runs. |
| 376 | >"$GIT_TEST_TEE_OUTPUT_FILE" |
| 377 | |
Jeff King | 3f824e9 | 2017-12-08 05:47:22 -0500 | [diff] [blame] | 378 | (GIT_TEST_TEE_STARTED=done ${TEST_SHELL_PATH} "$0" "$@" 2>&1; |
SZEDER Gábor | 62c379b | 2019-01-05 02:08:56 +0100 | [diff] [blame] | 379 | echo $? >"$TEST_RESULTS_BASE.exit") | tee -a "$GIT_TEST_TEE_OUTPUT_FILE" |
| 380 | test "$(cat "$TEST_RESULTS_BASE.exit")" = 0 |
Ramkumar Ramachandra | 4cde519 | 2012-09-22 10:25:10 +0530 | [diff] [blame] | 381 | exit |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 382 | fi |
| 383 | |
| 384 | if test -n "$trace" && test -n "$test_untraceable" |
| 385 | then |
| 386 | # '-x' tracing requested, but this test script can't be reliably |
| 387 | # traced, unless it is run with a Bash version supporting |
| 388 | # BASH_XTRACEFD (introduced in Bash v4.1). |
| 389 | # |
| 390 | # Perform this version check _after_ the test script was |
| 391 | # potentially re-executed with $TEST_SHELL_PATH for '--tee' or |
| 392 | # '--verbose-log', so the right shell is checked and the |
| 393 | # warning is issued only once. |
| 394 | if test -n "$BASH_VERSION" && eval ' |
| 395 | test ${BASH_VERSINFO[0]} -gt 4 || { |
| 396 | test ${BASH_VERSINFO[0]} -eq 4 && |
| 397 | test ${BASH_VERSINFO[1]} -ge 1 |
| 398 | } |
| 399 | ' |
| 400 | then |
| 401 | : Executed by a Bash version supporting BASH_XTRACEFD. Good. |
| 402 | else |
| 403 | echo >&2 "warning: ignoring -x; '$0' is untraceable without BASH_XTRACEFD" |
| 404 | trace= |
| 405 | fi |
| 406 | fi |
| 407 | if test -n "$trace" && test -z "$verbose_log" |
| 408 | then |
| 409 | verbose=t |
| 410 | fi |
Ramkumar Ramachandra | 4cde519 | 2012-09-22 10:25:10 +0530 | [diff] [blame] | 411 | |
Felipe Contreras | 390b44e | 2021-08-05 14:48:25 -0500 | [diff] [blame] | 412 | # Since bash 5.0, checkwinsize is enabled by default which does |
| 413 | # update the COLUMNS variable every time a non-builtin command |
| 414 | # completes, even for non-interactive shells. |
| 415 | # Disable that since we are aiming for repeatability. |
| 416 | test -n "$BASH_VERSION" && shopt -u checkwinsize 2>/dev/null |
| 417 | |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 418 | # For repeatability, reset the environment to known value. |
Richard Hansen | d5c1b7c | 2015-06-17 17:11:21 -0400 | [diff] [blame] | 419 | # TERM is sanitized below, after saving color control sequences. |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 420 | LANG=C |
| 421 | LC_ALL=C |
| 422 | PAGER=cat |
| 423 | TZ=UTC |
Ævar Arnfjörð Bjarmason | c49a177 | 2021-06-29 13:29:36 +0200 | [diff] [blame] | 424 | COLUMNS=80 |
| 425 | export LANG LC_ALL PAGER TZ COLUMNS |
Eric Wong | 8ff99e7 | 2006-07-11 12:01:54 -0700 | [diff] [blame] | 426 | EDITOR=: |
Ævar Arnfjörð Bjarmason | 6cdccfc | 2018-11-08 21:15:29 +0000 | [diff] [blame] | 427 | |
Stefano Lattarini | 661bfd1 | 2012-03-02 19:48:36 +0100 | [diff] [blame] | 428 | # A call to "unset" with no arguments causes at least Solaris 10 |
| 429 | # /usr/xpg4/bin/sh and /bin/ksh to bail out. So keep the unsets |
| 430 | # deriving from the command substitution clustered with the other |
| 431 | # ones. |
Ævar Arnfjörð Bjarmason | c49a177 | 2021-06-29 13:29:36 +0200 | [diff] [blame] | 432 | unset VISUAL EMAIL LANGUAGE $("$PERL_PATH" -e ' |
Jonathan Nieder | 95a1d12 | 2011-03-15 05:10:45 -0500 | [diff] [blame] | 433 | my @env = keys %ENV; |
Jens Lehmann | 730477f | 2011-03-28 21:16:09 +0200 | [diff] [blame] | 434 | my $ok = join("|", qw( |
| 435 | TRACE |
| 436 | DEBUG |
Jens Lehmann | 730477f | 2011-03-28 21:16:09 +0200 | [diff] [blame] | 437 | TEST |
| 438 | .*_TEST |
| 439 | PROVE |
| 440 | VALGRIND |
René Scharfe | ac00128 | 2013-01-06 18:47:57 +0100 | [diff] [blame] | 441 | UNZIP |
Nguyễn Thái Ngọc Duy | edb5408 | 2013-01-15 20:50:56 +0700 | [diff] [blame] | 442 | PERF_ |
Jeff King | e2a0ccc | 2014-05-22 05:28:50 -0400 | [diff] [blame] | 443 | CURL_VERBOSE |
Elia Pinto | 4527aa1 | 2016-09-05 10:24:42 +0000 | [diff] [blame] | 444 | TRACE_CURL |
Jens Lehmann | 730477f | 2011-03-28 21:16:09 +0200 | [diff] [blame] | 445 | )); |
| 446 | my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); |
Jonathan Nieder | 95a1d12 | 2011-03-15 05:10:45 -0500 | [diff] [blame] | 447 | print join("\n", @vars); |
| 448 | ') |
Genki Sky | 7976e90 | 2018-02-15 21:46:04 -0500 | [diff] [blame] | 449 | unset XDG_CACHE_HOME |
Jeff King | 5adf84e | 2012-07-24 07:53:05 -0400 | [diff] [blame] | 450 | unset XDG_CONFIG_HOME |
Benoit Person | 8bade1e | 2013-07-04 22:38:55 +0200 | [diff] [blame] | 451 | unset GITPERLLIB |
Prarit Bhargava | d8b8217 | 2019-10-29 08:09:14 -0400 | [diff] [blame] | 452 | TEST_AUTHOR_LOCALNAME=author |
| 453 | TEST_AUTHOR_DOMAIN=example.com |
| 454 | GIT_AUTHOR_EMAIL=${TEST_AUTHOR_LOCALNAME}@${TEST_AUTHOR_DOMAIN} |
Junio C Hamano | 29e55cd | 2006-02-10 19:11:23 -0800 | [diff] [blame] | 455 | GIT_AUTHOR_NAME='A U Thor' |
Jeff King | f2e3937 | 2020-07-09 16:42:04 -0400 | [diff] [blame] | 456 | GIT_AUTHOR_DATE='1112354055 +0200' |
Prarit Bhargava | d8b8217 | 2019-10-29 08:09:14 -0400 | [diff] [blame] | 457 | TEST_COMMITTER_LOCALNAME=committer |
| 458 | TEST_COMMITTER_DOMAIN=example.com |
| 459 | GIT_COMMITTER_EMAIL=${TEST_COMMITTER_LOCALNAME}@${TEST_COMMITTER_DOMAIN} |
Junio C Hamano | 29e55cd | 2006-02-10 19:11:23 -0800 | [diff] [blame] | 460 | GIT_COMMITTER_NAME='C O Mitter' |
Jeff King | f2e3937 | 2020-07-09 16:42:04 -0400 | [diff] [blame] | 461 | GIT_COMMITTER_DATE='1112354055 +0200' |
Shawn O. Pearce | 8d0fc48 | 2007-02-04 00:45:47 -0500 | [diff] [blame] | 462 | GIT_MERGE_VERBOSITY=5 |
Junio C Hamano | f824628 | 2012-01-10 22:44:45 -0800 | [diff] [blame] | 463 | GIT_MERGE_AUTOEDIT=no |
| 464 | export GIT_MERGE_VERBOSITY GIT_MERGE_AUTOEDIT |
Junio C Hamano | 29e55cd | 2006-02-10 19:11:23 -0800 | [diff] [blame] | 465 | export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME |
| 466 | export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME |
Jeff King | f2e3937 | 2020-07-09 16:42:04 -0400 | [diff] [blame] | 467 | export GIT_COMMITTER_DATE GIT_AUTHOR_DATE |
Jonathan Nieder | d33738d | 2009-11-11 17:56:07 -0600 | [diff] [blame] | 468 | export EDITOR |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 469 | |
brian m. carlson | 02a32db | 2020-07-29 23:14:24 +0000 | [diff] [blame] | 470 | GIT_DEFAULT_HASH="${GIT_TEST_DEFAULT_HASH:-sha1}" |
| 471 | export GIT_DEFAULT_HASH |
Elijah Newren | f3b964a | 2021-03-20 00:03:56 +0000 | [diff] [blame] | 472 | GIT_TEST_MERGE_ALGORITHM="${GIT_TEST_MERGE_ALGORITHM:-ort}" |
| 473 | export GIT_TEST_MERGE_ALGORITHM |
brian m. carlson | 02a32db | 2020-07-29 23:14:24 +0000 | [diff] [blame] | 474 | |
Karsten Blees | 124647c | 2014-07-12 02:03:01 +0200 | [diff] [blame] | 475 | # Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output |
| 476 | GIT_TRACE_BARE=1 |
| 477 | export GIT_TRACE_BARE |
| 478 | |
Ben Peart | 1f357b0 | 2018-09-18 23:29:36 +0000 | [diff] [blame] | 479 | # Use specific version of the index file format |
| 480 | if test -n "${GIT_TEST_INDEX_VERSION:+isset}" |
Thomas Gummerer | 5d9fc88 | 2014-02-23 21:49:58 +0100 | [diff] [blame] | 481 | then |
Ben Peart | 1f357b0 | 2018-09-18 23:29:36 +0000 | [diff] [blame] | 482 | GIT_INDEX_VERSION="$GIT_TEST_INDEX_VERSION" |
Thomas Gummerer | 5d9fc88 | 2014-02-23 21:49:58 +0100 | [diff] [blame] | 483 | export GIT_INDEX_VERSION |
| 484 | fi |
| 485 | |
Jeff King | 5338ed2 | 2020-10-21 23:24:00 -0400 | [diff] [blame] | 486 | if test -n "$GIT_TEST_PERL_FATAL_WARNINGS" |
| 487 | then |
| 488 | GIT_PERL_FATAL_WARNINGS=1 |
| 489 | export GIT_PERL_FATAL_WARNINGS |
| 490 | fi |
| 491 | |
Elia Pinto | a731fa9 | 2012-09-14 09:54:22 -0700 | [diff] [blame] | 492 | # Add libc MALLOC and MALLOC_PERTURB test |
| 493 | # only if we are not executing the test with valgrind |
SZEDER Gábor | 8cf5800 | 2019-01-05 02:08:55 +0100 | [diff] [blame] | 494 | if test -n "$valgrind" || |
René Scharfe | ee1431b | 2012-09-26 22:16:39 +0200 | [diff] [blame] | 495 | test -n "$TEST_NO_MALLOC_CHECK" |
Junio C Hamano | 1b3185f | 2012-09-14 20:38:24 -0700 | [diff] [blame] | 496 | then |
| 497 | setup_malloc_check () { |
| 498 | : nothing |
| 499 | } |
| 500 | teardown_malloc_check () { |
| 501 | : nothing |
| 502 | } |
| 503 | else |
| 504 | setup_malloc_check () { |
| 505 | MALLOC_CHECK_=3 MALLOC_PERTURB_=165 |
| 506 | export MALLOC_CHECK_ MALLOC_PERTURB_ |
| 507 | } |
| 508 | teardown_malloc_check () { |
| 509 | unset MALLOC_CHECK_ MALLOC_PERTURB_ |
| 510 | } |
| 511 | fi |
Elia Pinto | a731fa9 | 2012-09-14 09:54:22 -0700 | [diff] [blame] | 512 | |
Junio C Hamano | 886a390 | 2007-04-24 11:21:47 -0700 | [diff] [blame] | 513 | # Protect ourselves from common misconfiguration to export |
| 514 | # CDPATH into the environment |
| 515 | unset CDPATH |
| 516 | |
Bert Wesarg | 5565f47 | 2009-11-18 17:15:19 +0100 | [diff] [blame] | 517 | unset GREP_OPTIONS |
René Scharfe | ac00128 | 2013-01-06 18:47:57 +0100 | [diff] [blame] | 518 | unset UNZIP |
Bert Wesarg | 5565f47 | 2009-11-18 17:15:19 +0100 | [diff] [blame] | 519 | |
Robin Rosenberg | 3d5c0cc | 2006-09-23 00:35:20 +0200 | [diff] [blame] | 520 | case $(echo $GIT_TRACE |tr "[A-Z]" "[a-z]") in |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 521 | 1|2|true) |
Jeff King | 025232e | 2015-03-13 00:50:56 -0400 | [diff] [blame] | 522 | GIT_TRACE=4 |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 523 | ;; |
Christian Couder | 6ce4e61 | 2006-09-02 18:23:48 +0200 | [diff] [blame] | 524 | esac |
| 525 | |
Junio C Hamano | 3f4ab62 | 2011-08-08 11:51:00 -0700 | [diff] [blame] | 526 | # Line feed |
| 527 | LF=' |
| 528 | ' |
| 529 | |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 530 | # Single quote |
| 531 | SQ=\' |
| 532 | |
Jeff King | a42643a | 2014-12-15 18:15:20 -0500 | [diff] [blame] | 533 | # UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores |
| 534 | # when case-folding filenames |
| 535 | u200c=$(printf '\342\200\214') |
| 536 | |
Ævar Arnfjörð Bjarmason | 7050791 | 2021-09-11 13:17:51 +0200 | [diff] [blame] | 537 | export _x05 _x35 LF u200c EMPTY_TREE EMPTY_BLOB ZERO_OID OID_REGEX |
Thomas Rast | 342e9ef | 2012-02-17 11:25:09 +0100 | [diff] [blame] | 538 | |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 539 | # Each test should start with something like this, after copyright notices: |
| 540 | # |
| 541 | # test_description='Description of this test... |
| 542 | # This test checks if command xyzzy does the right thing... |
| 543 | # ' |
| 544 | # . ./test-lib.sh |
Richard Hansen | d5c1b7c | 2015-06-17 17:11:21 -0400 | [diff] [blame] | 545 | test "x$TERM" != "xdumb" && ( |
Richard Hansen | ca92a66 | 2015-06-17 15:06:25 -0400 | [diff] [blame] | 546 | test -t 1 && |
| 547 | tput bold >/dev/null 2>&1 && |
| 548 | tput setaf 1 >/dev/null 2>&1 && |
| 549 | tput sgr0 >/dev/null 2>&1 |
| 550 | ) && |
| 551 | color=t |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 552 | |
Richard Hansen | ca92a66 | 2015-06-17 15:06:25 -0400 | [diff] [blame] | 553 | if test -n "$color" |
| 554 | then |
Richard Hansen | d5c1b7c | 2015-06-17 17:11:21 -0400 | [diff] [blame] | 555 | # Save the color control sequences now rather than run tput |
| 556 | # each time say_color() is called. This is done for two |
| 557 | # reasons: |
| 558 | # * TERM will be changed to dumb |
| 559 | # * HOME will be changed to a temporary directory and tput |
| 560 | # might need to read ~/.terminfo from the original HOME |
| 561 | # directory to get the control sequences |
| 562 | # Note: This approach assumes the control sequences don't end |
| 563 | # in a newline for any terminal of interest (command |
| 564 | # substitutions strip trailing newlines). Given that most |
| 565 | # (all?) terminals in common use are related to ECMA-48, this |
| 566 | # shouldn't be a problem. |
| 567 | say_color_error=$(tput bold; tput setaf 1) # bold red |
| 568 | say_color_skip=$(tput setaf 4) # blue |
| 569 | say_color_warn=$(tput setaf 3) # brown/yellow |
| 570 | say_color_pass=$(tput setaf 2) # green |
| 571 | say_color_info=$(tput setaf 6) # cyan |
| 572 | say_color_reset=$(tput sgr0) |
| 573 | say_color_="" # no formatting for normal text |
Richard Hansen | ca92a66 | 2015-06-17 15:06:25 -0400 | [diff] [blame] | 574 | say_color () { |
Richard Hansen | d5c1b7c | 2015-06-17 17:11:21 -0400 | [diff] [blame] | 575 | test -z "$1" && test -n "$quiet" && return |
| 576 | eval "say_color_color=\$say_color_$1" |
Richard Hansen | ca92a66 | 2015-06-17 15:06:25 -0400 | [diff] [blame] | 577 | shift |
Richard Hansen | d5c1b7c | 2015-06-17 17:11:21 -0400 | [diff] [blame] | 578 | printf "%s\\n" "$say_color_color$*$say_color_reset" |
Richard Hansen | ca92a66 | 2015-06-17 15:06:25 -0400 | [diff] [blame] | 579 | } |
| 580 | else |
| 581 | say_color() { |
| 582 | test -z "$1" && test -n "$quiet" && return |
| 583 | shift |
| 584 | printf "%s\n" "$*" |
| 585 | } |
| 586 | fi |
| 587 | |
Philippe Blain | add5240 | 2021-09-06 04:38:59 +0000 | [diff] [blame] | 588 | USER_TERM="$TERM" |
Richard Hansen | d5c1b7c | 2015-06-17 17:11:21 -0400 | [diff] [blame] | 589 | TERM=dumb |
Philippe Blain | add5240 | 2021-09-06 04:38:59 +0000 | [diff] [blame] | 590 | export TERM USER_TERM |
Richard Hansen | d5c1b7c | 2015-06-17 17:11:21 -0400 | [diff] [blame] | 591 | |
Ævar Arnfjörð Bjarmason | 8583bf7 | 2021-10-14 02:47:28 +0200 | [diff] [blame] | 592 | _error_exit () { |
Johannes Schindelin | ab7d854 | 2019-10-04 08:09:34 -0700 | [diff] [blame] | 593 | finalize_junit_xml |
Clemens Buchacher | 6e7b5aa | 2009-06-01 14:14:41 +0200 | [diff] [blame] | 594 | GIT_EXIT_OK=t |
Pierre Habouzit | 55db1df | 2007-10-24 22:03:38 +0200 | [diff] [blame] | 595 | exit 1 |
| 596 | } |
| 597 | |
Ævar Arnfjörð Bjarmason | 8583bf7 | 2021-10-14 02:47:28 +0200 | [diff] [blame] | 598 | error () { |
| 599 | say_color error "error: $*" |
| 600 | _error_exit |
| 601 | } |
| 602 | |
SZEDER Gábor | 165293a | 2018-11-19 14:13:26 +0100 | [diff] [blame] | 603 | BUG () { |
| 604 | error >&7 "bug in the test script: $*" |
| 605 | } |
| 606 | |
Ævar Arnfjörð Bjarmason | 234383c | 2021-10-14 02:47:29 +0200 | [diff] [blame] | 607 | BAIL_OUT () { |
| 608 | test $# -ne 1 && BUG "1 param" |
| 609 | |
| 610 | # Do not change "Bail out! " string. It's part of TAP syntax: |
| 611 | # https://testanything.org/tap-specification.html |
| 612 | local bail_out="Bail out! " |
| 613 | local message="$1" |
| 614 | |
| 615 | say_color error $bail_out "$message" |
| 616 | _error_exit |
| 617 | } |
| 618 | |
Pierre Habouzit | 55db1df | 2007-10-24 22:03:38 +0200 | [diff] [blame] | 619 | say () { |
| 620 | say_color info "$*" |
| 621 | } |
| 622 | |
Jeff King | 614fe01 | 2016-10-22 00:45:06 -0400 | [diff] [blame] | 623 | if test -n "$HARNESS_ACTIVE" |
| 624 | then |
| 625 | if test "$verbose" = t || test -n "$verbose_only" |
| 626 | then |
Ævar Arnfjörð Bjarmason | 234383c | 2021-10-14 02:47:29 +0200 | [diff] [blame] | 627 | BAIL_OUT 'verbose mode forbidden under TAP harness; try --verbose-log' |
Jeff King | 614fe01 | 2016-10-22 00:45:06 -0400 | [diff] [blame] | 628 | fi |
| 629 | fi |
| 630 | |
Michele Ballabio | 570f322 | 2007-11-10 15:17:25 +0100 | [diff] [blame] | 631 | test "${test_description}" != "" || |
| 632 | error "Test script did not set test_description." |
| 633 | |
| 634 | if test "$help" = "t" |
| 635 | then |
Uwe Storbeck | cb1aefd | 2014-03-18 01:14:11 +0100 | [diff] [blame] | 636 | printf '%s\n' "$test_description" |
Michele Ballabio | 570f322 | 2007-11-10 15:17:25 +0100 | [diff] [blame] | 637 | exit 0 |
| 638 | fi |
| 639 | |
Pavel Roskin | 4d9d62f | 2005-08-10 23:56:21 -0400 | [diff] [blame] | 640 | exec 5>&1 |
Jeff King | 781f76b | 2011-12-15 01:55:29 -0500 | [diff] [blame] | 641 | exec 6<&0 |
SZEDER Gábor | 4ecae3c | 2017-03-18 17:13:59 +0100 | [diff] [blame] | 642 | exec 7>&2 |
Jeff King | 452320f | 2016-10-21 06:48:00 -0400 | [diff] [blame] | 643 | if test "$verbose_log" = "t" |
| 644 | then |
| 645 | exec 3>>"$GIT_TEST_TEE_OUTPUT_FILE" 4>&3 |
| 646 | elif test "$verbose" = "t" |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 647 | then |
| 648 | exec 4>&2 3>&1 |
| 649 | else |
| 650 | exec 4>/dev/null 3>/dev/null |
| 651 | fi |
| 652 | |
Jeff King | d88785e | 2016-05-11 09:44:04 -0400 | [diff] [blame] | 653 | # Send any "-x" output directly to stderr to avoid polluting tests |
| 654 | # which capture stderr. We can do this unconditionally since it |
| 655 | # has no effect if tracing isn't turned on. |
| 656 | # |
| 657 | # Note that this sets up the trace fd as soon as we assign the variable, so it |
| 658 | # must come after the creation of descriptor 4 above. Likewise, we must never |
| 659 | # unset this, as it has the side effect of closing descriptor 4, which we |
| 660 | # use to show verbose tests to the user. |
| 661 | # |
| 662 | # Note also that we don't need or want to export it. The tracing is local to |
| 663 | # this shell, and we would not want to influence any shells we exec. |
| 664 | BASH_XTRACEFD=4 |
| 665 | |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 666 | test_failure=0 |
| 667 | test_count=0 |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 668 | test_fixed=0 |
| 669 | test_broken=0 |
Sverre Rabbelier | 2d84e9f | 2008-06-08 16:04:33 +0200 | [diff] [blame] | 670 | test_success=0 |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 671 | |
Fabian Stelzer | 49da404 | 2021-11-20 16:03:59 +0100 | [diff] [blame^] | 672 | test_missing_prereq= |
| 673 | |
Ævar Arnfjörð Bjarmason | d998bd4 | 2010-06-24 17:44:46 +0000 | [diff] [blame] | 674 | test_external_has_tap=0 |
| 675 | |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 676 | die () { |
Clemens Buchacher | 6e7b5aa | 2009-06-01 14:14:41 +0200 | [diff] [blame] | 677 | code=$? |
Johannes Schindelin | 900721e | 2019-03-13 13:24:11 +0100 | [diff] [blame] | 678 | # This is responsible for running the atexit commands even when a |
| 679 | # test script run with '--immediate' fails, or when the user hits |
| 680 | # ctrl-C, i.e. when 'test_done' is not invoked at all. |
| 681 | test_atexit_handler || code=$? |
Clemens Buchacher | 6e7b5aa | 2009-06-01 14:14:41 +0200 | [diff] [blame] | 682 | if test -n "$GIT_EXIT_OK" |
| 683 | then |
| 684 | exit $code |
| 685 | else |
| 686 | echo >&5 "FATAL: Unexpected exit with code $code" |
| 687 | exit 1 |
| 688 | fi |
Clemens Buchacher | faa4bc3 | 2008-02-27 20:28:45 +0100 | [diff] [blame] | 689 | } |
| 690 | |
Clemens Buchacher | 6e7b5aa | 2009-06-01 14:14:41 +0200 | [diff] [blame] | 691 | GIT_EXIT_OK= |
Markus Heidelberg | 3564131 | 2009-01-20 00:43:26 +0100 | [diff] [blame] | 692 | trap 'die' EXIT |
SZEDER Gábor | c5c39f4 | 2019-03-13 13:24:09 +0100 | [diff] [blame] | 693 | # Disable '-x' tracing, because with some shells, notably dash, it |
| 694 | # prevents running the cleanup commands when a test script run with |
| 695 | # '--verbose-log -x' is interrupted. |
| 696 | trap '{ code=$?; set +x; } 2>/dev/null; exit $code' INT TERM HUP |
Pavel Roskin | 4118427 | 2005-08-11 12:00:40 -0400 | [diff] [blame] | 697 | |
Thomas Rast | 12a29b1 | 2012-02-17 11:25:08 +0100 | [diff] [blame] | 698 | # The user-facing functions are loaded from a separate file so that |
| 699 | # test_perf subshells can have them too |
Junio C Hamano | 3c8f12c | 2012-06-24 22:01:35 -0700 | [diff] [blame] | 700 | . "$TEST_DIRECTORY/test-lib-functions.sh" |
Jonathan Nieder | 05236a5 | 2010-10-17 02:36:58 +0800 | [diff] [blame] | 701 | |
Junio C Hamano | 886856a | 2005-05-14 00:24:27 -0700 | [diff] [blame] | 702 | # You are not expected to call test_ok_ and test_failure_ directly, use |
Torstein Hegge | 3fa3666 | 2013-10-27 10:56:33 +0100 | [diff] [blame] | 703 | # the test_expect_* functions instead. |
Junio C Hamano | 886856a | 2005-05-14 00:24:27 -0700 | [diff] [blame] | 704 | |
| 705 | test_ok_ () { |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 706 | if test -n "$write_junit_xml" |
| 707 | then |
| 708 | write_junit_xml_testcase "$*" |
| 709 | fi |
Johannes Sixt | d5d9de1 | 2009-02-05 20:59:27 +0100 | [diff] [blame] | 710 | test_success=$(($test_success + 1)) |
Thomas Rast | 633fe50 | 2013-10-19 23:06:08 +0200 | [diff] [blame] | 711 | say_color "" "ok $test_count - $@" |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 712 | } |
| 713 | |
Junio C Hamano | 886856a | 2005-05-14 00:24:27 -0700 | [diff] [blame] | 714 | test_failure_ () { |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 715 | if test -n "$write_junit_xml" |
| 716 | then |
| 717 | junit_insert="<failure message=\"not ok $test_count -" |
| 718 | junit_insert="$junit_insert $(xml_attr_encode "$1")\">" |
| 719 | junit_insert="$junit_insert $(xml_attr_encode \ |
Johannes Schindelin | af9912e | 2019-01-29 06:19:34 -0800 | [diff] [blame] | 720 | "$(if test -n "$GIT_TEST_TEE_OUTPUT_FILE" |
| 721 | then |
| 722 | test-tool path-utils skip-n-bytes \ |
| 723 | "$GIT_TEST_TEE_OUTPUT_FILE" $GIT_TEST_TEE_OFFSET |
| 724 | else |
| 725 | printf '%s\n' "$@" | sed 1d |
| 726 | fi)")" |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 727 | junit_insert="$junit_insert</failure>" |
Johannes Schindelin | af9912e | 2019-01-29 06:19:34 -0800 | [diff] [blame] | 728 | if test -n "$GIT_TEST_TEE_OUTPUT_FILE" |
| 729 | then |
| 730 | junit_insert="$junit_insert<system-err>$(xml_attr_encode \ |
| 731 | "$(cat "$GIT_TEST_TEE_OUTPUT_FILE")")</system-err>" |
| 732 | fi |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 733 | write_junit_xml_testcase "$1" " $junit_insert" |
| 734 | fi |
Johannes Sixt | d5d9de1 | 2009-02-05 20:59:27 +0100 | [diff] [blame] | 735 | test_failure=$(($test_failure + 1)) |
Junio C Hamano | e31600b | 2020-05-15 09:47:51 -0700 | [diff] [blame] | 736 | say_color error "not ok $test_count - $1" |
Junio C Hamano | bf0dd8a | 2005-07-22 19:09:34 -0700 | [diff] [blame] | 737 | shift |
Uwe Storbeck | cb1aefd | 2014-03-18 01:14:11 +0100 | [diff] [blame] | 738 | printf '%s\n' "$*" | sed -e 's/^/# /' |
Ævar Arnfjörð Bjarmason | 8583bf7 | 2021-10-14 02:47:28 +0200 | [diff] [blame] | 739 | test "$immediate" = "" || _error_exit |
Junio C Hamano | 886856a | 2005-05-14 00:24:27 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 742 | test_known_broken_ok_ () { |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 743 | if test -n "$write_junit_xml" |
| 744 | then |
| 745 | write_junit_xml_testcase "$* (breakage fixed)" |
| 746 | fi |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 747 | test_fixed=$(($test_fixed+1)) |
Thomas Rast | 633fe50 | 2013-10-19 23:06:08 +0200 | [diff] [blame] | 748 | say_color error "ok $test_count - $@ # TODO known breakage vanished" |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | test_known_broken_failure_ () { |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 752 | if test -n "$write_junit_xml" |
| 753 | then |
| 754 | write_junit_xml_testcase "$* (known breakage)" |
| 755 | fi |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 756 | test_broken=$(($test_broken+1)) |
Thomas Rast | 633fe50 | 2013-10-19 23:06:08 +0200 | [diff] [blame] | 757 | say_color warn "not ok $test_count - $@ # TODO known breakage" |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 758 | } |
Junio C Hamano | 886856a | 2005-05-14 00:24:27 -0700 | [diff] [blame] | 759 | |
| 760 | test_debug () { |
Junio C Hamano | 8e832eb | 2005-08-10 22:53:27 -0700 | [diff] [blame] | 761 | test "$debug" = "" || eval "$1" |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 762 | } |
| 763 | |
Thomas Rast | e6a6ddc | 2013-06-18 14:25:58 +0200 | [diff] [blame] | 764 | match_pattern_list () { |
| 765 | arg="$1" |
| 766 | shift |
| 767 | test -z "$*" && return 1 |
Jeff King | 560bf51 | 2021-06-16 06:23:07 -0400 | [diff] [blame] | 768 | # We need to use "$*" to get field-splitting, but we want to |
| 769 | # disable globbing, since we are matching against an arbitrary |
| 770 | # $arg, not what's in the filesystem. Using "set -f" accomplishes |
| 771 | # that, but we must do it in a subshell to avoid impacting the |
| 772 | # rest of the script. The exit value of the subshell becomes |
| 773 | # the function's return value. |
| 774 | ( |
| 775 | set -f |
| 776 | for pattern_ in $* |
| 777 | do |
| 778 | case "$arg" in |
| 779 | $pattern_) |
| 780 | exit 0 |
| 781 | ;; |
| 782 | esac |
| 783 | done |
| 784 | exit 1 |
| 785 | ) |
Thomas Rast | e6a6ddc | 2013-06-18 14:25:58 +0200 | [diff] [blame] | 786 | } |
| 787 | |
Ilya Bobyr | 0445e6f | 2014-04-30 02:50:44 -0700 | [diff] [blame] | 788 | match_test_selector_list () { |
Elijah Newren | f21ac36 | 2020-10-18 00:23:45 +0000 | [diff] [blame] | 789 | operation="$1" |
| 790 | shift |
Ilya Bobyr | 0445e6f | 2014-04-30 02:50:44 -0700 | [diff] [blame] | 791 | title="$1" |
| 792 | shift |
| 793 | arg="$1" |
| 794 | shift |
| 795 | test -z "$1" && return 0 |
| 796 | |
Elijah Newren | f21ac36 | 2020-10-18 00:23:45 +0000 | [diff] [blame] | 797 | # Commas are accepted as separators. |
Ilya Bobyr | 0445e6f | 2014-04-30 02:50:44 -0700 | [diff] [blame] | 798 | OLDIFS=$IFS |
Elijah Newren | f21ac36 | 2020-10-18 00:23:45 +0000 | [diff] [blame] | 799 | IFS=',' |
Ilya Bobyr | 0445e6f | 2014-04-30 02:50:44 -0700 | [diff] [blame] | 800 | set -- $1 |
| 801 | IFS=$OLDIFS |
| 802 | |
| 803 | # If the first selector is negative we include by default. |
| 804 | include= |
| 805 | case "$1" in |
| 806 | !*) include=t ;; |
| 807 | esac |
| 808 | |
| 809 | for selector |
| 810 | do |
| 811 | orig_selector=$selector |
| 812 | |
| 813 | positive=t |
| 814 | case "$selector" in |
| 815 | !*) |
| 816 | positive= |
| 817 | selector=${selector##?} |
| 818 | ;; |
| 819 | esac |
| 820 | |
| 821 | test -z "$selector" && continue |
| 822 | |
| 823 | case "$selector" in |
| 824 | *-*) |
| 825 | if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null |
| 826 | then |
Elijah Newren | f21ac36 | 2020-10-18 00:23:45 +0000 | [diff] [blame] | 827 | echo "error: $operation: invalid non-numeric in range" \ |
Ilya Bobyr | 0445e6f | 2014-04-30 02:50:44 -0700 | [diff] [blame] | 828 | "start: '$orig_selector'" >&2 |
| 829 | exit 1 |
| 830 | fi |
| 831 | if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null |
| 832 | then |
Elijah Newren | f21ac36 | 2020-10-18 00:23:45 +0000 | [diff] [blame] | 833 | echo "error: $operation: invalid non-numeric in range" \ |
Ilya Bobyr | 0445e6f | 2014-04-30 02:50:44 -0700 | [diff] [blame] | 834 | "end: '$orig_selector'" >&2 |
| 835 | exit 1 |
| 836 | fi |
| 837 | ;; |
| 838 | *) |
| 839 | if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null |
| 840 | then |
Elijah Newren | f21ac36 | 2020-10-18 00:23:45 +0000 | [diff] [blame] | 841 | case "$title" in *${selector}*) |
| 842 | include=$positive |
| 843 | ;; |
| 844 | esac |
| 845 | continue |
Ilya Bobyr | 0445e6f | 2014-04-30 02:50:44 -0700 | [diff] [blame] | 846 | fi |
| 847 | esac |
| 848 | |
| 849 | # Short cut for "obvious" cases |
| 850 | test -z "$include" && test -z "$positive" && continue |
| 851 | test -n "$include" && test -n "$positive" && continue |
| 852 | |
| 853 | case "$selector" in |
| 854 | -*) |
| 855 | if test $arg -le ${selector#-} |
| 856 | then |
| 857 | include=$positive |
| 858 | fi |
| 859 | ;; |
| 860 | *-) |
| 861 | if test $arg -ge ${selector%-} |
| 862 | then |
| 863 | include=$positive |
| 864 | fi |
| 865 | ;; |
| 866 | *-*) |
| 867 | if test ${selector%%-*} -le $arg \ |
| 868 | && test $arg -le ${selector#*-} |
| 869 | then |
| 870 | include=$positive |
| 871 | fi |
| 872 | ;; |
| 873 | *) |
| 874 | if test $arg -eq $selector |
| 875 | then |
| 876 | include=$positive |
| 877 | fi |
| 878 | ;; |
| 879 | esac |
| 880 | done |
| 881 | |
| 882 | test -n "$include" |
| 883 | } |
| 884 | |
Thomas Rast | ff09af3 | 2013-06-23 20:12:56 +0200 | [diff] [blame] | 885 | maybe_teardown_verbose () { |
| 886 | test -z "$verbose_only" && return |
| 887 | exec 4>/dev/null 3>/dev/null |
| 888 | verbose= |
| 889 | } |
| 890 | |
| 891 | last_verbose=t |
| 892 | maybe_setup_verbose () { |
| 893 | test -z "$verbose_only" && return |
Jeff King | 560bf51 | 2021-06-16 06:23:07 -0400 | [diff] [blame] | 894 | if match_pattern_list $test_count "$verbose_only" |
Thomas Rast | ff09af3 | 2013-06-23 20:12:56 +0200 | [diff] [blame] | 895 | then |
| 896 | exec 4>&2 3>&1 |
| 897 | # Emit a delimiting blank line when going from |
| 898 | # non-verbose to verbose. Within verbose mode the |
| 899 | # delimiter is printed by test_expect_*. The choice |
| 900 | # of the initial $last_verbose is such that before |
| 901 | # test 1, we do not print it. |
| 902 | test -z "$last_verbose" && echo >&3 "" |
| 903 | verbose=t |
| 904 | else |
| 905 | exec 4>/dev/null 3>/dev/null |
| 906 | verbose= |
| 907 | fi |
| 908 | last_verbose=$verbose |
| 909 | } |
| 910 | |
Thomas Rast | 5dfc368 | 2013-06-23 20:12:57 +0200 | [diff] [blame] | 911 | maybe_teardown_valgrind () { |
| 912 | test -z "$GIT_VALGRIND" && return |
| 913 | GIT_VALGRIND_ENABLED= |
| 914 | } |
| 915 | |
| 916 | maybe_setup_valgrind () { |
| 917 | test -z "$GIT_VALGRIND" && return |
Thomas Rast | 26a0730 | 2013-10-19 23:06:07 +0200 | [diff] [blame] | 918 | if test -z "$valgrind_only" |
Thomas Rast | 5dfc368 | 2013-06-23 20:12:57 +0200 | [diff] [blame] | 919 | then |
| 920 | GIT_VALGRIND_ENABLED=t |
| 921 | return |
| 922 | fi |
| 923 | GIT_VALGRIND_ENABLED= |
Jeff King | 560bf51 | 2021-06-16 06:23:07 -0400 | [diff] [blame] | 924 | if match_pattern_list $test_count "$valgrind_only" |
Thomas Rast | 5dfc368 | 2013-06-23 20:12:57 +0200 | [diff] [blame] | 925 | then |
| 926 | GIT_VALGRIND_ENABLED=t |
| 927 | fi |
| 928 | } |
| 929 | |
Johannes Schindelin | 477dcad | 2020-03-26 15:35:26 +0000 | [diff] [blame] | 930 | trace_level_=0 |
Jeff King | 9b5fe78 | 2015-08-06 01:33:57 -0400 | [diff] [blame] | 931 | want_trace () { |
Jeff King | f5ba2de | 2017-12-08 05:47:17 -0500 | [diff] [blame] | 932 | test "$trace" = t && { |
| 933 | test "$verbose" = t || test "$verbose_log" = t |
| 934 | } |
Jeff King | 9b5fe78 | 2015-08-06 01:33:57 -0400 | [diff] [blame] | 935 | } |
| 936 | |
Jeff King | a136f6d | 2014-10-10 02:47:27 -0400 | [diff] [blame] | 937 | # This is a separate function because some tests use |
| 938 | # "return" to end a test_expect_success block early |
| 939 | # (and we want to make sure we run any cleanup like |
| 940 | # "set +x"). |
| 941 | test_eval_inner_ () { |
| 942 | # Do not add anything extra (including LF) after '$*' |
| 943 | eval " |
Johannes Schindelin | 477dcad | 2020-03-26 15:35:26 +0000 | [diff] [blame] | 944 | want_trace && trace_level_=$(($trace_level_+1)) && set -x |
Jeff King | a136f6d | 2014-10-10 02:47:27 -0400 | [diff] [blame] | 945 | $*" |
| 946 | } |
| 947 | |
Jonathan Nieder | a7c58f2 | 2011-08-08 03:17:09 +0200 | [diff] [blame] | 948 | test_eval_ () { |
Jeff King | 90c8a1d | 2017-12-08 05:47:08 -0500 | [diff] [blame] | 949 | # If "-x" tracing is in effect, then we want to avoid polluting stderr |
| 950 | # with non-test commands. But once in "set -x" mode, we cannot prevent |
Jeff King | a136f6d | 2014-10-10 02:47:27 -0400 | [diff] [blame] | 951 | # the shell from printing the "set +x" to turn it off (nor the saving |
| 952 | # of $? before that). But we can make sure that the output goes to |
| 953 | # /dev/null. |
| 954 | # |
Jeff King | 90c8a1d | 2017-12-08 05:47:08 -0500 | [diff] [blame] | 955 | # There are a few subtleties here: |
| 956 | # |
| 957 | # - we have to redirect descriptor 4 in addition to 2, to cover |
| 958 | # BASH_XTRACEFD |
| 959 | # |
| 960 | # - the actual eval has to come before the redirection block (since |
| 961 | # it needs to see descriptor 4 to set up its stderr) |
| 962 | # |
| 963 | # - likewise, any error message we print must be outside the block to |
| 964 | # access descriptor 4 |
| 965 | # |
| 966 | # - checking $? has to come immediately after the eval, but it must |
| 967 | # be _inside_ the block to avoid polluting the "set -x" output |
| 968 | # |
| 969 | |
| 970 | test_eval_inner_ "$@" </dev/null >&3 2>&4 |
Jeff King | a136f6d | 2014-10-10 02:47:27 -0400 | [diff] [blame] | 971 | { |
Jeff King | a136f6d | 2014-10-10 02:47:27 -0400 | [diff] [blame] | 972 | test_eval_ret_=$? |
Jeff King | 9b5fe78 | 2015-08-06 01:33:57 -0400 | [diff] [blame] | 973 | if want_trace |
Jeff King | a136f6d | 2014-10-10 02:47:27 -0400 | [diff] [blame] | 974 | then |
Johannes Schindelin | 477dcad | 2020-03-26 15:35:26 +0000 | [diff] [blame] | 975 | test 1 = $trace_level_ && set +x |
| 976 | trace_level_=$(($trace_level_-1)) |
Jeff King | a136f6d | 2014-10-10 02:47:27 -0400 | [diff] [blame] | 977 | fi |
Jeff King | 90c8a1d | 2017-12-08 05:47:08 -0500 | [diff] [blame] | 978 | } 2>/dev/null 4>&2 |
| 979 | |
| 980 | if test "$test_eval_ret_" != 0 && want_trace |
| 981 | then |
| 982 | say_color error >&4 "error: last command exited with \$?=$test_eval_ret_" |
| 983 | fi |
Jeff King | a136f6d | 2014-10-10 02:47:27 -0400 | [diff] [blame] | 984 | return $test_eval_ret_ |
Jonathan Nieder | a7c58f2 | 2011-08-08 03:17:09 +0200 | [diff] [blame] | 985 | } |
| 986 | |
Pavel Roskin | 4d9d62f | 2005-08-10 23:56:21 -0400 | [diff] [blame] | 987 | test_run_ () { |
Jonathan Nieder | b6b0afd | 2010-05-06 03:41:10 -0500 | [diff] [blame] | 988 | test_cleanup=: |
Junio C Hamano | b586744 | 2011-06-27 11:02:22 -0700 | [diff] [blame] | 989 | expecting_failure=$2 |
Jeff King | bb79af9 | 2015-03-20 06:05:48 -0400 | [diff] [blame] | 990 | |
Jeff King | 92b269f | 2015-04-22 16:09:57 -0400 | [diff] [blame] | 991 | if test "${GIT_TEST_CHAIN_LINT:-1}" != 0; then |
Jeff King | 2a01ef8 | 2015-08-06 01:31:47 -0400 | [diff] [blame] | 992 | # turn off tracing for this test-eval, as it simply creates |
| 993 | # confusing noise in the "-x" output |
| 994 | trace_tmp=$trace |
| 995 | trace= |
Jeff King | bb79af9 | 2015-03-20 06:05:48 -0400 | [diff] [blame] | 996 | # 117 is magic because it is unlikely to match the exit |
| 997 | # code of other programs |
Jeff King | 2d86a96 | 2021-05-13 02:25:53 -0400 | [diff] [blame] | 998 | if test "OK-117" != "$(test_eval_ "(exit 117) && $1${LF}${LF}echo OK-\$?" 3>&1)" || |
| 999 | { |
| 1000 | test "${GIT_TEST_CHAIN_LINT_HARDER:-${GIT_TEST_CHAIN_LINT_HARDER_DEFAULT:-1}}" != 0 && |
| 1001 | $(printf '%s\n' "$1" | sed -f "$GIT_BUILD_DIR/t/chainlint.sed" | grep -q '?![A-Z][A-Z]*?!') |
| 1002 | } |
Junio C Hamano | 99a64e4 | 2017-03-22 22:43:18 -0700 | [diff] [blame] | 1003 | then |
SZEDER Gábor | 165293a | 2018-11-19 14:13:26 +0100 | [diff] [blame] | 1004 | BUG "broken &&-chain or run-away HERE-DOC: $1" |
Jeff King | bb79af9 | 2015-03-20 06:05:48 -0400 | [diff] [blame] | 1005 | fi |
Jeff King | 2a01ef8 | 2015-08-06 01:31:47 -0400 | [diff] [blame] | 1006 | trace=$trace_tmp |
Jeff King | bb79af9 | 2015-03-20 06:05:48 -0400 | [diff] [blame] | 1007 | fi |
| 1008 | |
Thomas Rast | a57397b | 2013-06-17 11:18:46 +0200 | [diff] [blame] | 1009 | setup_malloc_check |
Jonathan Nieder | a7c58f2 | 2011-08-08 03:17:09 +0200 | [diff] [blame] | 1010 | test_eval_ "$1" |
Jonathan Nieder | b6b0afd | 2010-05-06 03:41:10 -0500 | [diff] [blame] | 1011 | eval_ret=$? |
Thomas Rast | a57397b | 2013-06-17 11:18:46 +0200 | [diff] [blame] | 1012 | teardown_malloc_check |
Junio C Hamano | b586744 | 2011-06-27 11:02:22 -0700 | [diff] [blame] | 1013 | |
Jeff King | a136f6d | 2014-10-10 02:47:27 -0400 | [diff] [blame] | 1014 | if test -z "$immediate" || test $eval_ret = 0 || |
| 1015 | test -n "$expecting_failure" && test "$test_cleanup" != ":" |
Junio C Hamano | b586744 | 2011-06-27 11:02:22 -0700 | [diff] [blame] | 1016 | then |
Junio C Hamano | 1b3185f | 2012-09-14 20:38:24 -0700 | [diff] [blame] | 1017 | setup_malloc_check |
Jonathan Nieder | a7c58f2 | 2011-08-08 03:17:09 +0200 | [diff] [blame] | 1018 | test_eval_ "$test_cleanup" |
Junio C Hamano | 1b3185f | 2012-09-14 20:38:24 -0700 | [diff] [blame] | 1019 | teardown_malloc_check |
Junio C Hamano | b586744 | 2011-06-27 11:02:22 -0700 | [diff] [blame] | 1020 | fi |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 1021 | if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE" |
| 1022 | then |
Ævar Arnfjörð Bjarmason | 57e1538 | 2010-06-24 17:44:47 +0000 | [diff] [blame] | 1023 | echo "" |
| 1024 | fi |
Jonathan Nieder | aa0bcf9 | 2011-08-08 03:15:34 +0200 | [diff] [blame] | 1025 | return "$eval_ret" |
Pavel Roskin | 4d9d62f | 2005-08-10 23:56:21 -0400 | [diff] [blame] | 1026 | } |
| 1027 | |
Thomas Rast | ae75342 | 2013-06-18 14:25:59 +0200 | [diff] [blame] | 1028 | test_start_ () { |
Johannes Sixt | 8586f98 | 2009-02-05 21:20:56 +0100 | [diff] [blame] | 1029 | test_count=$(($test_count+1)) |
Thomas Rast | ff09af3 | 2013-06-23 20:12:56 +0200 | [diff] [blame] | 1030 | maybe_setup_verbose |
Thomas Rast | 5dfc368 | 2013-06-23 20:12:57 +0200 | [diff] [blame] | 1031 | maybe_setup_valgrind |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 1032 | if test -n "$write_junit_xml" |
| 1033 | then |
| 1034 | junit_start=$(test-tool date getnanos) |
| 1035 | fi |
Thomas Rast | ae75342 | 2013-06-18 14:25:59 +0200 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | test_finish_ () { |
| 1039 | echo >&3 "" |
Thomas Rast | 5dfc368 | 2013-06-23 20:12:57 +0200 | [diff] [blame] | 1040 | maybe_teardown_valgrind |
Thomas Rast | ff09af3 | 2013-06-23 20:12:56 +0200 | [diff] [blame] | 1041 | maybe_teardown_verbose |
Johannes Schindelin | af9912e | 2019-01-29 06:19:34 -0800 | [diff] [blame] | 1042 | if test -n "$GIT_TEST_TEE_OFFSET" |
| 1043 | then |
| 1044 | GIT_TEST_TEE_OFFSET=$(test-tool path-utils file-size \ |
| 1045 | "$GIT_TEST_TEE_OUTPUT_FILE") |
| 1046 | fi |
Thomas Rast | ae75342 | 2013-06-18 14:25:59 +0200 | [diff] [blame] | 1047 | } |
| 1048 | |
| 1049 | test_skip () { |
Junio C Hamano | 04ece59 | 2006-12-28 17:58:00 -0800 | [diff] [blame] | 1050 | to_skip= |
Ilya Bobyr | ef2ac68 | 2014-04-30 02:50:43 -0700 | [diff] [blame] | 1051 | skipped_reason= |
Jeff King | 560bf51 | 2021-06-16 06:23:07 -0400 | [diff] [blame] | 1052 | if match_pattern_list $this_test.$test_count "$GIT_SKIP_TESTS" |
Thomas Rast | e6a6ddc | 2013-06-18 14:25:58 +0200 | [diff] [blame] | 1053 | then |
| 1054 | to_skip=t |
Ilya Bobyr | ef2ac68 | 2014-04-30 02:50:43 -0700 | [diff] [blame] | 1055 | skipped_reason="GIT_SKIP_TESTS" |
Thomas Rast | e6a6ddc | 2013-06-18 14:25:58 +0200 | [diff] [blame] | 1056 | fi |
SZEDER Gábor | e031669 | 2019-11-12 13:24:38 +0100 | [diff] [blame] | 1057 | if test -z "$to_skip" && test -n "$run_list" && |
Elijah Newren | f21ac36 | 2020-10-18 00:23:45 +0000 | [diff] [blame] | 1058 | ! match_test_selector_list '--run' "$1" $test_count "$run_list" |
SZEDER Gábor | e031669 | 2019-11-12 13:24:38 +0100 | [diff] [blame] | 1059 | then |
| 1060 | to_skip=t |
| 1061 | skipped_reason="--run" |
| 1062 | fi |
Jonathan Nieder | 05236a5 | 2010-10-17 02:36:58 +0800 | [diff] [blame] | 1063 | if test -z "$to_skip" && test -n "$test_prereq" && |
| 1064 | ! test_have_prereq "$test_prereq" |
Johannes Sixt | a7bb394 | 2009-03-01 21:04:46 +0100 | [diff] [blame] | 1065 | then |
| 1066 | to_skip=t |
Ilya Bobyr | ef2ac68 | 2014-04-30 02:50:43 -0700 | [diff] [blame] | 1067 | |
Jonathan Nieder | 07431fc | 2010-08-24 02:34:10 -0500 | [diff] [blame] | 1068 | of_prereq= |
Jonathan Nieder | 05236a5 | 2010-10-17 02:36:58 +0800 | [diff] [blame] | 1069 | if test "$missing_prereq" != "$test_prereq" |
Jonathan Nieder | 07431fc | 2010-08-24 02:34:10 -0500 | [diff] [blame] | 1070 | then |
Jonathan Nieder | 05236a5 | 2010-10-17 02:36:58 +0800 | [diff] [blame] | 1071 | of_prereq=" of $test_prereq" |
Jonathan Nieder | 07431fc | 2010-08-24 02:34:10 -0500 | [diff] [blame] | 1072 | fi |
Ilya Bobyr | ef2ac68 | 2014-04-30 02:50:43 -0700 | [diff] [blame] | 1073 | skipped_reason="missing $missing_prereq${of_prereq}" |
Fabian Stelzer | 49da404 | 2021-11-20 16:03:59 +0100 | [diff] [blame^] | 1074 | |
| 1075 | # Keep a list of all the missing prereq for result aggregation |
| 1076 | if test -z "$missing_prereq" |
| 1077 | then |
| 1078 | test_missing_prereq=$missing_prereq |
| 1079 | else |
| 1080 | test_missing_prereq="$test_missing_prereq,$missing_prereq" |
| 1081 | fi |
Ilya Bobyr | ef2ac68 | 2014-04-30 02:50:43 -0700 | [diff] [blame] | 1082 | fi |
Jonathan Nieder | 07431fc | 2010-08-24 02:34:10 -0500 | [diff] [blame] | 1083 | |
Ilya Bobyr | ef2ac68 | 2014-04-30 02:50:43 -0700 | [diff] [blame] | 1084 | case "$to_skip" in |
| 1085 | t) |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 1086 | if test -n "$write_junit_xml" |
| 1087 | then |
| 1088 | message="$(xml_attr_encode "$skipped_reason")" |
| 1089 | write_junit_xml_testcase "$1" \ |
| 1090 | " <skipped message=\"$message\" />" |
| 1091 | fi |
| 1092 | |
Ilya Bobyr | ef2ac68 | 2014-04-30 02:50:43 -0700 | [diff] [blame] | 1093 | say_color skip "ok $test_count # skip $1 ($skipped_reason)" |
Junio C Hamano | 04ece59 | 2006-12-28 17:58:00 -0800 | [diff] [blame] | 1094 | : true |
| 1095 | ;; |
| 1096 | *) |
| 1097 | false |
| 1098 | ;; |
| 1099 | esac |
| 1100 | } |
| 1101 | |
Thomas Rast | 342e9ef | 2012-02-17 11:25:09 +0100 | [diff] [blame] | 1102 | # stub; perf-lib overrides it |
| 1103 | test_at_end_hook_ () { |
| 1104 | : |
| 1105 | } |
| 1106 | |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 1107 | write_junit_xml () { |
| 1108 | case "$1" in |
| 1109 | --truncate) |
| 1110 | >"$junit_xml_path" |
| 1111 | junit_have_testcase= |
| 1112 | shift |
| 1113 | ;; |
| 1114 | esac |
| 1115 | printf '%s\n' "$@" >>"$junit_xml_path" |
| 1116 | } |
| 1117 | |
| 1118 | xml_attr_encode () { |
| 1119 | printf '%s\n' "$@" | test-tool xml-encode |
| 1120 | } |
| 1121 | |
| 1122 | write_junit_xml_testcase () { |
| 1123 | junit_attrs="name=\"$(xml_attr_encode "$this_test.$test_count $1")\"" |
| 1124 | shift |
| 1125 | junit_attrs="$junit_attrs classname=\"$this_test\"" |
| 1126 | junit_attrs="$junit_attrs time=\"$(test-tool \ |
| 1127 | date getnanos $junit_start)\"" |
| 1128 | write_junit_xml "$(printf '%s\n' \ |
| 1129 | " <testcase $junit_attrs>" "$@" " </testcase>")" |
| 1130 | junit_have_testcase=t |
| 1131 | } |
| 1132 | |
Johannes Schindelin | ab7d854 | 2019-10-04 08:09:34 -0700 | [diff] [blame] | 1133 | finalize_junit_xml () { |
| 1134 | if test -n "$write_junit_xml" && test -n "$junit_xml_path" |
| 1135 | then |
| 1136 | test -n "$junit_have_testcase" || { |
| 1137 | junit_start=$(test-tool date getnanos) |
| 1138 | write_junit_xml_testcase "all tests skipped" |
| 1139 | } |
| 1140 | |
| 1141 | # adjust the overall time |
| 1142 | junit_time=$(test-tool date getnanos $junit_suite_start) |
Johannes Schindelin | 076ee3e | 2020-02-12 11:27:55 +0000 | [diff] [blame] | 1143 | sed -e "s/\(<testsuite.*\) time=\"[^\"]*\"/\1/" \ |
| 1144 | -e "s/<testsuite [^>]*/& time=\"$junit_time\"/" \ |
Johannes Schindelin | d3507cc | 2020-03-23 12:44:35 +0000 | [diff] [blame] | 1145 | -e '/^ *<\/testsuite/d' \ |
Johannes Schindelin | ab7d854 | 2019-10-04 08:09:34 -0700 | [diff] [blame] | 1146 | <"$junit_xml_path" >"$junit_xml_path.new" |
| 1147 | mv "$junit_xml_path.new" "$junit_xml_path" |
| 1148 | |
| 1149 | write_junit_xml " </testsuite>" "</testsuites>" |
| 1150 | write_junit_xml= |
| 1151 | fi |
| 1152 | } |
| 1153 | |
Johannes Schindelin | 900721e | 2019-03-13 13:24:11 +0100 | [diff] [blame] | 1154 | test_atexit_cleanup=: |
| 1155 | test_atexit_handler () { |
| 1156 | # In a succeeding test script 'test_atexit_handler' is invoked |
| 1157 | # twice: first from 'test_done', then from 'die' in the trap on |
| 1158 | # EXIT. |
| 1159 | # This condition and resetting 'test_atexit_cleanup' below makes |
| 1160 | # sure that the registered cleanup commands are run only once. |
| 1161 | test : != "$test_atexit_cleanup" || return 0 |
| 1162 | |
| 1163 | setup_malloc_check |
| 1164 | test_eval_ "$test_atexit_cleanup" |
| 1165 | test_atexit_cleanup=: |
| 1166 | teardown_malloc_check |
| 1167 | } |
| 1168 | |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1169 | test_done () { |
Clemens Buchacher | 6e7b5aa | 2009-06-01 14:14:41 +0200 | [diff] [blame] | 1170 | GIT_EXIT_OK=t |
Sverre Rabbelier | 2d84e9f | 2008-06-08 16:04:33 +0200 | [diff] [blame] | 1171 | |
Johannes Schindelin | 900721e | 2019-03-13 13:24:11 +0100 | [diff] [blame] | 1172 | # Run the atexit commands _before_ the trash directory is |
| 1173 | # removed, so the commands can access pidfiles and socket files. |
| 1174 | test_atexit_handler |
| 1175 | |
Johannes Schindelin | ab7d854 | 2019-10-04 08:09:34 -0700 | [diff] [blame] | 1176 | finalize_junit_xml |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 1177 | |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 1178 | if test -z "$HARNESS_ACTIVE" |
| 1179 | then |
SZEDER Gábor | 62c379b | 2019-01-05 02:08:56 +0100 | [diff] [blame] | 1180 | mkdir -p "$TEST_RESULTS_DIR" |
Ævar Arnfjörð Bjarmason | 8ef1abe | 2010-08-11 19:37:31 +0000 | [diff] [blame] | 1181 | |
SZEDER Gábor | 62c379b | 2019-01-05 02:08:56 +0100 | [diff] [blame] | 1182 | cat >"$TEST_RESULTS_BASE.counts" <<-EOF |
Mathias Lafeldt | c54e6be | 2011-04-29 14:30:30 +0200 | [diff] [blame] | 1183 | total $test_count |
| 1184 | success $test_success |
| 1185 | fixed $test_fixed |
| 1186 | broken $test_broken |
| 1187 | failed $test_failure |
Fabian Stelzer | 49da404 | 2021-11-20 16:03:59 +0100 | [diff] [blame^] | 1188 | missing_prereq $test_missing_prereq |
Mathias Lafeldt | c54e6be | 2011-04-29 14:30:30 +0200 | [diff] [blame] | 1189 | |
| 1190 | EOF |
Ævar Arnfjörð Bjarmason | 8ef1abe | 2010-08-11 19:37:31 +0000 | [diff] [blame] | 1191 | fi |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 1192 | |
| 1193 | if test "$test_fixed" != 0 |
| 1194 | then |
Thomas Rast | 633fe50 | 2013-10-19 23:06:08 +0200 | [diff] [blame] | 1195 | say_color error "# $test_fixed known breakage(s) vanished; please update test(s)" |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 1196 | fi |
| 1197 | if test "$test_broken" != 0 |
| 1198 | then |
Thomas Rast | 633fe50 | 2013-10-19 23:06:08 +0200 | [diff] [blame] | 1199 | say_color warn "# still have $test_broken known breakage(s)" |
Adam Spiers | b73d9a2 | 2012-12-16 18:28:15 +0000 | [diff] [blame] | 1200 | fi |
| 1201 | if test "$test_broken" != 0 || test "$test_fixed" != 0 |
| 1202 | then |
| 1203 | test_remaining=$(( $test_count - $test_broken - $test_fixed )) |
| 1204 | msg="remaining $test_remaining test(s)" |
Junio C Hamano | 11d54b8 | 2008-02-03 00:23:02 -0800 | [diff] [blame] | 1205 | else |
Adam Spiers | b73d9a2 | 2012-12-16 18:28:15 +0000 | [diff] [blame] | 1206 | test_remaining=$test_count |
Junio C Hamano | 11d54b8 | 2008-02-03 00:23:02 -0800 | [diff] [blame] | 1207 | msg="$test_count test(s)" |
Junio C Hamano | 41ac414 | 2008-02-01 01:50:53 -0800 | [diff] [blame] | 1208 | fi |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1209 | case "$test_failure" in |
Junio C Hamano | 10b94e2 | 2005-12-09 17:32:18 -0800 | [diff] [blame] | 1210 | 0) |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 1211 | if test $test_external_has_tap -eq 0 |
| 1212 | then |
Adam Spiers | b73d9a2 | 2012-12-16 18:28:15 +0000 | [diff] [blame] | 1213 | if test $test_remaining -gt 0 |
Ramsay Jones | d87bd7c | 2012-09-01 19:26:21 +0100 | [diff] [blame] | 1214 | then |
Thomas Rast | 633fe50 | 2013-10-19 23:06:08 +0200 | [diff] [blame] | 1215 | say_color pass "# passed all $msg" |
Ramsay Jones | d87bd7c | 2012-09-01 19:26:21 +0100 | [diff] [blame] | 1216 | fi |
Junio C Hamano | c7018be | 2017-05-18 11:52:20 +0900 | [diff] [blame] | 1217 | |
| 1218 | # Maybe print SKIP message |
| 1219 | test -z "$skip_all" || skip_all="# SKIP $skip_all" |
| 1220 | case "$test_count" in |
| 1221 | 0) |
| 1222 | say "1..$test_count${skip_all:+ $skip_all}" |
| 1223 | ;; |
| 1224 | *) |
| 1225 | test -z "$skip_all" || |
| 1226 | say_color warn "$skip_all" |
| 1227 | say "1..$test_count" |
| 1228 | ;; |
| 1229 | esac |
Ævar Arnfjörð Bjarmason | d998bd4 | 2010-06-24 17:44:46 +0000 | [diff] [blame] | 1230 | fi |
Johannes Schindelin | abc5d37 | 2008-08-08 13:08:37 +0200 | [diff] [blame] | 1231 | |
Ævar Arnfjörð Bjarmason | edc2384 | 2021-05-10 16:19:00 +0200 | [diff] [blame] | 1232 | if test -z "$debug" && test -n "$remove_trash" |
Junio C Hamano | 4d0912a | 2017-04-24 23:39:47 -0700 | [diff] [blame] | 1233 | then |
Junio C Hamano | 06478da | 2017-04-23 17:15:09 -0700 | [diff] [blame] | 1234 | test -d "$TRASH_DIRECTORY" || |
Junio C Hamano | 4d0912a | 2017-04-24 23:39:47 -0700 | [diff] [blame] | 1235 | error "Tests passed but trash directory already removed before test cleanup; aborting" |
Johannes Schindelin | abc5d37 | 2008-08-08 13:08:37 +0200 | [diff] [blame] | 1236 | |
Junio C Hamano | 06478da | 2017-04-23 17:15:09 -0700 | [diff] [blame] | 1237 | cd "$TRASH_DIRECTORY/.." && |
Johannes Schindelin | 046e90d | 2019-01-29 06:19:35 -0800 | [diff] [blame] | 1238 | rm -fr "$TRASH_DIRECTORY" || { |
| 1239 | # try again in a bit |
| 1240 | sleep 5; |
| 1241 | rm -fr "$TRASH_DIRECTORY" |
| 1242 | } || |
Junio C Hamano | 4d0912a | 2017-04-24 23:39:47 -0700 | [diff] [blame] | 1243 | error "Tests passed but test cleanup failed; aborting" |
Junio C Hamano | 4d0912a | 2017-04-24 23:39:47 -0700 | [diff] [blame] | 1244 | fi |
Thomas Rast | 342e9ef | 2012-02-17 11:25:09 +0100 | [diff] [blame] | 1245 | test_at_end_hook_ |
| 1246 | |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1247 | exit 0 ;; |
| 1248 | |
| 1249 | *) |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 1250 | if test $test_external_has_tap -eq 0 |
| 1251 | then |
Thomas Rast | 633fe50 | 2013-10-19 23:06:08 +0200 | [diff] [blame] | 1252 | say_color error "# failed $test_failure among $msg" |
| 1253 | say "1..$test_count" |
Ævar Arnfjörð Bjarmason | d998bd4 | 2010-06-24 17:44:46 +0000 | [diff] [blame] | 1254 | fi |
Ævar Arnfjörð Bjarmason | 5099b99 | 2010-06-24 21:52:12 +0000 | [diff] [blame] | 1255 | |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1256 | exit 1 ;; |
| 1257 | |
| 1258 | esac |
| 1259 | } |
| 1260 | |
Matthew Ogilvie | e4597aa | 2009-12-02 22:14:06 -0700 | [diff] [blame] | 1261 | if test -n "$valgrind" |
Johannes Schindelin | 4e1be63 | 2009-02-04 00:25:59 +0100 | [diff] [blame] | 1262 | then |
Johannes Schindelin | 4e1be63 | 2009-02-04 00:25:59 +0100 | [diff] [blame] | 1263 | make_symlink () { |
| 1264 | test -h "$2" && |
| 1265 | test "$1" = "$(readlink "$2")" || { |
| 1266 | # be super paranoid |
| 1267 | if mkdir "$2".lock |
| 1268 | then |
| 1269 | rm -f "$2" && |
| 1270 | ln -s "$1" "$2" && |
| 1271 | rm -r "$2".lock |
| 1272 | else |
| 1273 | while test -d "$2".lock |
| 1274 | do |
| 1275 | say "Waiting for lock on $2." |
| 1276 | sleep 1 |
| 1277 | done |
| 1278 | fi |
| 1279 | } |
| 1280 | } |
| 1281 | |
| 1282 | make_valgrind_symlink () { |
Jeff King | 36bfb0e | 2011-06-17 16:36:32 -0400 | [diff] [blame] | 1283 | # handle only executables, unless they are shell libraries that |
Jonathan Nieder | 11d6214 | 2013-11-25 13:03:52 -0800 | [diff] [blame] | 1284 | # need to be in the exec-path. |
Jeff King | 36bfb0e | 2011-06-17 16:36:32 -0400 | [diff] [blame] | 1285 | test -x "$1" || |
Ævar Arnfjörð Bjarmason | 2a59a6e | 2018-08-24 15:20:11 +0000 | [diff] [blame] | 1286 | test "# " = "$(test_copy_bytes 2 <"$1")" || |
Jeff King | 36bfb0e | 2011-06-17 16:36:32 -0400 | [diff] [blame] | 1287 | return; |
Johannes Schindelin | 4e1be63 | 2009-02-04 00:25:59 +0100 | [diff] [blame] | 1288 | |
| 1289 | base=$(basename "$1") |
René Scharfe | 28fab7b | 2016-10-28 00:14:00 +0200 | [diff] [blame] | 1290 | case "$base" in |
| 1291 | test-*) |
| 1292 | symlink_target="$GIT_BUILD_DIR/t/helper/$base" |
| 1293 | ;; |
| 1294 | *) |
| 1295 | symlink_target="$GIT_BUILD_DIR/$base" |
| 1296 | ;; |
| 1297 | esac |
Johannes Schindelin | 4e1be63 | 2009-02-04 00:25:59 +0100 | [diff] [blame] | 1298 | # do not override scripts |
| 1299 | if test -x "$symlink_target" && |
| 1300 | test ! -d "$symlink_target" && |
Ævar Arnfjörð Bjarmason | 2a59a6e | 2018-08-24 15:20:11 +0000 | [diff] [blame] | 1301 | test "#!" != "$(test_copy_bytes 2 <"$symlink_target")" |
Johannes Schindelin | 4e1be63 | 2009-02-04 00:25:59 +0100 | [diff] [blame] | 1302 | then |
| 1303 | symlink_target=../valgrind.sh |
| 1304 | fi |
Johannes Schindelin | efd92ff | 2009-02-04 00:26:08 +0100 | [diff] [blame] | 1305 | case "$base" in |
| 1306 | *.sh|*.perl) |
| 1307 | symlink_target=../unprocessed-script |
| 1308 | esac |
Johannes Schindelin | 4e1be63 | 2009-02-04 00:25:59 +0100 | [diff] [blame] | 1309 | # create the link, or replace it if it is out of date |
| 1310 | make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit |
| 1311 | } |
| 1312 | |
Thomas Rast | 26a0730 | 2013-10-19 23:06:07 +0200 | [diff] [blame] | 1313 | # override all git executables in TEST_DIRECTORY/.. |
| 1314 | GIT_VALGRIND=$TEST_DIRECTORY/valgrind |
| 1315 | mkdir -p "$GIT_VALGRIND"/bin |
Johannes Schindelin | 503e224 | 2016-07-11 13:45:08 +0200 | [diff] [blame] | 1316 | for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/t/helper/test-* |
Thomas Rast | 26a0730 | 2013-10-19 23:06:07 +0200 | [diff] [blame] | 1317 | do |
| 1318 | make_valgrind_symlink $file |
| 1319 | done |
| 1320 | # special-case the mergetools loadables |
| 1321 | make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools" |
| 1322 | OLDIFS=$IFS |
| 1323 | IFS=: |
| 1324 | for path in $PATH |
| 1325 | do |
| 1326 | ls "$path"/git-* 2> /dev/null | |
| 1327 | while read file |
Johannes Schindelin | efd92ff | 2009-02-04 00:26:08 +0100 | [diff] [blame] | 1328 | do |
Thomas Rast | 26a0730 | 2013-10-19 23:06:07 +0200 | [diff] [blame] | 1329 | make_valgrind_symlink "$file" |
Johannes Schindelin | efd92ff | 2009-02-04 00:26:08 +0100 | [diff] [blame] | 1330 | done |
Thomas Rast | 26a0730 | 2013-10-19 23:06:07 +0200 | [diff] [blame] | 1331 | done |
| 1332 | IFS=$OLDIFS |
Johannes Schindelin | 4e1be63 | 2009-02-04 00:25:59 +0100 | [diff] [blame] | 1333 | PATH=$GIT_VALGRIND/bin:$PATH |
| 1334 | GIT_EXEC_PATH=$GIT_VALGRIND/bin |
| 1335 | export GIT_VALGRIND |
Thomas Rast | 952af35 | 2013-03-31 10:00:16 +0200 | [diff] [blame] | 1336 | GIT_VALGRIND_MODE="$valgrind" |
| 1337 | export GIT_VALGRIND_MODE |
Thomas Rast | 5dfc368 | 2013-06-23 20:12:57 +0200 | [diff] [blame] | 1338 | GIT_VALGRIND_ENABLED=t |
Thomas Rast | 26a0730 | 2013-10-19 23:06:07 +0200 | [diff] [blame] | 1339 | test -n "$valgrind_only" && GIT_VALGRIND_ENABLED= |
Thomas Rast | 5dfc368 | 2013-06-23 20:12:57 +0200 | [diff] [blame] | 1340 | export GIT_VALGRIND_ENABLED |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 1341 | elif test -n "$GIT_TEST_INSTALLED" |
| 1342 | then |
Matthew Ogilvie | e4597aa | 2009-12-02 22:14:06 -0700 | [diff] [blame] | 1343 | GIT_EXEC_PATH=$($GIT_TEST_INSTALLED/git --exec-path) || |
| 1344 | error "Cannot run git from $GIT_TEST_INSTALLED." |
Johannes Schindelin | 16df35c | 2018-11-12 05:48:33 -0800 | [diff] [blame] | 1345 | PATH=$GIT_TEST_INSTALLED:$GIT_BUILD_DIR/t/helper:$PATH |
Matthew Ogilvie | e4597aa | 2009-12-02 22:14:06 -0700 | [diff] [blame] | 1346 | GIT_EXEC_PATH=${GIT_TEST_EXEC_PATH:-$GIT_EXEC_PATH} |
| 1347 | else # normal case, use ../bin-wrappers only unless $with_dashes: |
Johannes Schindelin | dd167a3 | 2019-01-29 06:19:37 -0800 | [diff] [blame] | 1348 | if test -n "$no_bin_wrappers" |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 1349 | then |
Matthew Ogilvie | e4597aa | 2009-12-02 22:14:06 -0700 | [diff] [blame] | 1350 | with_dashes=t |
Johannes Schindelin | dd167a3 | 2019-01-29 06:19:37 -0800 | [diff] [blame] | 1351 | else |
| 1352 | git_bin_dir="$GIT_BUILD_DIR/bin-wrappers" |
| 1353 | if ! test -x "$git_bin_dir/git" |
| 1354 | then |
| 1355 | if test -z "$with_dashes" |
| 1356 | then |
| 1357 | say "$git_bin_dir/git is not executable; using GIT_EXEC_PATH" |
| 1358 | fi |
| 1359 | with_dashes=t |
| 1360 | fi |
| 1361 | PATH="$git_bin_dir:$PATH" |
Matthew Ogilvie | e4597aa | 2009-12-02 22:14:06 -0700 | [diff] [blame] | 1362 | fi |
Ævar Arnfjörð Bjarmason | 6cec5c6 | 2010-08-19 16:08:10 +0000 | [diff] [blame] | 1363 | GIT_EXEC_PATH=$GIT_BUILD_DIR |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 1364 | if test -n "$with_dashes" |
| 1365 | then |
Johannes Schindelin | ca7312d | 2019-01-29 06:19:35 -0800 | [diff] [blame] | 1366 | PATH="$GIT_BUILD_DIR:$GIT_BUILD_DIR/t/helper:$PATH" |
Matthew Ogilvie | e4597aa | 2009-12-02 22:14:06 -0700 | [diff] [blame] | 1367 | fi |
Johannes Schindelin | 4e1be63 | 2009-02-04 00:25:59 +0100 | [diff] [blame] | 1368 | fi |
Ævar Arnfjörð Bjarmason | 6cec5c6 | 2010-08-19 16:08:10 +0000 | [diff] [blame] | 1369 | GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt |
Jeff King | 8bfa6bd | 2008-02-06 05:11:53 -0500 | [diff] [blame] | 1370 | GIT_CONFIG_NOSYSTEM=1 |
Jonathan Nieder | 3c995be | 2011-03-15 04:05:10 -0500 | [diff] [blame] | 1371 | GIT_ATTR_NOSYSTEM=1 |
SZEDER Gábor | 614c3d8 | 2021-08-29 11:25:36 +0200 | [diff] [blame] | 1372 | GIT_CEILING_DIRECTORIES="$TRASH_DIRECTORY/.." |
| 1373 | export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM GIT_CEILING_DIRECTORIES |
Junio C Hamano | 49ccb08 | 2005-12-07 21:52:28 -0800 | [diff] [blame] | 1374 | |
Junio C Hamano | 5e87eae | 2010-06-11 09:40:25 -0700 | [diff] [blame] | 1375 | if test -z "$GIT_TEST_CMP" |
| 1376 | then |
| 1377 | if test -n "$GIT_TEST_CMP_USE_COPIED_CONTEXT" |
| 1378 | then |
| 1379 | GIT_TEST_CMP="$DIFF -c" |
| 1380 | else |
| 1381 | GIT_TEST_CMP="$DIFF -u" |
| 1382 | fi |
| 1383 | fi |
| 1384 | |
Ævar Arnfjörð Bjarmason | 20d2a30 | 2017-12-10 21:13:33 +0000 | [diff] [blame] | 1385 | GITPERLLIB="$GIT_BUILD_DIR"/perl/build/lib |
Petr Baudis | 6fcca93 | 2006-07-03 23:16:32 +0200 | [diff] [blame] | 1386 | export GITPERLLIB |
Ævar Arnfjörð Bjarmason | 6cec5c6 | 2010-08-19 16:08:10 +0000 | [diff] [blame] | 1387 | test -d "$GIT_BUILD_DIR"/templates/blt || { |
Junio C Hamano | eea4206 | 2005-12-10 20:55:32 -0800 | [diff] [blame] | 1388 | error "You haven't built things yet, have you?" |
| 1389 | } |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1390 | |
Johannes Schindelin | d609615 | 2019-01-21 07:12:19 -0800 | [diff] [blame] | 1391 | if ! test -x "$GIT_BUILD_DIR"/t/helper/test-tool$X |
Ramsay Jones | 1c0cc75 | 2012-09-01 19:11:49 +0100 | [diff] [blame] | 1392 | then |
Nguyễn Thái Ngọc Duy | 0e49649 | 2018-03-24 08:44:31 +0100 | [diff] [blame] | 1393 | echo >&2 'You need to build test-tool:' |
| 1394 | echo >&2 'Run "make t/helper/test-tool" in the source (toplevel) directory' |
Eric Wong | 56cf980 | 2007-02-24 16:59:52 -0800 | [diff] [blame] | 1395 | exit 1 |
| 1396 | fi |
| 1397 | |
Ævar Arnfjörð Bjarmason | edc2384 | 2021-05-10 16:19:00 +0200 | [diff] [blame] | 1398 | # Are we running this test at all? |
| 1399 | remove_trash= |
Johannes Sixt | d5d9de1 | 2009-02-05 20:59:27 +0100 | [diff] [blame] | 1400 | this_test=${0##*/} |
| 1401 | this_test=${this_test%%-*} |
Jeff King | 560bf51 | 2021-06-16 06:23:07 -0400 | [diff] [blame] | 1402 | if match_pattern_list "$this_test" "$GIT_SKIP_TESTS" |
Thomas Rast | e6a6ddc | 2013-06-18 14:25:58 +0200 | [diff] [blame] | 1403 | then |
| 1404 | say_color info >&3 "skipping test $this_test altogether" |
| 1405 | skip_all="skip all tests in $this_test" |
| 1406 | test_done |
| 1407 | fi |
Johannes Sixt | f17e9fb | 2009-03-11 21:17:26 +0100 | [diff] [blame] | 1408 | |
Ævar Arnfjörð Bjarmason | 956d2e4 | 2021-09-23 11:20:46 +0200 | [diff] [blame] | 1409 | # skip non-whitelisted tests when compiled with SANITIZE=leak |
| 1410 | if test -n "$SANITIZE_LEAK" |
| 1411 | then |
| 1412 | if test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false |
| 1413 | then |
| 1414 | # We need to see it in "git env--helper" (via |
| 1415 | # test_bool_env) |
| 1416 | export TEST_PASSES_SANITIZE_LEAK |
| 1417 | |
| 1418 | if ! test_bool_env TEST_PASSES_SANITIZE_LEAK false |
| 1419 | then |
| 1420 | skip_all="skipping $this_test under GIT_TEST_PASSING_SANITIZE_LEAK=true" |
| 1421 | test_done |
| 1422 | fi |
| 1423 | fi |
| 1424 | elif test_bool_env GIT_TEST_PASSING_SANITIZE_LEAK false |
| 1425 | then |
Ævar Arnfjörð Bjarmason | 234383c | 2021-10-14 02:47:29 +0200 | [diff] [blame] | 1426 | BAIL_OUT "GIT_TEST_PASSING_SANITIZE_LEAK=true has no effect except when compiled with SANITIZE=leak" |
Ævar Arnfjörð Bjarmason | 956d2e4 | 2021-09-23 11:20:46 +0200 | [diff] [blame] | 1427 | fi |
| 1428 | |
Ævar Arnfjörð Bjarmason | edc2384 | 2021-05-10 16:19:00 +0200 | [diff] [blame] | 1429 | # Last-minute variable setup |
Philippe Blain | add5240 | 2021-09-06 04:38:59 +0000 | [diff] [blame] | 1430 | USER_HOME="$HOME" |
Ævar Arnfjörð Bjarmason | edc2384 | 2021-05-10 16:19:00 +0200 | [diff] [blame] | 1431 | HOME="$TRASH_DIRECTORY" |
| 1432 | GNUPGHOME="$HOME/gnupg-home-not-used" |
Philippe Blain | add5240 | 2021-09-06 04:38:59 +0000 | [diff] [blame] | 1433 | export HOME GNUPGHOME USER_HOME |
Ævar Arnfjörð Bjarmason | edc2384 | 2021-05-10 16:19:00 +0200 | [diff] [blame] | 1434 | |
Ævar Arnfjörð Bjarmason | 5d22e18 | 2021-10-11 03:41:59 +0200 | [diff] [blame] | 1435 | # "rm -rf" existing trash directory, even if a previous run left it |
| 1436 | # with bad permissions. |
| 1437 | remove_trash_directory () { |
| 1438 | dir="$1" |
| 1439 | if ! rm -rf "$dir" 2>/dev/null |
| 1440 | then |
| 1441 | chmod -R u+rwx "$dir" |
| 1442 | rm -rf "$dir" |
| 1443 | fi |
| 1444 | ! test -d "$dir" |
| 1445 | } |
| 1446 | |
Johannes Sixt | ee9fb68 | 2009-03-13 22:55:27 +0100 | [diff] [blame] | 1447 | # Test repository |
Ævar Arnfjörð Bjarmason | 5d22e18 | 2021-10-11 03:41:59 +0200 | [diff] [blame] | 1448 | remove_trash_directory "$TRASH_DIRECTORY" || { |
Johannes Sixt | f17e9fb | 2009-03-11 21:17:26 +0100 | [diff] [blame] | 1449 | GIT_EXIT_OK=t |
Johannes Sixt | 704a314 | 2009-03-04 22:38:24 +0100 | [diff] [blame] | 1450 | echo >&5 "FATAL: Cannot prepare test area" |
| 1451 | exit 1 |
Johannes Sixt | 6fd1106 | 2009-03-13 23:00:15 +0100 | [diff] [blame] | 1452 | } |
Johannes Sixt | fb9a2be | 2009-03-25 13:21:15 +0100 | [diff] [blame] | 1453 | |
Ævar Arnfjörð Bjarmason | edc2384 | 2021-05-10 16:19:00 +0200 | [diff] [blame] | 1454 | remove_trash=t |
Johannes Sixt | 704a314 | 2009-03-04 22:38:24 +0100 | [diff] [blame] | 1455 | if test -z "$TEST_NO_CREATE_REPO" |
Zbigniew Jędrzejewski-Szmek | b082687 | 2012-04-27 11:25:25 +0200 | [diff] [blame] | 1456 | then |
Ævar Arnfjörð Bjarmason | f0d4d39 | 2021-05-10 16:19:10 +0200 | [diff] [blame] | 1457 | git init "$TRASH_DIRECTORY" >&3 2>&4 || |
| 1458 | error "cannot run git init" |
Johan Herland | d4e1b47 | 2009-11-18 02:42:31 +0100 | [diff] [blame] | 1459 | else |
Michał Kiedrowicz | 8f852ce | 2011-05-09 23:52:07 +0200 | [diff] [blame] | 1460 | mkdir -p "$TRASH_DIRECTORY" |
Ævar Arnfjörð Bjarmason | 5e9637c | 2011-11-18 00:14:42 +0100 | [diff] [blame] | 1461 | fi |
Jeff King | 1b19ccd | 2009-04-03 15:33:59 -0400 | [diff] [blame] | 1462 | |
Ævar Arnfjörð Bjarmason | bb946bb | 2011-02-22 23:41:21 +0000 | [diff] [blame] | 1463 | # Use -P to resolve symlinks in our working directory so that the cwd |
Jonathan Nieder | 3095522 | 2011-02-22 23:41:22 +0000 | [diff] [blame] | 1464 | # in subprocesses like git equals our $PWD (for pathname comparisons). |
| 1465 | cd -P "$TRASH_DIRECTORY" || exit 1 |
| 1466 | |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 1467 | if test -n "$write_junit_xml" |
| 1468 | then |
| 1469 | junit_xml_dir="$TEST_OUTPUT_DIRECTORY/out" |
| 1470 | mkdir -p "$junit_xml_dir" |
| 1471 | junit_xml_base=${0##*/} |
| 1472 | junit_xml_path="$junit_xml_dir/TEST-${junit_xml_base%.sh}.xml" |
| 1473 | junit_attrs="name=\"${junit_xml_base%.sh}\"" |
| 1474 | junit_attrs="$junit_attrs timestamp=\"$(TZ=UTC \ |
| 1475 | date +%Y-%m-%dT%H:%M:%S)\"" |
| 1476 | write_junit_xml --truncate "<testsuites>" " <testsuite $junit_attrs>" |
| 1477 | junit_suite_start=$(test-tool date getnanos) |
Johannes Schindelin | af9912e | 2019-01-29 06:19:34 -0800 | [diff] [blame] | 1478 | if test -n "$GIT_TEST_TEE_OUTPUT_FILE" |
| 1479 | then |
| 1480 | GIT_TEST_TEE_OFFSET=0 |
| 1481 | fi |
Johannes Schindelin | 2223190 | 2019-01-29 06:19:27 -0800 | [diff] [blame] | 1482 | fi |
| 1483 | |
brian m. carlson | 192b517 | 2020-02-22 20:17:31 +0000 | [diff] [blame] | 1484 | # Convenience |
Ævar Arnfjörð Bjarmason | 7050791 | 2021-09-11 13:17:51 +0200 | [diff] [blame] | 1485 | # A regexp to match 5 and 35 hexdigits |
brian m. carlson | 192b517 | 2020-02-22 20:17:31 +0000 | [diff] [blame] | 1486 | _x05='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]' |
| 1487 | _x35="$_x05$_x05$_x05$_x05$_x05$_x05$_x05" |
brian m. carlson | 192b517 | 2020-02-22 20:17:31 +0000 | [diff] [blame] | 1488 | |
| 1489 | test_oid_init |
| 1490 | |
| 1491 | ZERO_OID=$(test_oid zero) |
| 1492 | OID_REGEX=$(echo $ZERO_OID | sed -e 's/0/[0-9a-f]/g') |
brian m. carlson | a114296 | 2020-05-13 00:53:41 +0000 | [diff] [blame] | 1493 | OIDPATH_REGEX=$(test_oid_to_path $ZERO_OID | sed -e 's/0/[0-9a-f]/g') |
brian m. carlson | 192b517 | 2020-02-22 20:17:31 +0000 | [diff] [blame] | 1494 | EMPTY_TREE=$(test_oid empty_tree) |
| 1495 | EMPTY_BLOB=$(test_oid empty_blob) |
brian m. carlson | 192b517 | 2020-02-22 20:17:31 +0000 | [diff] [blame] | 1496 | |
Junio C Hamano | 11f470a | 2019-02-09 10:25:26 -0800 | [diff] [blame] | 1497 | # Provide an implementation of the 'yes' utility; the upper bound |
| 1498 | # limit is there to help Windows that cannot stop this loop from |
| 1499 | # wasting cycles when the downstream stops reading, so do not be |
| 1500 | # tempted to turn it into an infinite loop. cf. 6129c930 ("test-lib: |
| 1501 | # limit the output of the yes utility", 2016-02-02) |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1502 | yes () { |
| 1503 | if test $# = 0 |
| 1504 | then |
| 1505 | y=y |
| 1506 | else |
| 1507 | y="$*" |
| 1508 | fi |
| 1509 | |
Johannes Schindelin | 6129c93 | 2016-02-02 19:15:53 +0100 | [diff] [blame] | 1510 | i=0 |
| 1511 | while test $i -lt 99 |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1512 | do |
Johannes Schindelin | 6129c93 | 2016-02-02 19:15:53 +0100 | [diff] [blame] | 1513 | echo "$y" |
| 1514 | i=$(($i+1)) |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1515 | done |
| 1516 | } |
| 1517 | |
Ævar Arnfjörð Bjarmason | c740039 | 2019-06-21 12:18:12 +0200 | [diff] [blame] | 1518 | # The GIT_TEST_FAIL_PREREQS code hooks into test_set_prereq(), and |
| 1519 | # thus needs to be set up really early, and set an internal variable |
| 1520 | # for convenience so the hot test_set_prereq() codepath doesn't need |
SZEDER Gábor | 43a2afe | 2019-11-22 14:14:36 +0100 | [diff] [blame] | 1521 | # to call "git env--helper" (via test_bool_env). Only do that work |
| 1522 | # if needed by seeing if GIT_TEST_FAIL_PREREQS is set at all. |
Ævar Arnfjörð Bjarmason | c740039 | 2019-06-21 12:18:12 +0200 | [diff] [blame] | 1523 | GIT_TEST_FAIL_PREREQS_INTERNAL= |
| 1524 | if test -n "$GIT_TEST_FAIL_PREREQS" |
| 1525 | then |
SZEDER Gábor | 43a2afe | 2019-11-22 14:14:36 +0100 | [diff] [blame] | 1526 | if test_bool_env GIT_TEST_FAIL_PREREQS false |
Ævar Arnfjörð Bjarmason | c740039 | 2019-06-21 12:18:12 +0200 | [diff] [blame] | 1527 | then |
| 1528 | GIT_TEST_FAIL_PREREQS_INTERNAL=true |
| 1529 | test_set_prereq FAIL_PREREQS |
| 1530 | fi |
| 1531 | else |
| 1532 | test_lazy_prereq FAIL_PREREQS ' |
SZEDER Gábor | 43a2afe | 2019-11-22 14:14:36 +0100 | [diff] [blame] | 1533 | test_bool_env GIT_TEST_FAIL_PREREQS false |
Ævar Arnfjörð Bjarmason | c740039 | 2019-06-21 12:18:12 +0200 | [diff] [blame] | 1534 | ' |
| 1535 | fi |
| 1536 | |
Ed Maste | 7187c7b | 2019-11-27 17:15:07 +0000 | [diff] [blame] | 1537 | # Fix some commands on Windows, and other OS-specific things |
Johannes Schindelin | d98b2c5 | 2016-07-21 18:02:54 +0200 | [diff] [blame] | 1538 | uname_s=$(uname -s) |
| 1539 | case $uname_s in |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1540 | *MINGW*) |
| 1541 | # Windows has its own (incompatible) sort and find |
| 1542 | sort () { |
| 1543 | /usr/bin/sort "$@" |
| 1544 | } |
| 1545 | find () { |
| 1546 | /usr/bin/find "$@" |
| 1547 | } |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1548 | # git sees Windows-style pwd |
| 1549 | pwd () { |
Johannes Sixt | 704a314 | 2009-03-04 22:38:24 +0100 | [diff] [blame] | 1550 | builtin pwd -W |
| 1551 | } |
| 1552 | # no POSIX permissions |
| 1553 | # backslashes in pathspec are converted to '/' |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1554 | # exec does not inherit the PID |
| 1555 | test_set_prereq MINGW |
Brice Lambson | 5f4e02e | 2014-08-30 23:39:07 +0200 | [diff] [blame] | 1556 | test_set_prereq NATIVE_CRLF |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1557 | test_set_prereq SED_STRIPS_CR |
Mark Levedahl | 97669ee | 2013-07-18 17:44:57 -0400 | [diff] [blame] | 1558 | test_set_prereq GREP_STRIPS_CR |
Adam Dinwoodie | bccc37f | 2021-04-29 21:11:44 +0100 | [diff] [blame] | 1559 | test_set_prereq WINDOWS |
Johannes Sixt | 4d715ac | 2013-10-26 21:17:15 +0200 | [diff] [blame] | 1560 | GIT_TEST_CMP=mingw_test_cmp |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1561 | ;; |
| 1562 | *CYGWIN*) |
| 1563 | test_set_prereq POSIXPERM |
| 1564 | test_set_prereq EXECKEEPSPID |
| 1565 | test_set_prereq CYGWIN |
| 1566 | test_set_prereq SED_STRIPS_CR |
Mark Levedahl | 97669ee | 2013-07-18 17:44:57 -0400 | [diff] [blame] | 1567 | test_set_prereq GREP_STRIPS_CR |
Adam Dinwoodie | bccc37f | 2021-04-29 21:11:44 +0100 | [diff] [blame] | 1568 | test_set_prereq WINDOWS |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1569 | ;; |
| 1570 | *) |
| 1571 | test_set_prereq POSIXPERM |
| 1572 | test_set_prereq BSLASHPSPEC |
| 1573 | test_set_prereq EXECKEEPSPID |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1574 | ;; |
| 1575 | esac |
| 1576 | |
Greg Price | ddcfc7c | 2020-05-15 22:33:38 -0700 | [diff] [blame] | 1577 | # Detect arches where a few things don't work |
| 1578 | uname_m=$(uname -m) |
| 1579 | case $uname_m in |
| 1580 | parisc* | hppa*) |
| 1581 | test_set_prereq HPPA |
| 1582 | ;; |
| 1583 | esac |
| 1584 | |
Han-Wen Nienhuys | c305e66 | 2021-05-31 16:56:29 +0000 | [diff] [blame] | 1585 | test_set_prereq REFFILES |
| 1586 | |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1587 | ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1 |
| 1588 | test -z "$NO_PERL" && test_set_prereq PERL |
Ævar Arnfjörð Bjarmason | 68c7d27 | 2017-05-25 19:45:31 +0000 | [diff] [blame] | 1589 | test -z "$NO_PTHREADS" && test_set_prereq PTHREADS |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1590 | test -z "$NO_PYTHON" && test_set_prereq PYTHON |
Ævar Arnfjörð Bjarmason | 7599730 | 2021-01-24 02:58:33 +0100 | [diff] [blame] | 1591 | test -n "$USE_LIBPCRE2" && test_set_prereq PCRE |
Ævar Arnfjörð Bjarmason | ce9a257 | 2017-11-23 14:16:57 +0000 | [diff] [blame] | 1592 | test -n "$USE_LIBPCRE2" && test_set_prereq LIBPCRE2 |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1593 | test -z "$NO_GETTEXT" && test_set_prereq GETTEXT |
Ævar Arnfjörð Bjarmason | 2cdc292 | 2021-09-23 11:20:45 +0200 | [diff] [blame] | 1594 | test -n "$SANITIZE_LEAK" && test_set_prereq SANITIZE_LEAK |
Junio C Hamano | e1970ce | 2005-05-13 22:50:32 -0700 | [diff] [blame] | 1595 | |
Nguyễn Thái Ngọc Duy | 4592e60 | 2018-08-18 16:41:28 +0200 | [diff] [blame] | 1596 | if test -z "$GIT_TEST_CHECK_CACHE_TREE" |
| 1597 | then |
| 1598 | GIT_TEST_CHECK_CACHE_TREE=true |
| 1599 | export GIT_TEST_CHECK_CACHE_TREE |
| 1600 | fi |
| 1601 | |
Adam Spiers | 2007327 | 2013-04-11 03:07:04 +0100 | [diff] [blame] | 1602 | test_lazy_prereq PIPE ' |
| 1603 | # test whether the filesystem supports FIFOs |
Ramsay Jones | 7b7bea2 | 2017-09-17 23:56:00 +0100 | [diff] [blame] | 1604 | test_have_prereq !MINGW,!CYGWIN && |
| 1605 | rm -f testfifo && mkfifo testfifo |
Adam Spiers | 2007327 | 2013-04-11 03:07:04 +0100 | [diff] [blame] | 1606 | ' |
| 1607 | |
Junio C Hamano | 04083f2 | 2012-07-26 15:50:45 -0700 | [diff] [blame] | 1608 | test_lazy_prereq SYMLINKS ' |
| 1609 | # test whether the filesystem supports symbolic links |
| 1610 | ln -s x y && test -h y |
| 1611 | ' |
Ævar Arnfjörð Bjarmason | c91cfd1 | 2010-08-06 22:09:09 +0000 | [diff] [blame] | 1612 | |
Thomas Bétous | 3e7d488 | 2021-08-02 21:07:30 +0000 | [diff] [blame] | 1613 | test_lazy_prereq SYMLINKS_WINDOWS ' |
| 1614 | # test whether symbolic links are enabled on Windows |
| 1615 | test_have_prereq MINGW && |
| 1616 | cmd //c "mklink y x" &> /dev/null && test -h y |
| 1617 | ' |
| 1618 | |
Jonathan Nieder | b018c73 | 2013-11-25 13:02:16 -0800 | [diff] [blame] | 1619 | test_lazy_prereq FILEMODE ' |
| 1620 | test "$(git config --bool core.filemode)" = true |
| 1621 | ' |
| 1622 | |
Michael J Gruber | ac39aa6 | 2012-07-26 15:39:53 +0200 | [diff] [blame] | 1623 | test_lazy_prereq CASE_INSENSITIVE_FS ' |
| 1624 | echo good >CamelCase && |
| 1625 | echo bad >camelcase && |
| 1626 | test "$(cat CamelCase)" != good |
| 1627 | ' |
| 1628 | |
William Chargin | 6ec6330 | 2018-08-06 11:35:08 -0700 | [diff] [blame] | 1629 | test_lazy_prereq FUNNYNAMES ' |
| 1630 | test_have_prereq !MINGW && |
| 1631 | touch -- \ |
| 1632 | "FUNNYNAMES tab embedded" \ |
| 1633 | "FUNNYNAMES \"quote embedded\"" \ |
| 1634 | "FUNNYNAMES newline |
| 1635 | embedded" 2>/dev/null && |
| 1636 | rm -- \ |
| 1637 | "FUNNYNAMES tab embedded" \ |
| 1638 | "FUNNYNAMES \"quote embedded\"" \ |
| 1639 | "FUNNYNAMES newline |
| 1640 | embedded" 2>/dev/null |
| 1641 | ' |
| 1642 | |
Michael J Gruber | 5b0b5dd | 2012-07-26 15:39:56 +0200 | [diff] [blame] | 1643 | test_lazy_prereq UTF8_NFD_TO_NFC ' |
| 1644 | # check whether FS converts nfd unicode to nfc |
| 1645 | auml=$(printf "\303\244") |
| 1646 | aumlcdiar=$(printf "\141\314\210") |
| 1647 | >"$auml" && |
Torsten Bögershausen | 742ae10 | 2018-04-30 08:35:19 +0200 | [diff] [blame] | 1648 | test -f "$aumlcdiar" |
Michael J Gruber | 5b0b5dd | 2012-07-26 15:39:56 +0200 | [diff] [blame] | 1649 | ' |
| 1650 | |
Jeff King | 09feffb | 2012-11-14 16:33:40 -0800 | [diff] [blame] | 1651 | test_lazy_prereq AUTOIDENT ' |
| 1652 | sane_unset GIT_AUTHOR_NAME && |
| 1653 | sane_unset GIT_AUTHOR_EMAIL && |
| 1654 | git var GIT_AUTHOR_IDENT |
| 1655 | ' |
| 1656 | |
Junio C Hamano | 6219bb2 | 2014-06-09 12:23:30 -0700 | [diff] [blame] | 1657 | test_lazy_prereq EXPENSIVE ' |
| 1658 | test -n "$GIT_TEST_LONG" |
| 1659 | ' |
| 1660 | |
Ævar Arnfjörð Bjarmason | 5b1fe6e | 2018-01-30 21:21:23 +0000 | [diff] [blame] | 1661 | test_lazy_prereq EXPENSIVE_ON_WINDOWS ' |
| 1662 | test_have_prereq EXPENSIVE || test_have_prereq !MINGW,!CYGWIN |
| 1663 | ' |
| 1664 | |
Junio C Hamano | e1ecd9e | 2014-06-09 13:54:25 -0700 | [diff] [blame] | 1665 | test_lazy_prereq USR_BIN_TIME ' |
| 1666 | test -x /usr/bin/time |
| 1667 | ' |
| 1668 | |
Jeff King | 1767c51 | 2015-01-16 04:16:49 -0500 | [diff] [blame] | 1669 | test_lazy_prereq NOT_ROOT ' |
| 1670 | uid=$(id -u) && |
| 1671 | test "$uid" != 0 |
| 1672 | ' |
| 1673 | |
Jonathan Tan | 63b747c | 2016-09-09 10:36:28 -0700 | [diff] [blame] | 1674 | test_lazy_prereq JGIT ' |
Todd Zullinger | abd0f28 | 2019-05-14 21:36:33 -0400 | [diff] [blame] | 1675 | jgit --version |
Jonathan Tan | 63b747c | 2016-09-09 10:36:28 -0700 | [diff] [blame] | 1676 | ' |
| 1677 | |
Junio C Hamano | 719c3da | 2016-01-19 14:09:37 -0800 | [diff] [blame] | 1678 | # SANITY is about "can you correctly predict what the filesystem would |
| 1679 | # do by only looking at the permission bits of the files and |
| 1680 | # directories?" A typical example of !SANITY is running the test |
| 1681 | # suite as root, where a test may expect "chmod -r file && cat file" |
| 1682 | # to fail because file is supposed to be unreadable after a successful |
| 1683 | # chmod. In an environment (i.e. combination of what filesystem is |
| 1684 | # being used and who is running the tests) that lacks SANITY, you may |
| 1685 | # be able to delete or create a file when the containing directory |
| 1686 | # doesn't have write permissions, or access a file even if the |
| 1687 | # containing directory doesn't have read or execute permissions. |
| 1688 | |
Torsten Bögershausen | f400e51 | 2015-01-27 16:39:01 +0100 | [diff] [blame] | 1689 | test_lazy_prereq SANITY ' |
| 1690 | mkdir SANETESTD.1 SANETESTD.2 && |
| 1691 | |
| 1692 | chmod +w SANETESTD.1 SANETESTD.2 && |
| 1693 | >SANETESTD.1/x 2>SANETESTD.2/x && |
| 1694 | chmod -w SANETESTD.1 && |
Junio C Hamano | 719c3da | 2016-01-19 14:09:37 -0800 | [diff] [blame] | 1695 | chmod -r SANETESTD.1/x && |
Torsten Bögershausen | f400e51 | 2015-01-27 16:39:01 +0100 | [diff] [blame] | 1696 | chmod -rx SANETESTD.2 || |
SZEDER Gábor | 165293a | 2018-11-19 14:13:26 +0100 | [diff] [blame] | 1697 | BUG "cannot prepare SANETESTD" |
Torsten Bögershausen | f400e51 | 2015-01-27 16:39:01 +0100 | [diff] [blame] | 1698 | |
Junio C Hamano | 719c3da | 2016-01-19 14:09:37 -0800 | [diff] [blame] | 1699 | ! test -r SANETESTD.1/x && |
Torsten Bögershausen | f400e51 | 2015-01-27 16:39:01 +0100 | [diff] [blame] | 1700 | ! rm SANETESTD.1/x && ! test -f SANETESTD.2/x |
| 1701 | status=$? |
| 1702 | |
| 1703 | chmod +rwx SANETESTD.1 SANETESTD.2 && |
| 1704 | rm -rf SANETESTD.1 SANETESTD.2 || |
SZEDER Gábor | 165293a | 2018-11-19 14:13:26 +0100 | [diff] [blame] | 1705 | BUG "cannot clean SANETESTD" |
Torsten Bögershausen | f400e51 | 2015-01-27 16:39:01 +0100 | [diff] [blame] | 1706 | return $status |
| 1707 | ' |
Jeff King | f838ce5 | 2013-03-10 21:31:47 -0400 | [diff] [blame] | 1708 | |
Johannes Schindelin | d98b2c5 | 2016-07-21 18:02:54 +0200 | [diff] [blame] | 1709 | test FreeBSD != $uname_s || GIT_UNZIP=${GIT_UNZIP:-/usr/local/bin/unzip} |
Jeff King | f838ce5 | 2013-03-10 21:31:47 -0400 | [diff] [blame] | 1710 | GIT_UNZIP=${GIT_UNZIP:-unzip} |
| 1711 | test_lazy_prereq UNZIP ' |
| 1712 | "$GIT_UNZIP" -v |
| 1713 | test $? -ne 127 |
| 1714 | ' |
Jeff King | 9a308de | 2015-03-13 00:53:07 -0400 | [diff] [blame] | 1715 | |
| 1716 | run_with_limited_cmdline () { |
| 1717 | (ulimit -s 128 && "$@") |
| 1718 | } |
| 1719 | |
Ramsay Jones | 21dac1d | 2017-09-14 18:24:41 +0100 | [diff] [blame] | 1720 | test_lazy_prereq CMDLINE_LIMIT ' |
Greg Price | ddcfc7c | 2020-05-15 22:33:38 -0700 | [diff] [blame] | 1721 | test_have_prereq !HPPA,!MINGW,!CYGWIN && |
Ramsay Jones | 21dac1d | 2017-09-14 18:24:41 +0100 | [diff] [blame] | 1722 | run_with_limited_cmdline true |
| 1723 | ' |
Jeff King | 6b9c38e | 2016-07-11 19:54:18 -0400 | [diff] [blame] | 1724 | |
Michael J Gruber | 4db464f | 2017-09-07 16:02:20 +0200 | [diff] [blame] | 1725 | run_with_limited_stack () { |
| 1726 | (ulimit -s 128 && "$@") |
| 1727 | } |
| 1728 | |
Ramsay Jones | 21dac1d | 2017-09-14 18:24:41 +0100 | [diff] [blame] | 1729 | test_lazy_prereq ULIMIT_STACK_SIZE ' |
Greg Price | ddcfc7c | 2020-05-15 22:33:38 -0700 | [diff] [blame] | 1730 | test_have_prereq !HPPA,!MINGW,!CYGWIN && |
Ramsay Jones | 21dac1d | 2017-09-14 18:24:41 +0100 | [diff] [blame] | 1731 | run_with_limited_stack true |
| 1732 | ' |
Michael J Gruber | 4db464f | 2017-09-07 16:02:20 +0200 | [diff] [blame] | 1733 | |
Taylor Blau | b30fdb4 | 2020-04-23 15:41:06 -0600 | [diff] [blame] | 1734 | run_with_limited_open_files () { |
| 1735 | (ulimit -n 32 && "$@") |
| 1736 | } |
| 1737 | |
| 1738 | test_lazy_prereq ULIMIT_FILE_DESCRIPTORS ' |
| 1739 | test_have_prereq !MINGW,!CYGWIN && |
| 1740 | run_with_limited_open_files true |
| 1741 | ' |
| 1742 | |
Jeff King | 6b9c38e | 2016-07-11 19:54:18 -0400 | [diff] [blame] | 1743 | build_option () { |
| 1744 | git version --build-options | |
| 1745 | sed -ne "s/^$1: //p" |
| 1746 | } |
| 1747 | |
| 1748 | test_lazy_prereq LONG_IS_64BIT ' |
| 1749 | test 8 -le "$(build_option sizeof-long)" |
| 1750 | ' |
Johannes Schindelin | a07fb05 | 2017-04-20 22:52:13 +0200 | [diff] [blame] | 1751 | |
Nguyễn Thái Ngọc Duy | a801a7c | 2018-03-24 08:44:36 +0100 | [diff] [blame] | 1752 | test_lazy_prereq TIME_IS_64BIT 'test-tool date is64bit' |
| 1753 | test_lazy_prereq TIME_T_IS_64BIT 'test-tool date time_t-is64bit' |
Jeff King | e9184b0 | 2018-04-03 10:01:57 -0400 | [diff] [blame] | 1754 | |
| 1755 | test_lazy_prereq CURL ' |
| 1756 | curl --version |
| 1757 | ' |
brian m. carlson | d16ab63 | 2018-05-13 02:24:11 +0000 | [diff] [blame] | 1758 | |
| 1759 | # SHA1 is a test if the hash algorithm in use is SHA-1. This is both for tests |
| 1760 | # which will not work with other hash algorithms and tests that work but don't |
| 1761 | # test anything meaningful (e.g. special values which cause short collisions). |
| 1762 | test_lazy_prereq SHA1 ' |
brian m. carlson | c49fe07 | 2020-07-29 23:14:25 +0000 | [diff] [blame] | 1763 | case "$GIT_DEFAULT_HASH" in |
| 1764 | sha1) true ;; |
| 1765 | "") test $(git hash-object /dev/null) = e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 ;; |
| 1766 | *) false ;; |
| 1767 | esac |
brian m. carlson | d16ab63 | 2018-05-13 02:24:11 +0000 | [diff] [blame] | 1768 | ' |
Johannes Schindelin | 11aad46 | 2018-10-31 13:02:02 -0700 | [diff] [blame] | 1769 | |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 1770 | # Ensure that no test accidentally triggers a Git command |
Derrick Stolee | 31345d5 | 2020-11-24 04:16:42 +0000 | [diff] [blame] | 1771 | # that runs the actual maintenance scheduler, affecting a user's |
| 1772 | # system permanently. |
| 1773 | # Tests that verify the scheduler integration must set this locally |
Derrick Stolee | 2fec604 | 2020-09-11 17:49:18 +0000 | [diff] [blame] | 1774 | # to avoid errors. |
Derrick Stolee | 31345d5 | 2020-11-24 04:16:42 +0000 | [diff] [blame] | 1775 | GIT_TEST_MAINT_SCHEDULER="none:exit 1" |