]>
diplodocus.org Git - nmh/blob - test/mkstemp/test-mkstemp
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
33 if [ $has_mkstemps -eq 1 ]; then
34 cat >$expected <<-'EOF'
35 Usage: mkstemp [switches]
44 cat >$expected <<-'EOF'
45 Usage: mkstemp [switches]
54 #### Skip nmh intro text.
55 run_prog
$mkstemp -h 2>&1 | sed '/^$/,$d' >"$actual"
56 check
"$expected" "$actual"
61 # Verified same behavior as compiled mhmail.
64 * ) printf '%s: mkstemp -v generated unexpected output\n' "$0" >&2
65 failed
=`expr ${failed:-0} + 1`;;
69 # check with no switches
70 start_test
"with no switches"
72 if [ -f "$tmpfile" ]; then
80 start_test
"-directory"
81 tmpfile
=`$mkstemp -directory "$MHTMPDIR"`
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 "^$MHTMPDIR/......$" >/dev/null`
85 run_test
'eval echo $check_tmpfile' ''
90 tmpfile
=`$mkstemp -prefix mkstemptest`
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 '^mkstemptest......$' >/dev/null`
94 run_test
'eval echo $check_tmpfile' ''
97 if [ $has_mkstemps -eq 1 ]; then
99 tmpfile
=`$mkstemp -suffix .txt`
100 [ -f "$tmpfile" ] && rm "$tmpfile" || failed
=`expr ${failed:-0} + 1`
101 # Rely on exit status of grep to detect failure and terminate due to set -e:
102 check_tmpfile
=`echo $tmpfile | grep '^......\.txt$' >/dev/null`
103 run_test
'eval echo $check_tmpfile' ''