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"
24 check_exit '-eq 1' $mkstemp -
26 $mkstemp -help | grep suffix >/dev/null && has_mkstemps=1 || has_mkstemps=0
32 if [ $has_mkstemps -eq 1 ]; then
33 cat >$expected <<-'EOF'
34 Usage: mkstemp [switches]
43 cat >$expected <<-'EOF'
44 Usage: mkstemp [switches]
53 #### Skip nmh intro text.
54 run_prog $mkstemp -h 2>&1 | sed '/^$/,$d' >"$actual"
55 check "$expected" "$actual"
59 # Verified same behavior as compiled mhmail.
62 * ) printf '%s: mkstemp -v generated unexpected output\n' "$0" >&2
63 failed=`expr ${failed:-0} + 1`;;
67 # check with no switches
69 if [ -f "$tmpfile" ]; then
77 tmpfile=`$mkstemp -directory "$MHTMPDIR"`
78 [ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
79 # Rely on exit status of grep to detect failure and terminate due to set -e:
80 check_tmpfile=`echo $tmpfile | grep "^$MHTMPDIR/......$" >/dev/null`
81 run_test 'eval echo $check_tmpfile' ''
85 tmpfile=`$mkstemp -prefix mkstemptest`
86 [ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
87 # Rely on exit status of grep to detect failure and terminate due to set -e:
88 check_tmpfile=`echo $tmpfile | grep '^mkstemptest......$' >/dev/null`
89 run_test 'eval echo $check_tmpfile' ''
92 if [ $has_mkstemps -eq 1 ]; then
94 tmpfile=`$mkstemp -suffix .txt`
95 [ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
96 # Rely on exit status of grep to detect failure and terminate due to set -e:
97 check_tmpfile=`echo $tmpfile | grep '^......\.txt$' >/dev/null`
98 run_test 'eval echo $check_tmpfile' ''