#! /bin/sh
# Test atexit handling.
#
# Copyright (C) 2019 Free Software Foundation, Inc.
#
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.

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

if ! [ -c /dev/full ]; then
  # no such character device, skip this check
  exit 77
fi

tmpfiles="atexit-test1.ok"
cat <<EOF >atexit-test1.ok
hello: write error: No space left on device
EOF

tmpfiles="$tmpfiles atexit-test1.out"
: ${HELLO=hello}
${HELLO} 2>&1 1>/dev/full | tr -d '\r' >atexit-test1.out

# remove \r (CR) characters from the output, so that the tests work on
# platforms with CRLF line endings.  There is apparently no reliable
# method (across Cygwin, MingW, etc.) to force an eol style.

: ${DIFF=diff}
${DIFF} atexit-test1.ok atexit-test1.out
result=$?

rm -fr $tmpfiles

exit $result
