Debian Codegraph @

tests/init.cfg

raw
1 # This file is sourced by init.sh, *before* its initialization.
2
3 # Copyright (C) 2010-2025 Free Software Foundation, Inc.
4
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 3 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 <https://www.gnu.org/licenses/>.
17
18 # Skip the current test if valgrind doesn't work,
19 # which could happen if not installed,
20 # or hasn't support for the built architecture,
21 # or hasn't appropriate error suppressions installed etc.
22
23 # This goes hand in hand with the "exec 9>&2;" in tests/Makefile.am's
24 # TESTS_ENVIRONMENT definition.
25 stderr_fileno_=9
26
27 # Having an unsearchable directory in PATH causes execve to fail with EACCES
28 # when applied to an unresolvable program name, contrary to the desired ENOENT.
29 # Avoid the problem by rewriting PATH to exclude unsearchable directories.
30 # Also, if PATH lacks /sbin and/or /usr/sbin, append it/them.
31 sanitize_path_()
32 {
33 # FIXME: remove double quotes around $IFS when all tests use init.sh.
34 # They constitute a work-around for a bug in FreeBSD 8.1's /bin/sh.
35 local saved_IFS="$IFS"
36 IFS=$PATH_SEPARATOR
37 set -- $PATH
38 IFS=$saved_IFS
39
40 local d d1
41 local colon=
42 local new_path=
43 for d in "$@"; do
44 test -z "$d" && d1=. || d1=$d
45 if ls -d "$d1/." > /dev/null 2>&1; then
46 new_path="$new_path$colon$d"
47 colon=$PATH_SEPARATOR
48 fi
49 done
50
51 for d in /sbin /usr/sbin ; do
52 case "$PATH_SEPARATOR$new_path$PATH_SEPARATOR" in
53 *$PATH_SEPARATOR$d$PATH_SEPARATOR*) ;;
54 *) new_path="$new_path$PATH_SEPARATOR$d" ;;
55 esac
56 done
57
58 PATH=$new_path
59 export PATH
60 }
61
62 require_timeout_()
63 {
64 ( timeout 10s true ) > /dev/null 2>&1 \
65 || skip_ your system lacks the timeout program
66 returns_ 1 timeout 10s false \
67 || skip_ your system has a non-GNU timeout program
68 returns_ 124 timeout 0.01 sleep 0.02 \
69 || skip_ "'timeout 0.01 sleep 0.02' did not time out"
70 }
71
72 require_valgrind_()
73 {
74 require_timeout_
75 local errout; errout=$(
76 LC_ALL=C timeout --signal=9 3 valgrind --error-exitcode=1 diff /dev/null /dev/null 2>&1
77 ) ||
78 skip_ "requires a working valgrind"
79 case $errout in
80 *'Serious error'*)
81 skip_ "requires a valgrind without serious errors";;
82 esac
83 }
84
85 # Skip the current test if we lack Perl.
86 require_perl_()
87 {
88 : ${PERL=perl}
89 $PERL -e 'use warnings' > /dev/null 2>&1 \
90 || skip_ 'configure did not find a usable version of Perl'
91 }
92
93 # Run this test in a UTF-8 locale if possible, and skip the test otherwise.
94 # Prefer en_US for its diagnostics.
95 require_utf8_locale_()
96 {
97 local locale
98
99 if test "`(locale charmap) 2>/dev/null`" != UTF-8; then
100 for locale in en_US.UTF-8 `(locale -a) 2>/dev/null` not-found; do
101 case $locale in
102 *.[Uu][Tt][Ff]*8)
103 if test "`(LC_ALL=$locale locale charmap) 2>/dev/null`" = UTF-8; then
104 LC_ALL=$locale
105 export LC_ALL
106 break
107 fi;;
108 not-found)
109 skip_ "No UTF-8 locale found";;
110 esac
111 done
112 fi
113
114 # Solaris 10's /usr/bin/tr can silently malfunction. Try to find one that works.
115 found_working_tr=0
116 for i in tr /usr/xpg4/bin/tr gtr; do
117 tr() { env $i "$@"; }
118 test '一' = "$(printf 一|tr a b)" && { found_working_tr=1; break; }
119 done
120 test $found_working_tr = 1 || skip_ "failed to find a working tr program"
121 }
122
123 # Some systems lack seq.
124 # A limited replacement for seq: handle 1 or 2 args; increment must be 1
125 seq()
126 {
127 case $# in
128 1) start=1 final=$1;;
129 2) start=$1 final=$2;;
130 *) echo you lose 1>&2; exit 1;;
131 esac
132 awk 'BEGIN{for(i='$start';i<='$final';i++) print i}' < /dev/null
133 }
134
135 sanitize_path_