Blame tests/init.cfg

Packit 709fb3
# This file is sourced by init.sh, *before* its initialization.
Packit 709fb3
Packit 709fb3
# This goes hand in hand with the "9>&2;" in tests/Makefile.am's
Packit 709fb3
# TESTS_ENVIRONMENT definition.
Packit 709fb3
stderr_fileno_=9
Packit 709fb3
Packit 709fb3
# Map settings of "none" to the empty string.
Packit 709fb3
test _"$LOCALE_FR" = _none && LOCALE_FR=
Packit 709fb3
test _"$LOCALE_FR_UTF8" = _none && LOCALE_FR_UTF8=
Packit 709fb3
Packit 709fb3
# Unset key environment variables.
Packit 709fb3
if (FOO=FOO; unset FOO) >/dev/null 2>&1; then
Packit 709fb3
  as_unset=unset
Packit 709fb3
else
Packit 709fb3
  as_unset=false
Packit 709fb3
fi
Packit 709fb3
Packit 709fb3
# Derive this list by searching for string literals as the first
Packit 709fb3
# argument to getenv:
Packit 709fb3
# git grep getenv|perl -nle '/\bgetenv *\("(.+?)"\)/ and print $1'|sort -u grep
Packit 709fb3
vars_='
Packit 709fb3
GREP_COLOR
Packit 709fb3
GREP_COLORS
Packit 709fb3
GREP_OPTIONS
Packit 709fb3
TERM
Packit 709fb3
'
Packit 709fb3
envvar_check_fail=0
Packit 709fb3
for v_ in $vars_
Packit 709fb3
do
Packit 709fb3
  $as_unset $v_
Packit 709fb3
  if eval test \"\${$v_+set}\" = set; then
Packit 709fb3
    echo "$0: the $v_ environment variable is set --" \
Packit 709fb3
      ' unset it and rerun this test' >&2
Packit 709fb3
    envvar_check_fail=1
Packit 709fb3
  fi
Packit 709fb3
done
Packit 709fb3
Packit 709fb3
test "$envvar_check_fail" = 1 && fail_ "failed to unset the above envvars"
Packit 709fb3
Packit 709fb3
require_timeout_()
Packit 709fb3
{
Packit 709fb3
  ( timeout 10s true ) > /dev/null 2>&1 \
Packit 709fb3
    || skip_ your system lacks the timeout program
Packit 709fb3
  returns_ 1 timeout 10s false \
Packit 709fb3
    || skip_ your system has a non-GNU timeout program
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
require_pcre_()
Packit 709fb3
{
Packit 709fb3
  echo . | grep -P . 2>err || {
Packit 709fb3
    test $? -eq 1 && fail_ PCRE available, but does not work.
Packit 709fb3
    skip_ no PCRE support
Packit 709fb3
  }
Packit 709fb3
  compare /dev/null err || fail_ PCRE available, but stderr not empty.
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
# Some tests would fail without this particular locale.
Packit 709fb3
# If the locale is not available, just skip the test.
Packit 709fb3
require_en_utf8_locale_()
Packit 709fb3
{
Packit 709fb3
  path_prepend_ .
Packit 709fb3
  case $(get-mb-cur-max en_US.UTF-8) in
Packit 709fb3
    [3456]) ;;
Packit 709fb3
    *) skip_ 'en_US.UTF-8 locale not found' ;;
Packit 709fb3
  esac
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
require_tr_utf8_locale_()
Packit 709fb3
{
Packit 709fb3
  path_prepend_ .
Packit 709fb3
  case $(get-mb-cur-max tr_TR.UTF-8) in
Packit 709fb3
    [3456]) ;;
Packit 709fb3
    *) skip_ 'tr_TR.UTF-8 locale not found' ;;
Packit 709fb3
  esac
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
require_ru_RU_koi8_r()
Packit 709fb3
{
Packit 709fb3
  path_prepend_ .
Packit 709fb3
  case $(get-mb-cur-max ru_RU.KOI8-R) in
Packit 709fb3
    1) ;;
Packit 709fb3
    *) skip_ 'ru_RU.KOI8-R locale not found' ;;
