]> git.phdru.name Git - mimedecode.git/blob - test/test_all
df65454df9050d52c121c78a67a7c7bac33ba7fe
[mimedecode.git] / test / test_all
1 #! /bin/sh
2
3 cd "`dirname \"$0\"`" &&
4 rm -rf save tmp &&
5 mkdir tmp || exit 1
6
7 LC_CTYPE=c.UTF-8 &&
8 export LC_CTYPE &&
9
10 MAILCAPS="`pwd`"/.mailcap &&
11 export MAILCAPS &&
12
13 : ${PYTHON:=python}
14 RC=0
15
16 if [ `$PYTHON -c "import sys; print(sys.version[0])"` -eq 2 ]; then
17    PY3=NO
18 else
19    PY3=YES
20 fi
21
22 test1() {
23    infile="$1"
24    shift
25    expfile="$1"
26    if [ $PY3 = YES -a -f expected/"$expfile"-py3 ]; then
27       expfile="$expfile"-py3
28    fi
29    shift
30
31    $PYTHON ../mimedecode.py -H test -f utf-8 "$@" input/"$infile" >tmp/"$expfile" || return 1
32    if cmp -s expected/"$expfile" tmp/"$expfile"; then
33       rm tmp/"$expfile" && return 0 || return 1
34    else
35       diff --text expected/"$expfile" tmp/"$expfile" >tmp/"$expfile".diff
36       return 1
37    fi
38 }
39
40 test_file() {
41    echo -n "$2 "
42    if test1 "$@"; then
43       echo "ok"
44    else
45       echo "fail"
46       RC=1
47    fi
48 }
49
50 for f in input/*.txt; do
51    n="`basename \"$f\"`"
52    test_file "$n" "$n"
53 done
54
55 test_file msg_03.txt msg_03-1.txt -D -d From,To,Subject
56 test_file msg_03.txt msg_03-1.txt -d '*,-cc'
57 test_file msg_03.txt msg_03-1.txt -d \*,From,To,Subject,-cc
58 test_file msg_15.txt msg_15-1.txt -b text/html
59 test_file msg_15.txt msg_15-2.txt -i text/html
60 test_file msg_22.txt msg_22.txt -P -p Content-Type,Content-Disposition:name,filename
61 test_file msg_22.txt msg_22.txt -P -p \*:name,filename
62 test_file msg_22.txt msg_22.txt -P -p Content-Type,Content-Disposition:\*
63 test_file msg_22.txt msg_22.txt -P -p '*,-Content-Id:*,-x-mac-type'
64 test_file msg_22.txt msg_22-1.txt -r content-id
65 test_file msg_16.txt msg_16-1.txt -r Received,List-Help,List-Post,List-Subscribe,List-Id,List-Unsubscribe,List-Archive
66 test_file msg_16.txt msg_16-2.txt -r \*,-mime-version,-content-type
67 test_file msg_29.txt msg_29-1.txt -R Content-Type:title
68 test_file msg_18.txt msg_18-1.txt -R X-Foobar-Spoink-Defrobnit:\*
69 test_file msg_01.txt msg_01-1.txt --set-header=X-Test:set
70 test_file msg_01.txt msg_01-2.txt --set-header=X-Test:set --set-param=X-Test:test:set
71 test_file msg_02.txt msg_02.txt --set-param=X-Test:test:set
72 test_file msg_02.txt msg_02-1.txt --set-param=X-Mailer:test=set
73 test_file msg_02.txt msg_02-1.txt --set-param=X-Mailer:test:set
74 test_file msg_13.txt msg_13-1.txt -B '*/*'
75 test_file msg_13.txt msg_13.txt -t 'text/*' -b 'image/*' -B '*/*'
76 test_file msg_36.txt msg_36-1.txt -i multipart/alternative
77 test_file msg_36.txt msg_36-2.txt -I multipart/alternative
78
79 # Test --save-*
80 test2() {
81    infile="$1"
82    shift
83    expfile="$1"
84    shift
85    savefile="$1"
86    shift
87    expsavefile="$1"
88    shift
89
90    test_file "$infile" "$expfile" -O save "$@"
91
92    if cmp -s expected-save/"$expsavefile" save/"$savefile"; then
93       rm save/"$savefile" && return 0 || return 1
94    else
95       return 1
96    fi
97 }
98
99 test_save() {
100    if test2 "$@"; then
101       echo "    save: ok"
102    else
103       echo "    save: fail"
104       RC=1
105    fi
106 }
107
108 test_save msg_07.txt msg_07.txt 1-dingusfish.gif msg_07-1.txt --save-headers image/gif
109 test_save msg_07.txt msg_07.txt 1-dingusfish.gif msg_07-2.txt --save-body image/gif
110 test_save msg_07.txt msg_07.txt 1-dingusfish.gif msg_07-3.txt --save-message image/gif
111 test_save msg_07-1.txt msg_07-1.txt 1-dingusfish.gif msg_07-4.txt --save-message image/gif
112
113 test_save msg_07.txt msg_07.txt 1.dig msg_07-5.txt --save-headers multipart/mixed
114 test_save msg_07.txt msg_07.txt 1.dig msg_07-6.txt --save-body multipart/mixed
115 test_save msg_07.txt msg_07.txt 1.dig msg_07-7.txt --save-message multipart/mixed
116
117 echo
118
119 if [ "$RC" -eq 0 ]; then
120    echo "All tests passed!"
121    rmdir save tmp
122 else
123    echo "ERRORS!"
124 fi
125
126 exit $RC