#! /bin/sh
. "${srcdir=.}/init.sh"; path_prepend_ . ../src

# Test for sanity checks.

: ${AUTOCONF=autoconf}
${AUTOCONF} --version >/dev/null 2>/dev/null \
  || { echo "Skipping test: autoconf not found"; exit 77; }

cat <<\EOF >configure.ac
AC_PREREQ([2.60])
EOF

${AUTOCONF} >/dev/null 2>/dev/null \
  || { echo "Skipping test: autoconf version too old"; exit 77; }

rm -f configure.ac

gettext_datadir=$top_builddir/misc
export gettext_datadir

# Check if sanity checks are actually working.

# no configure.ac
$gettext_datadir/autopoint 2>&1 | grep -q 'Missing configure.in or configure.ac' \
    || exit 1

test ! -d intl || exit 1
test ! -d m4 || exit 1
test ! -d po || exit 1

# configure.ac without AM_GNU_GETTEXT_VERSION
cat <<\EOF >configure.ac
AC_INIT
AC_CONFIG_SRCDIR(hello.c)

AC_PROG_CC

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
EOF

$gettext_datadir/autopoint 2>&1 | grep -q 'Missing version' \
    || exit 1

test ! -d intl || exit 1
test ! -d m4 || exit 1
test ! -d po || exit 1

# VERSION specified through intl/VERSION file, but in wrong format
cat <<\EOF >configure.ac
AC_INIT
AC_CONFIG_SRCDIR(hello.c)

AC_PROG_CC

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
EOF

test -d intl || mkdir intl
echo bogus-version > intl/VERSION

$gettext_datadir/autopoint 2>&1 | grep -q 'Missing version' \
    || exit 1

test ! -d m4 || exit 1
test ! -d po || exit 1

# VERSION specified through intl/VERSION file
cat <<\EOF >configure.ac
AC_INIT
AC_CONFIG_SRCDIR(hello.c)

AC_PROG_CC

AC_CONFIG_FILES([Makefile])
AC_OUTPUT
EOF

test -d intl || mkdir intl
echo gettext-0.15 > intl/VERSION

$gettext_datadir/autopoint 2>&1 | grep -q 'locally modified' || exit 1

test ! -d m4 || exit 1
test ! -d po || exit 1

rm -fr intl

exit 0
