]>
git.ipfire.org Git - thirdparty/gcc.git/blob - contrib/gcc-changelog/test_email.py
92bcb89ed8b1951c172469fa18b2e7fca354c716
3 # This file is part of GCC.
5 # GCC is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation; either version 3, or (at your option) any later
10 # GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 # You should have received a copy of the GNU General Public License
16 # along with GCC; see the file COPYING3. If not see
17 # <http://www.gnu.org/licenses/>. */
23 from git_email
import GitEmail
26 script_path
= os
.path
.dirname(os
.path
.realpath(__file__
))
29 class TestGccChangelog(unittest
.TestCase
):
36 lines
= open(os
.path
.join(script_path
, 'test_patches.txt')).read()
37 for line
in lines
.split('\n'):
38 if line
.startswith('==='):
40 self
.patches
[filename
] = patch_lines
41 filename
= line
.split(' ')[1]
44 patch_lines
.append(line
)
46 self
.patches
[filename
] = patch_lines
50 assert t
.endswith('.patch')
53 def get_git_email(self
, filename
, strict
=False):
54 with tempfile
.NamedTemporaryFile(mode
='w+', suffix
='.patch',
56 f
.write('\n'.join(self
.patches
[filename
]))
57 self
.temps
.append(f
.name
)
58 return GitEmail(f
.name
, strict
)
60 def from_patch_glob(self
, name
, strict
=False):
61 files
= [f
for f
in self
.patches
.keys() if f
.startswith(name
)]
62 assert len(files
) == 1
63 return self
.get_git_email(files
[0], strict
)
65 def test_simple_patch_format(self
):
66 email
= self
.get_git_email('0577-aarch64-Add-an-and.patch')
67 assert not email
.errors
68 assert len(email
.changelog_entries
) == 2
69 entry
= email
.changelog_entries
[0]
70 assert (entry
.author_lines
==
71 [('Richard Sandiford <richard.sandiford@arm.com>',
73 assert len(entry
.authors
) == 1
74 assert (entry
.authors
[0]
75 == 'Richard Sandiford <richard.sandiford@arm.com>')
76 assert entry
.folder
== 'gcc'
77 assert entry
.prs
== ['PR target/87763']
78 assert len(entry
.files
) == 3
79 assert entry
.files
[0] == 'config/aarch64/aarch64-protos.h'
81 def test_daily_bump(self
):
82 email
= self
.get_git_email('0085-Daily-bump.patch')
83 assert not email
.errors
84 assert not email
.changelog_entries
86 def test_deduce_changelog_entries(self
):
87 email
= self
.from_patch_glob('0040')
88 assert len(email
.changelog_entries
) == 2
89 assert email
.changelog_entries
[0].folder
== 'gcc/cp'
90 assert email
.changelog_entries
[0].prs
== ['PR c++/90916']
91 assert email
.changelog_entries
[0].files
== ['pt.c']
92 # this one is added automatically
93 assert email
.changelog_entries
[1].folder
== 'gcc/testsuite'
95 def test_only_changelog_updated(self
):
96 email
= self
.from_patch_glob('0129')
97 assert not email
.errors
98 assert not email
.changelog_entries
100 def test_wrong_mentioned_filename(self
):
101 email
= self
.from_patch_glob('0096')
103 err
= email
.errors
[0]
104 assert err
.message
== 'file not changed in a patch'
105 assert err
.line
== 'gcc/testsuite/gcc.target/aarch64/' \
106 'advsimd-intrinsics/vdot-compile-3-1.c'
108 def test_missing_tab(self
):
109 email
= self
.from_patch_glob('0031')
110 assert len(email
.errors
) == 2
111 err
= email
.errors
[0]
112 assert err
.message
== 'line should start with a tab'
113 assert err
.line
== ' * cfgloopanal.c (average_num_loop_insns): ' \
114 'Free bbs when early'
116 def test_leading_changelog_format(self
):
117 email
= self
.from_patch_glob('0184')
118 assert len(email
.errors
) == 4
119 assert email
.errors
[0].line
== 'gcc/c-family/c-cppbuiltins.c'
120 assert email
.errors
[2].line
== 'gcc/c-family/c-cppbuiltin.c'
122 def test_cannot_deduce_no_blank_line(self
):
123 email
= self
.from_patch_glob('0334')
124 assert len(email
.errors
) == 1
125 assert len(email
.changelog_entries
) == 1
126 assert email
.changelog_entries
[0].folder
is None
128 def test_author_lines(self
):
129 email
= self
.from_patch_glob('0814')
130 assert not email
.errors
131 assert (email
.changelog_entries
[0].author_lines
==
132 [('Martin Jambor <mjambor@suse.cz>', '2020-02-19')])
134 def test_multiple_authors_and_prs(self
):
135 email
= self
.from_patch_glob('0735')
136 assert len(email
.changelog_entries
) == 1
137 entry
= email
.changelog_entries
[0]
138 assert len(entry
.author_lines
) == 2
139 assert len(entry
.authors
) == 2
140 assert (entry
.author_lines
[1] ==
141 ('Bernd Edlinger <bernd.edlinger@hotmail.de>', None))
143 def test_multiple_prs(self
):
144 email
= self
.from_patch_glob('1699')
145 assert len(email
.changelog_entries
) == 2
146 assert len(email
.changelog_entries
[0].prs
) == 2
148 def test_missing_PR_component(self
):
149 email
= self
.from_patch_glob('0735')
150 assert len(email
.errors
) == 1
151 assert email
.errors
[0].message
== 'missing PR component'
153 def test_invalid_PR_component(self
):
154 email
= self
.from_patch_glob('0198')
155 assert len(email
.errors
) == 1
156 assert email
.errors
[0].message
== 'invalid PR component'
158 def test_additional_author_list(self
):
159 email
= self
.from_patch_glob('0342')
160 assert (email
.errors
[1].message
== 'additional author must prepend '
161 'with tab and 4 spaces')
163 def test_trailing_whitespaces(self
):
164 email
= self
.get_git_email('trailing-whitespaces.patch')
165 assert len(email
.errors
) == 3
167 def test_space_after_asterisk(self
):
168 email
= self
.from_patch_glob('1999')
169 assert len(email
.errors
) == 1
170 assert email
.errors
[0].message
== 'one space should follow asterisk'
172 def test_long_lines(self
):
173 email
= self
.get_git_email('long-lines.patch')
174 assert len(email
.errors
) == 1
175 assert email
.errors
[0].message
== 'line limit exceeds 100 characters'
177 def test_new_files(self
):
178 email
= self
.from_patch_glob('0030')
179 assert not email
.errors
181 def test_wrong_changelog_location(self
):
182 email
= self
.from_patch_glob('0043')
183 assert len(email
.errors
) == 2
184 assert (email
.errors
[0].message
==
185 'wrong ChangeLog location "gcc", should be "gcc/testsuite"')
187 def test_single_author_name(self
):
188 email
= self
.from_patch_glob('1975')
189 assert len(email
.changelog_entries
) == 2
190 assert len(email
.changelog_entries
[0].author_lines
) == 1
191 assert len(email
.changelog_entries
[1].author_lines
) == 1
193 def test_bad_first_line(self
):
194 email
= self
.from_patch_glob('0413')
195 assert len(email
.errors
) == 1
197 def test_co_authored_by(self
):
198 email
= self
.from_patch_glob('1850')
199 assert email
.co_authors
== ['Jakub Jelinek <jakub@redhat.com>']
200 output_entries
= list(email
.to_changelog_entries())
201 assert len(output_entries
) == 2
202 ent0
= output_entries
[0]
203 assert ent0
[1].startswith('2020-04-16 Martin Liska '
204 '<mliska@suse.cz>\n\t'
205 ' Jakub Jelinek <jakub@redhat.com>')
207 def test_multiple_co_author_formats(self
):
208 email
= self
.get_git_email('co-authored-by.patch')
209 assert len(email
.co_authors
) == 3
210 assert email
.co_authors
[0] == 'Jakub Jelinek <jakub@redhat.com>'
211 assert email
.co_authors
[1] == 'John Miller <jm@example.com>'
212 assert email
.co_authors
[2] == 'John Miller2 <jm2@example.com>'
214 def test_new_file_added_entry(self
):
215 email
= self
.from_patch_glob('1957')
216 output_entries
= list(email
.to_changelog_entries())
217 assert len(output_entries
) == 2
218 needle
= ('\t* g++.dg/cpp2a/lambda-generic-variadic20.C'
220 assert output_entries
[1][1].endswith(needle
)
221 assert email
.changelog_entries
[1].prs
== ['PR c++/94546']
223 def test_global_pr_entry(self
):
224 email
= self
.from_patch_glob('2004')
225 assert not email
.errors
226 assert email
.changelog_entries
[0].prs
== ['PR other/94629']
228 def test_unique_prs(self
):
229 email
= self
.get_git_email('pr-check1.patch')
230 assert not email
.errors
231 assert email
.changelog_entries
[0].prs
== ['PR ipa/12345']
232 assert email
.changelog_entries
[1].prs
== []
234 def test_multiple_prs_not_added(self
):
235 email
= self
.from_patch_glob('0001-Add-patch_are')
236 assert not email
.errors
237 assert email
.changelog_entries
[0].prs
== ['PR target/93492']
238 assert email
.changelog_entries
[1].prs
== ['PR target/12345']
239 assert email
.changelog_entries
[2].prs
== []
240 assert email
.changelog_entries
[2].folder
== 'gcc/testsuite'
242 def test_strict_mode(self
):
243 email
= self
.from_patch_glob('0001-Add-patch_are',
245 msg
= 'ChangeLog, DATESTAMP, BASE-VER and DEV-PHASE updates should ' \
246 'be done separately from normal commits'
247 assert email
.errors
[0].message
== msg
249 def test_strict_mode_normal_patch(self
):
250 email
= self
.get_git_email('0001-Just-test-it.patch', True)
251 assert not email
.errors
253 def test_strict_mode_datestamp_only(self
):
254 email
= self
.get_git_email('0002-Bump-date.patch', True)
255 assert not email
.errors
257 def test_wrong_changelog_entry(self
):
258 email
= self
.from_patch_glob('0020-IPA-Avoid')
259 assert (email
.errors
[0].message
260 == 'first line should start with a tab, asterisk and space')
262 def test_cherry_pick_format(self
):
263 email
= self
.from_patch_glob('0001-c-Alias.patch')
264 assert not email
.errors
266 def test_signatures(self
):
267 email
= self
.from_patch_glob('0001-RISC-V-Make-unique.patch')
268 assert not email
.errors
269 assert len(email
.changelog_entries
) == 1