2 ##################################
4 # Test creation of temporary file.
6 ##################################
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir=`dirname "$0"`/../..
12 MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
15 . "$MH_OBJ_DIR/test/common.sh"
19 expected="$MH_TEST_DIR"/$$.expected
20 actual="$MH_TEST_DIR"/$$.actual
22 mkstemp="${MH_LIBEXEC_DIR}/mkstemp"
23 $mkstemp -help | grep suffix >/dev/null && has_mkstemps=1 || has_mkstemps=0
29 if [ $has_mkstemps -eq 1 ]; then
30 cat >$expected <<-'EOF'
31 Usage: mkstemp [switches]
40 cat >$expected <<-'EOF'
41 Usage: mkstemp [switches]
50 $mkstemp -h >$actual 2>&1
51 check $expected $actual
55 # Verified same behavior as compiled mhmail.
58 * ) printf '%s: mkstemp -v generated unexpected output\n' "$0" >&2
59 failed=`expr ${failed:-0} + 1`;;
63 # check with no switches
65 if [ -f "$tmpfile" ]; then
73 tmpfile=`$mkstemp -directory "$MHTMPDIR"`
74 [ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
75 # Rely on exit status of grep to detect failure and terminate due to set -e:
76 check_tmpfile=`echo $tmpfile | grep "^$MHTMPDIR/......$" >/dev/null`
77 run_test 'eval echo $check_tmpfile' ''
81 tmpfile=`$mkstemp -prefix mkstemptest`
82 [ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
83 # Rely on exit status of grep to detect failure and terminate due to set -e:
84 check_tmpfile=`echo $tmpfile | grep '^mkstemptest......$' >/dev/null`
85 run_test 'eval echo $check_tmpfile' ''
88 if [ $has_mkstemps -eq 1 ]; then
90 tmpfile=`$mkstemp -suffix .txt`
91 [ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
92 # Rely on exit status of grep to detect failure and terminate due to set -e:
93 check_tmpfile=`echo $tmpfile | grep '^......\.txt$' >/dev/null`
94 run_test 'eval echo $check_tmpfile' ''