1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
|
#!/bin/sh
##################################
#
# Test creation of temporary file.
#
##################################
set -e
if test -z "${MH_OBJ_DIR}"; then
srcdir=`dirname "$0"`/../..
MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
fi
. "$MH_OBJ_DIR/test/common.sh"
setup_test
expected="$MH_TEST_DIR"/$$.expected
actual="$MH_TEST_DIR"/$$.actual
mkstemp="${MH_LIB_DIR}/mkstemp"
$mkstemp -help | grep suffix >/dev/null && has_mkstemps=1 || has_mkstemps=0
cd "$MHTMPDIR"
# check -help
if [ $has_mkstemps -eq 1 ]; then
cat >$expected <<-'EOF'
Usage: mkstemp [switches]
switches are:
-directory
-prefix
-suffix
-version
-help
EOF
else
cat >$expected <<-'EOF'
Usage: mkstemp [switches]
switches are:
-directory
-prefix
-version
-help
EOF
fi
$mkstemp -h >$actual 2>&1
check $expected $actual
# check -version
# Verified same behavior as compiled mhmail.
case `$mkstemp -v` in
mkstemp\ --*) ;;
* ) printf '%s: mkstemp -v generated unexpected output\n' "$0" >&2
failed=`expr ${failed:-0} + 1`;;
esac
# check with no switches
tmpfile=`$mkstemp`
if [ -f "$tmpfile" ]; then
rm "$tmpfile"
else
failed=1
fi
# check -directory
tmpfile=`$mkstemp -directory "$MHTMPDIR"`
[ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
# Rely on exit status of grep to detect failure and terminate due to set -e:
check_tmpfile=`echo $tmpfile | grep "^$MHTMPDIR/......$" >/dev/null`
run_test 'eval echo $check_tmpfile' ''
# check -prefix
tmpfile=`$mkstemp -prefix mkstemptest`
[ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
# Rely on exit status of grep to detect failure and terminate due to set -e:
check_tmpfile=`echo $tmpfile | grep '^mkstemptest......$' >/dev/null`
run_test 'eval echo $check_tmpfile' ''
if [ $has_mkstemps -eq 1 ]; then
# check -suffix
tmpfile=`$mkstemp -suffix .txt`
[ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
# Rely on exit status of grep to detect failure and terminate due to set -e:
check_tmpfile=`echo $tmpfile | grep '^......\.txt$' >/dev/null`
run_test 'eval echo $check_tmpfile' ''
fi
exit $failed
|