File: test-mkstemp

package info (click to toggle)
nmh 1.8-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 7,860 kB
  • sloc: ansic: 50,445; sh: 22,697; makefile: 1,138; lex: 740; perl: 509; yacc: 265
file content (108 lines) | stat: -rwxr-xr-x 2,451 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
##################################
#
# Test creation of temporary file.
#
##################################

set -e

if test -z "${MH_OBJ_DIR}"; then
    srcdir=`dirname "$0"`/../..
    MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
fi

. "$MH_OBJ_DIR/test/common.sh"

setup_test

expected="$MH_TEST_DIR"/$$.expected
actual="$MH_TEST_DIR"/$$.actual

mkstemp="${MH_LIBEXEC_DIR}/mkstemp"

check_exit '-eq 1' $mkstemp -

$mkstemp -help | grep suffix >/dev/null  &&  has_mkstemps=1  ||  has_mkstemps=0

cd "$MHTMPDIR"


# check -help
start_test "-help"
if [ $has_mkstemps -eq 1 ]; then
    cat >$expected <<-'EOF'
	Usage: mkstemp [switches]
	  switches are:
	  -directory
	  -prefix
	  -suffix
	  -version
	  -help
	EOF
else
    cat >$expected <<-'EOF'
	Usage: mkstemp [switches]
	  switches are:
	  -directory
	  -prefix
	  -version
	  -help
	EOF
fi

#### Skip nmh intro text.
run_prog $mkstemp -h 2>&1 | sed '/^$/,$d' >"$actual"
check "$expected" "$actual"


# check -version
start_test "-version"
# Verified same behavior as compiled mhmail.
case `$mkstemp -v` in
    mkstemp\ --*) ;;
    *           ) printf '%s: mkstemp -v generated unexpected output\n' "$0" >&2
                  failed=`expr ${failed:-0} + 1`;;
esac


# check with no switches
start_test "with no switches"
tmpfile=`$mkstemp`
if [ -f "$tmpfile" ]; then
    rm "$tmpfile"
else
    failed=1
fi


# check -directory
start_test "-directory"
tmpfile=`$mkstemp -directory "$MHTMPDIR"`
[ -f "$tmpfile" ]  &&  rm "$tmpfile"  ||  failed=`expr ${failed:-0} + 1`
# Rely on exit status of grep to detect failure and terminate due to set -e:
check_tmpfile=`echo $tmpfile | grep "^$MHTMPDIR/......$" >/dev/null`
run_test 'eval echo $check_tmpfile' ''


# check -prefix
start_test "-prefix"
tmpfile=`$mkstemp -prefix mkstemptest`
[ -f "$tmpfile" ]  &&  rm "$tmpfile"  ||  failed=`expr ${failed:-0} + 1`
# Rely on exit status of grep to detect failure and terminate due to set -e:
check_tmpfile=`echo $tmpfile | grep '^mkstemptest......$' >/dev/null`
run_test 'eval echo $check_tmpfile' ''


if [ $has_mkstemps -eq 1 ]; then
    # check -suffix
    tmpfile=`$mkstemp -suffix .txt`
    [ -f "$tmpfile" ]  &&  rm "$tmpfile"  ||  failed=`expr ${failed:-0} + 1`
    # Rely on exit status of grep to detect failure and terminate due to set -e:
    check_tmpfile=`echo $tmpfile | grep '^......\.txt$' >/dev/null`
    run_test 'eval echo $check_tmpfile' ''
fi


finish_test
exit $failed