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