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