Packit 709fb3
  esac
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
require_compiled_in_MB_support()
Packit 709fb3
{
Packit 709fb3
  require_en_utf8_locale_
Packit 709fb3
  printf 'é' | LC_ALL=en_US.UTF-8 grep '[[:lower:]]' \
Packit 709fb3
    || skip_ this test requires MBS support
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
require_unibyte_locale()
Packit 709fb3
{
Packit 709fb3
  path_prepend_ .
Packit 709fb3
  for loc in C en_US; do
Packit 709fb3
    for encoding in '' .iso88591 .iso885915 .ISO8859-1 .ISO8859-15; do
Packit 709fb3
      locale=$loc$encoding
Packit 709fb3
      MB_CUR_MAX=$(get-mb-cur-max $locale 2>/dev/null) &&
Packit 709fb3
        test "$MB_CUR_MAX" -eq 1 &&
Packit 709fb3
        LC_ALL=$locale &&
Packit 709fb3
        export LC_ALL &&
Packit 709fb3
        return
Packit 709fb3
    done
Packit 709fb3
  done
Packit 709fb3
  skip_ 'no unibyte locale found'
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
# Define hi_res_time_ to a function that prints the current time
Packit 709fb3
# as a floating point number with greater than 1-second resolution.
Packit 709fb3
# Otherwise, skip the requiring test.
Packit 709fb3
require_hi_res_time_()
Packit 709fb3
{
Packit 709fb3
  local cmd
Packit 709fb3
  for cmd in 'date +%s.%N' \
Packit 709fb3
          'perl -le "use Time::HiRes qw(time); print scalar time()"'; do
Packit 709fb3
      case $($cmd) in
Packit 709fb3
          *.[0-9]*) eval 'hi_res_time_() { '"$cmd"'; }'; break;;
Packit 709fb3
      esac
Packit 709fb3
  done
Packit 709fb3
  type hi_res_time_ || skip_ no high-resolution timer support
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
require_JP_EUC_locale_()
Packit 709fb3
{
Packit 709fb3
  local locale=ja_JP.eucJP
Packit 709fb3
  path_prepend_ .
Packit 709fb3
  case $(get-mb-cur-max $locale) in
Packit 709fb3
    [23])
Packit 709fb3
        LC_ALL=$locale &&
Packit 709fb3
        export LC_ALL &&
Packit 709fb3
        return
Packit 709fb3
        ;;
Packit 709fb3
    *) ;;
Packit 709fb3
  esac
Packit 709fb3
Packit 709fb3
  skip_ "$loc locale not found"
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
expensive_()
Packit 709fb3
{
Packit 709fb3
  if test "$RUN_EXPENSIVE_TESTS" != yes; then
Packit 709fb3
    skip_ 'expensive: disabled by default
Packit 709fb3
This test is relatively expensive, so it is disabled by default.
Packit 709fb3
To run it anyway, rerun make check with the RUN_EXPENSIVE_TESTS
Packit 709fb3
environment variable set to yes.  E.g.,
Packit 709fb3
Packit 709fb3
  env RUN_EXPENSIVE_TESTS=yes make check
Packit 709fb3
Packit 709fb3
or use the shortcut target of the toplevel Makefile,
Packit 709fb3
Packit 709fb3
  make check-expensive
Packit 709fb3
'
Packit 709fb3
  fi
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
# Like printf with a single argument, but that argument must be a
Packit 709fb3
# sequence of four-byte strings \xHH where each H is a hexadecimal byte.
Packit 709fb3
hex_printf_()
Packit 709fb3
{
Packit 709fb3
  local octal_fmt=$(printf '\\%o' \
Packit 709fb3
    $(printf '%s\n' "$1" \
Packit 709fb3
      | sed 's,\\x\([0-9abcdefABCDEF][0-9abcdefABCDEF]\), 0x\1,g'))
Packit 709fb3
  printf "$octal_fmt"
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
# Wrap tr so that it always runs in the C locale.
Packit 709fb3
# Otherwise, in a multibyte locale, GNU tr (which is not multibyte-aware
Packit 709fb3
# as of 2014-11-08), would work differently than others.  For example,
Packit 709fb3
# this command, which was written with unibyte GNU tr in mind,
Packit 709fb3
#   LC_ALL=ja_JP.eucJP tr AB '\244\263'
Packit 709fb3
# would act like this with the multibyte tr from HP-UX and Solaris:
Packit 709fb3
#   LC_ALL=ja_JP.eucJP tr A  '\244\263'
Packit 709fb3
tr() { LC_ALL=C env -- tr "$@"; }
Packit 709fb3
Packit 709fb3
# Usage: user_time_ EXPECTED_EXIT_STATUS CMD ...
Packit 709fb3
# If CMD ... exits with the expected exit status, print the elapsed
Packit 709fb3
# child "user" time (not "system" time) in milliseconds and return 0.
Packit 709fb3
# Otherwise, diagnose the exit status mismatch and return nonzero.
Packit 709fb3
user_time_()
Packit 709fb3
{
Packit 709fb3
  $PERL -le '
Packit 709fb3
    my $expected_exit_status = $ARGV[0];
Packit 709fb3
    shift @ARGV;
Packit 709fb3
Packit 709fb3
    system (@ARGV);
Packit 709fb3
    my ($user, $system, $child_user, $child_system) = times;
Packit 709fb3
Packit 709fb3
    my $me = q('"$ME_"');
Packit 709fb3
    $? == -1
Packit 709fb3
      and die qq($me: failed to exec ") . join (" ", @ARGV) . qq(": $!\n);
Packit 709fb3
    my $rc = $?;
Packit 709fb3
    my $sig = ($rc & 127);
Packit 709fb3
    $sig and die "$me: child died with signal $sig\n";
Packit 709fb3
    $rc >>= 8;
Packit 709fb3
    $rc == $expected_exit_status
Packit 709fb3
      or die "$me: bad exit status: expected $expected_exit_status; got $rc\n";
Packit 709fb3
Packit 709fb3
    # Print milliseconds of child user time.
Packit 709fb3
    $child_user *= 1000;
Packit 709fb3
    print int ($child_user + 0.5)' "$@"
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
# yes is not portable, fake it with $AWK
Packit 709fb3
yes() { line=${*-y} ${AWK-awk} 'BEGIN{for (;;) print ENVIRON["line"]}'; }