Blame gnulib-tests/test-init.sh

Packit 709fb3
#!/bin/sh
Packit 709fb3
# Unit tests for init.sh
Packit 709fb3
# Copyright (C) 2011-2017 Free Software Foundation, Inc.
Packit 709fb3
# This file is part of the GNUlib Library.
Packit 709fb3
#
Packit 709fb3
# This program is free software: you can redistribute it and/or modify
Packit 709fb3
# it under the terms of the GNU General Public License as published by
Packit 709fb3
# the Free Software Foundation; either version 3 of the License, or
Packit 709fb3
# (at your option) any later version.
Packit 709fb3
#
Packit 709fb3
# This program is distributed in the hope that it will be useful,
Packit 709fb3
# but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 709fb3
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 709fb3
# GNU General Public License for more details.
Packit 709fb3
#
Packit 709fb3
# You should have received a copy of the GNU General Public License
Packit 709fb3
# along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit 709fb3
Packit 709fb3
: ${srcdir=.}
Packit 709fb3
. "$srcdir/init.sh"; path_prepend_ .
Packit 709fb3
Packit 709fb3
fail=0
Packit 709fb3
Packit 709fb3
test_compare()
Packit 709fb3
{
Packit 709fb3
  touch empty || fail=1
Packit 709fb3
  echo xyz > in || fail=1
Packit 709fb3
Packit 709fb3
  compare /dev/null /dev/null >out 2>err || fail=1
Packit 709fb3
  test -s out && fail_ "out not empty: $(cat out)"
Packit 709fb3
  # "err" should be empty, too, but has "set -x" output when VERBOSE=yes
Packit 709fb3
  case $- in *x*) ;; *) test -s err && fail_ "err not empty: $(cat err)";; esac
Packit 709fb3
Packit 709fb3
  compare /dev/null empty >out 2>err || fail=1
Packit 709fb3
  test -s out && fail_ "out not empty: $(cat out)"
Packit 709fb3
  case $- in *x*) ;; *) test -s err && fail_ "err not empty: $(cat err)";; esac
Packit 709fb3
Packit 709fb3
  compare in in >out 2>err || fail=1
Packit 709fb3
  test -s out && fail_ "out not empty: $(cat out)"
Packit 709fb3
  case $- in *x*) ;; *) test -s err && fail_ "err not empty: $(cat err)";; esac
Packit 709fb3
Packit 709fb3
  compare /dev/null in >out 2>err && fail=1
Packit 709fb3
  cat <<\EOF > exp
Packit 709fb3
diff -u /dev/null in
Packit 709fb3
--- /dev/null	1970-01-01
Packit 709fb3
+++ in	1970-01-01
Packit 709fb3
+xyz
Packit 709fb3
EOF
Packit 709fb3
  compare exp out || fail=1
Packit 709fb3
  case $- in *x*) ;; *) test -s err && fail_ "err not empty: $(cat err)";; esac
Packit 709fb3
Packit 709fb3
  compare empty in >out 2>err && fail=1
Packit 709fb3
  # Compare against expected output only if compare is using diff -u.
Packit 709fb3
  if grep @ out >/dev/null; then
Packit 709fb3
    # Remove the TAB-date suffix on each --- and +++ line,
Packit 709fb3
    # for both the expected and the actual output files.
Packit 709fb3
    # Also remove the @@ line, since Solaris 5.10 and GNU diff formats differ:
Packit 709fb3
    # -@@ -0,0 +1 @@
Packit 709fb3
    # +@@ -1,0 +1,1 @@
Packit 709fb3
    # Also, remove space after leading '+', since AIX 7.1 diff outputs a space.
Packit 709fb3
    sed 's/	.*//;/^@@/d;s/^+ /+/' out > k && mv k out
Packit 709fb3
    cat <<\EOF > exp
Packit 709fb3
--- empty
Packit 709fb3
+++ in
Packit 709fb3
+xyz
Packit 709fb3
EOF
Packit 709fb3
    compare exp out || fail=1
Packit 709fb3
  fi
Packit 709fb3
  case $- in *x*) ;; *) test -s err && fail_ "err not empty: $(cat err)";; esac
Packit 709fb3
}
Packit 709fb3
Packit 709fb3
test_compare
Packit 709fb3
Packit 709fb3
Exit $fail