]> diplodocus.org Git - nmh/blob - test/mkstemp/test-mkstemp
Alter HasSuffixC()'s char * to be const.
[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 $mkstemp -help | grep suffix >/dev/null && has_mkstemps=1 || has_mkstemps=0
24
25 cd "$MHTMPDIR"
26
27
28 # check -help
29 if [ $has_mkstemps -eq 1 ]; then
30 cat >$expected <<-'EOF'
31 Usage: mkstemp [switches]
32 switches are:
33 -directory
34 -prefix
35 -suffix
36 -version
37 -help
38 EOF
39 else
40 cat >$expected <<-'EOF'
41 Usage: mkstemp [switches]
42 switches are:
43 -directory
44 -prefix
45 -version
46 -help
47 EOF
48 fi
49
50 #### Skip nmh intro text.
51 run_prog $mkstemp -h | sed '/^$/,$d' >"$actual" 2>&1
52 check "$expected" "$actual"
53
54
55 # check -version
56 # Verified same behavior as compiled mhmail.
57 case `$mkstemp -v` in
58 mkstemp\ --*) ;;
59 * ) printf '%s: mkstemp -v generated unexpected output\n' "$0" >&2
60 failed=`expr ${failed:-0} + 1`;;
61 esac
62
63
64 # check with no switches
65 tmpfile=`$mkstemp`
66 if [ -f "$tmpfile" ]; then
67 rm "$tmpfile"
68 else
69 failed=1
70 fi
71
72
73 # check -directory
74 tmpfile=`$mkstemp -directory "$MHTMPDIR"`
75 [ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
76 # Rely on exit status of grep to detect failure and terminate due to set -e:
77 check_tmpfile=`echo $tmpfile | grep "^$MHTMPDIR/......$" >/dev/null`
78 run_test 'eval echo $check_tmpfile' ''
79
80
81 # check -prefix
82 tmpfile=`$mkstemp -prefix mkstemptest`
83 [ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
84 # Rely on exit status of grep to detect failure and terminate due to set -e:
85 check_tmpfile=`echo $tmpfile | grep '^mkstemptest......$' >/dev/null`
86 run_test 'eval echo $check_tmpfile' ''
87
88
89 if [ $has_mkstemps -eq 1 ]; then
90 # check -suffix
91 tmpfile=`$mkstemp -suffix .txt`
92 [ -f "$tmpfile" ] && rm "$tmpfile" || failed=`expr ${failed:-0} + 1`
93 # Rely on exit status of grep to detect failure and terminate due to set -e:
94 check_tmpfile=`echo $tmpfile | grep '^......\.txt$' >/dev/null`
95 run_test 'eval echo $check_tmpfile' ''
96 fi
97
98
99 exit $failed