]> git.ipfire.org Git - thirdparty/git.git/blame - t/t5100-mailinfo.sh
Merge branch 'js/trace2-cap-max-output-files'
[thirdparty/git.git] / t / t5100-mailinfo.sh
CommitLineData
4839c0b5
JH
1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
5be60078 6test_description='git mailinfo and git mailsplit test'
4839c0b5
JH
7
8. ./test-lib.sh
9
ee4d679f
KD
10DATA="$TEST_DIRECTORY/t5100"
11
4839c0b5 12test_expect_success 'split sample box' \
ee4d679f 13 'git mailsplit -o. "$DATA/sample.mbox" >last &&
fc7b076d 14 last=$(cat last) &&
4839c0b5 15 echo total is $last &&
6b4b013f 16 test $(cat last) = 18'
4839c0b5 17
017678b4
JH
18check_mailinfo () {
19 mail=$1 opt=$2
20 mo="$mail$opt"
ee4d679f
KD
21 git mailinfo -u $opt "msg$mo" "patch$mo" <"$mail" >"info$mo" &&
22 test_cmp "$DATA/msg$mo" "msg$mo" &&
23 test_cmp "$DATA/patch$mo" "patch$mo" &&
24 test_cmp "$DATA/info$mo" "info$mo"
017678b4
JH
25}
26
27
6ffd3ec8 28for mail in 00*
4839c0b5 29do
bfdbee98 30 test_expect_success "mailinfo $mail" '
ee4d679f
KD
31 check_mailinfo "$mail" "" &&
32 if test -f "$DATA/msg$mail--scissors"
017678b4 33 then
ee4d679f 34 check_mailinfo "$mail" --scissors
d25e5159 35 fi &&
ee4d679f 36 if test -f "$DATA/msg$mail--no-inbody-headers"
d25e5159 37 then
ee4d679f 38 check_mailinfo "$mail" --no-inbody-headers
8fb26872 39 fi &&
ee4d679f 40 if test -f "$DATA/msg$mail--message-id"
452dfbed 41 then
ee4d679f 42 check_mailinfo "$mail" --message-id
452dfbed 43 fi
bfdbee98 44 '
4839c0b5
JH
45done
46
c32815f9
KS
47
48test_expect_success 'split box with rfc2047 samples' \
49 'mkdir rfc2047 &&
ee4d679f 50 git mailsplit -orfc2047 "$DATA/rfc2047-samples.mbox" \
c32815f9 51 >rfc2047/last &&
fc7b076d 52 last=$(cat rfc2047/last) &&
c32815f9 53 echo total is $last &&
fc7b076d 54 test $(cat rfc2047/last) = 11'
c32815f9 55
6ffd3ec8 56for mail in rfc2047/00*
c32815f9
KS
57do
58 test_expect_success "mailinfo $mail" '
ee4d679f 59 git mailinfo -u "$mail-msg" "$mail-patch" <"$mail" >"$mail-info" &&
c32815f9 60 echo msg &&
ee4d679f 61 test_cmp "$DATA/empty" "$mail-msg" &&
c32815f9 62 echo patch &&
ee4d679f 63 test_cmp "$DATA/empty" "$mail-patch" &&
c32815f9 64 echo info &&
ee4d679f 65 test_cmp "$DATA/rfc2047-info-$(basename $mail)" "$mail-info"
c32815f9
KS
66 '
67done
68
cce8d6fd
JS
69test_expect_success 'respect NULs' '
70
ee4d679f
KD
71 git mailsplit -d3 -o. "$DATA/nul-plain" &&
72 test_cmp "$DATA/nul-plain" 001 &&
cce8d6fd 73 (cat 001 | git mailinfo msg patch) &&
3fb0459b 74 test_line_count = 4 patch
cce8d6fd
JS
75
76'
77
9aa23094
JH
78test_expect_success 'Preserve NULs out of MIME encoded message' '
79
ee4d679f
KD
80 git mailsplit -d5 -o. "$DATA/nul-b64.in" &&
81 test_cmp "$DATA/nul-b64.in" 00001 &&
9aa23094 82 git mailinfo msg patch <00001 &&
ee4d679f 83 test_cmp "$DATA/nul-b64.expect" patch
9aa23094
JH
84
85'
86
e9d7d10a
JK
87test_expect_success 'mailinfo on from header without name works' '
88
89 mkdir info-from &&
ee4d679f
KD
90 git mailsplit -oinfo-from "$DATA/info-from.in" &&
91 test_cmp "$DATA/info-from.in" info-from/0001 &&
e9d7d10a
JK
92 git mailinfo info-from/msg info-from/patch \
93 <info-from/0001 >info-from/out &&
ee4d679f 94 test_cmp "$DATA/info-from.expect" info-from/out
e9d7d10a
JK
95
96'
97
2da1f366
JK
98test_expect_success 'mailinfo finds headers after embedded From line' '
99 mkdir embed-from &&
ee4d679f
KD
100 git mailsplit -oembed-from "$DATA/embed-from.in" &&
101 test_cmp "$DATA/embed-from.in" embed-from/0001 &&
2da1f366
JK
102 git mailinfo embed-from/msg embed-from/patch \
103 <embed-from/0001 >embed-from/out &&
ee4d679f 104 test_cmp "$DATA/embed-from.expect" embed-from/out
2da1f366
JK
105'
106
107test_expect_success 'mailinfo on message with quoted >From' '
108 mkdir quoted-from &&
ee4d679f
KD
109 git mailsplit -oquoted-from "$DATA/quoted-from.in" &&
110 test_cmp "$DATA/quoted-from.in" quoted-from/0001 &&
2da1f366
JK
111 git mailinfo quoted-from/msg quoted-from/patch \
112 <quoted-from/0001 >quoted-from/out &&
ee4d679f 113 test_cmp "$DATA/quoted-from.expect" quoted-from/msg
2da1f366
JK
114'
115
c88098d7
EW
116test_expect_success 'mailinfo unescapes with --mboxrd' '
117 mkdir mboxrd &&
118 git mailsplit -omboxrd --mboxrd \
ee4d679f 119 "$DATA/sample.mboxrd" >last &&
c88098d7
EW
120 test x"$(cat last)" = x2 &&
121 for i in 0001 0002
122 do
123 git mailinfo mboxrd/msg mboxrd/patch \
124 <mboxrd/$i >mboxrd/out &&
ee4d679f 125 test_cmp "$DATA/${i}mboxrd" mboxrd/msg
c88098d7
EW
126 done &&
127 sp=" " &&
128 echo "From " >expect &&
129 echo "From " >>expect &&
130 echo >> expect &&
131 cat >sp <<-INPUT_END &&
132 From mboxrd Mon Sep 17 00:00:00 2001
133 From: trailing spacer <sp@example.com>
134 Subject: [PATCH] a commit with trailing space
135
136 From$sp
137 >From$sp
138
139 INPUT_END
140
141 git mailsplit -f2 -omboxrd --mboxrd <sp >last &&
142 test x"$(cat last)" = x1 &&
143 git mailinfo mboxrd/msg mboxrd/patch <mboxrd/0003 &&
144 test_cmp expect mboxrd/msg
145'
146
f357e5de
KD
147test_expect_success 'mailinfo handles rfc2822 quoted-string' '
148 mkdir quoted-string &&
149 git mailinfo /dev/null /dev/null <"$DATA/quoted-string.in" \
150 >quoted-string/info &&
151 test_cmp "$DATA/quoted-string.expect" quoted-string/info
152'
153
154test_expect_success 'mailinfo handles rfc2822 comment' '
155 mkdir comment &&
156 git mailinfo /dev/null /dev/null <"$DATA/comment.in" \
157 >comment/info &&
158 test_cmp "$DATA/comment.expect" comment/info
159'
160
3f0ec068
JH
161test_expect_success 'mailinfo with mailinfo.scissors config' '
162 test_config mailinfo.scissors true &&
163 (
164 mkdir sub &&
165 cd sub &&
166 git mailinfo ../msg0014.sc ../patch0014.sc <../0014 >../info0014.sc
167 ) &&
168 test_cmp "$DATA/msg0014--scissors" msg0014.sc &&
169 test_cmp "$DATA/patch0014--scissors" patch0014.sc &&
170 test_cmp "$DATA/info0014--scissors" info0014.sc
171'
172
173
ae52d57f
KM
174test_expect_success 'mailinfo no options' '
175 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
176 git mailinfo /dev/null /dev/null)" &&
177 test z"$subj" = z"Subject: message"
178'
179
180test_expect_success 'mailinfo -k' '
181 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
182 git mailinfo -k /dev/null /dev/null)" &&
183 test z"$subj" = z"Subject: [PATCH] [other] [PATCH] message"
184'
185
186test_expect_success 'mailinfo -b no [PATCH]' '
187 subj="$(echo "Subject: [other] message" |
188 git mailinfo -b /dev/null /dev/null)" &&
189 test z"$subj" = z"Subject: [other] message"
190'
191
192test_expect_success 'mailinfo -b leading [PATCH]' '
193 subj="$(echo "Subject: [PATCH] [other] message" |
194 git mailinfo -b /dev/null /dev/null)" &&
195 test z"$subj" = z"Subject: [other] message"
196'
197
198test_expect_success 'mailinfo -b double [PATCH]' '
199 subj="$(echo "Subject: [PATCH] [PATCH] message" |
200 git mailinfo -b /dev/null /dev/null)" &&
201 test z"$subj" = z"Subject: message"
202'
203
204test_expect_failure 'mailinfo -b trailing [PATCH]' '
205 subj="$(echo "Subject: [other] [PATCH] message" |
206 git mailinfo -b /dev/null /dev/null)" &&
207 test z"$subj" = z"Subject: [other] message"
208'
209
210test_expect_failure 'mailinfo -b separated double [PATCH]' '
211 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
212 git mailinfo -b /dev/null /dev/null)" &&
213 test z"$subj" = z"Subject: [other] message"
214'
215
4839c0b5 216test_done