#!/bin/sh

# Test of ITS search path.

tmpfiles=""
trap 'rm -fr $tmpfiles' 1 2 3 15

for d in xg-its-2-a xg-its-2-b xg-its-2-c xg-its-2-xa xg-its-2-xb xg-its-2-xc; do
  tmpfiles="$tmpfiles $d"
  test -d "$d" || mkdir "$d"
  base="$d"
  if expr "$d" : xg-its-2-x 2>&1 >/dev/null; then
    test -d "$d/gettext" || mkdir "$d/gettext"
    base="$d/gettext"
  fi
  test -d "$base/its" || mkdir "$base/its"
  cat <<EOF > "$base/its/$d.loc"
<?xml version='1.0'?>
<locatingRules>
  <locatingRule pattern='*.$d'>
    <documentRule prefix='' localName='$d' target='empty.its'/>
  </locatingRule>
</locatingRules>
EOF
  cat <<EOF > "$base/its/empty.its"
<?xml version='1.0'?>
<its:rules xmlns:its='http://www.w3.org/2005/11/its' version='1.0'>
</its:rules>
EOF
  tmpfiles="$tmpfiles input.$d"
  cat <<EOF > "input.$d"
<?xml version='1.0'?>
<$d>
</$d>
EOF
done

: ${XGETTEXT=xgettext}

unset GETTEXTDATADIR
unset GETTEXTDATADIRS
unset XDG_DATA_DIRS

${XGETTEXT} -o /dev/null input.xg-its-2-a 2>&1 | grep 'is unknown; will try C' 2>&1 >/dev/null
result=$?
test $result = 0 || exit 1

GETTEXTDATADIR=xg-its-2-a
export GETTEXTDATADIR
${XGETTEXT} -o /dev/null input.xg-its-2-a 2>&1 | grep 'is unknown; will try C' 2>&1 >/dev/null
result=$?
test $result = 0 && exit 1

GETTEXTDATADIRS=xg-its-2-b:xg-its-2-a
export GETTEXTDATADIRS
${XGETTEXT} -o /dev/null input.xg-its-2-b 2>&1 | grep 'is unknown; will try C' 2>&1 >/dev/null
result=$?
test $result = 0 && exit 1

XDG_DATA_DIRS=xg-its-2-xa
export XDG_DATA_DIRS
${XGETTEXT} -o /dev/null input.xg-its-2-xa 2>&1 | grep 'is unknown; will try C' 2>&1 >/dev/null
result=$?
test $result = 0 && exit 1

rm -fr $tmpfiles

exit 0
