File: test-dp

package info (click to toggle)
nmh 1.6-16
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 6,312 kB
  • ctags: 3,934
  • sloc: ansic: 48,921; sh: 16,427; makefile: 560; perl: 509; lex: 402; awk: 74
file content (115 lines) | stat: -rwxr-xr-x 2,194 bytes parent folder | download | duplicates (2)
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
109
110
111
112
113
114
115
#!/bin/sh
######################################################
#
# Test dp
#
######################################################

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

# Use proper program, likely not the first one on PATH.
dp="${MH_LIB_DIR}/dp"

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


# check -help
cat >"$expected" <<EOF
Usage: dp [switches] dates ...
  switches are:
  -form formatfile
  -(forma)t string
  -width columns
  -version
  -help
EOF

run_prog $dp -help >"$actual" 2>&1
check "$expected" "$actual"

# check -version
case `$dp -v` in
  dp\ --*) ;;
  *      ) printf '%s: dp -v generated unexpected output\n' "$0" >&2
           failed=`expr ${failed:-0} + 1`;;
esac

# check unknown switch
run_test "$dp -nonexistent" 'dp: -nonexistent unknown'

# check with no switches
run_test "$dp" 'dp: usage: dp [switches] dates ...'

# check with one valid date
cat >"$expected" <<EOF
Sun, 01 Jul 2012 00:00:00
EOF

run_prog $dp 'Sun Jul  1 2012' > "$actual" 2>&1
check "$expected" "$actual"

# check with two valid dates
cat >"$expected" <<EOF
Sun, 01 Jul 2012 00:00:00
Mon, 02 Jul 2012 00:00:00
EOF

run_prog $dp 'Sun Jul  1 2012' 'Mon Jul  2 2012' > "$actual" 2>&1
check "$expected" "$actual"

# check with invalid date
cat >"$expected" <<EOF
error: not a date
EOF

cat >"$expected_err" <<EOF
EOF

run_prog $dp 'not a date' > "$actual" 2> "$actual_err"
check "$expected" "$actual"
check "$expected_err" "$actual_err"

# check -form
form="${MH_TEST_DIR}/Mail/dp-form"
cat >"$form" <<'EOF'
%(day{text})
EOF

cat >"$expected" <<EOF
Sun
EOF

run_prog $dp -form "$form" 'Jul 1 2012' >$actual 2>&1
check $expected $actual
rm -f "$form"

# check -format
cat >"$expected" <<EOF
Sun
EOF

run_prog $dp -format '%(day{text})' 'Jul 1 2012' >$actual 2>&1
check $expected $actual

# check -width
cat >"$expected" <<EOF
Sun, 01 Jul 2012
EOF

run_prog $dp -width 17 'Sun Jul  1 2012' > "$actual" 2>&1
check "$expected" "$actual"


exit ${failed:-0}