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