]> diplodocus.org Git - nmh/blob - test/mkstemp/test-mkstemp
Fix invalid pointer arithmetic.
[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_LIBEXEC_DIR}/mkstemp"
23
24 check_exit '-eq 1' $mkstemp -
25
26 $mkstemp -help | grep suffix >/dev/null && has_mkstemps=1 || has_mkstemps=0
27
28 cd "$MHTMPDIR"
29
30
31 # check -help
32 if [ $has_mkstemps -eq 1 ]; then
33 cat >$expected <<-'EOF'
34 Usage: mkstemp [switches]
35 switches are:
36 -directory
37 -prefix
38 -suffix
39 -version
40 -help
41 EOF
42 else
43 cat >$expected <<-'EOF'
44 Usage: mkstemp [switches]
45 switches are:
46 -directory
47 -prefix
48 -version
49 -help
50 EOF
51 fi
52
53 #### Skip nmh intro text.
54 run_prog $mkstemp -h | sed '/^$/,$d' >"$actual" 2>&1
55 check "$expected" "$actual"
56
57
58 # check -version
59 # Verified same behavior as compiled mhmail.
60 case `$mkstemp -v` in
61 mkstemp\ --*) ;;
62 * ) printf '%s: mkstemp -v generated unexpected output\n' "$0" >&2
63 failed=`expr ${failed:-0} + 1`;;
64 esac
65
66
67 # check with no switches
68 tmpfile=`$mkstemp`
69 if [ -f "$tmpfile" ]; then
70 rm "$tmpfile"
71 else
72 failed=1
73 fi
74
75
76 # check -directory
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' ''
82
83
84 # check -prefix
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' ''
90
91
92 if [ $has_mkstemps -eq 1 ]; then
93 # check -suffix
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' ''
99 fi
100
101
102 exit $failed