Update tools and configurations after renaming Source/WebKit to Source/WebKitLegacy.
[WebKit-https.git] / Tools / Scripts / webkitpy / style / checkers / changelog_unittest.py
1 # Copyright (C) 2010 Apple Inc. All rights reserved.
2 # Copyright (C) 2011 Patrick Gansterer <paroga@paroga.com>
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7 # 1.  Redistributions of source code must retain the above copyright
8 #     notice, this list of conditions and the following disclaimer.
9 # 2.  Redistributions in binary form must reproduce the above copyright
10 #     notice, this list of conditions and the following disclaimer in the
11 #     documentation and/or other materials provided with the distribution.
12 #
13 # THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND
14 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 # DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR
17 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
20 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
21 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23
24 """Unit test for changelog.py."""
25
26 import changelog
27 import unittest
28
29
30 class ChangeLogCheckerTest(unittest.TestCase):
31     """Tests ChangeLogChecker class."""
32
33     def assert_no_error(self, lines_to_check, changelog_data):
34         def handle_style_error(line_number, category, confidence, message):
35             self.fail('Unexpected error: %d %s %d %s for\n%s' % (line_number, category, confidence, message, changelog_data))
36         self.lines_to_check = set(lines_to_check)
37         checker = changelog.ChangeLogChecker('ChangeLog', handle_style_error, self.mock_should_line_be_checked)
38         checker.check(changelog_data.split('\n'))
39
40     def assert_error(self, expected_line_number, lines_to_check, expected_category, changelog_data):
41         self.had_error = False
42
43         def handle_style_error(line_number, category, confidence, message):
44             self.had_error = True
45             self.assertEqual(expected_line_number, line_number)
46             self.assertEqual(expected_category, category)
47         self.lines_to_check = set(lines_to_check)
48         checker = changelog.ChangeLogChecker('ChangeLog', handle_style_error, self.mock_should_line_be_checked)
49         checker.check(changelog_data.split('\n'))
50         self.assertTrue(self.had_error)
51
52     def mock_handle_style_error(self):
53         pass
54
55     def mock_should_line_be_checked(self, line_number):
56         return line_number in self.lines_to_check
57
58     def test_init(self):
59         checker = changelog.ChangeLogChecker('ChangeLog', self.mock_handle_style_error, self.mock_should_line_be_checked)
60         self.assertEqual(checker.file_path, 'ChangeLog')
61         self.assertEqual(checker.handle_style_error, self.mock_handle_style_error)
62         self.assertEqual(checker.should_line_be_checked, self.mock_should_line_be_checked)
63
64     def test_missing_bug_number(self):
65         self.assert_error(1, range(1, 20), 'changelog/bugnumber',
66                           '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
67                           '\n'
68                           '        Example bug\n')
69         self.assert_error(1, range(1, 20), 'changelog/bugnumber',
70                           '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
71                           '\n'
72                           '        Example bug\n'
73                           '        http://bugs.webkit.org/show_bug.cgi?id=\n')
74         self.assert_error(1, range(1, 20), 'changelog/bugnumber',
75                           '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
76                           '\n'
77                           '        Example bug\n'
78                           '        https://bugs.webkit.org/show_bug.cgi?id=\n')
79         self.assert_error(1, range(1, 20), 'changelog/bugnumber',
80                           '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
81                           '\n'
82                           '        Example bug\n'
83                           '        http://webkit.org/b/\n')
84         self.assert_error(1, range(1, 20), 'changelog/bugnumber',
85                           '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
86                           '\n'
87                           '        Example bug'
88                           '\n'
89                           '        http://trac.webkit.org/changeset/12345\n')
90         self.assert_error(2, range(2, 5), 'changelog/bugnumber',
91                           '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
92                           '        Example bug\n'
93                           '        https://bugs.webkit.org/show_bug.cgi\n'
94                           '\n'
95                           '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
96                           '        Another change\n')
97         self.assert_error(2, range(2, 6), 'changelog/bugnumber',
98                           '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
99                           '        Example bug\n'
100                           '        More text about bug.\n'
101                           '\n'
102                           '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
103                           '\n'
104                           '        No bug in this change.\n')
105
106     def test_file_descriptions(self):
107         self.assert_error(5, range(1, 20), 'changelog/filechangedescriptionwhitespace',
108                           '2011-01-01 Dmitry Lomov  <dslomov@google.com>\n'
109                           '        ExampleBug\n'
110                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
111                           '\n'
112                           '        *  Source/Tools/random-script.py:Fixed')
113         self.assert_error(6, range(1, 20), 'changelog/filechangedescriptionwhitespace',
114                           '2011-01-01 Dmitry Lomov  <dslomov@google.com>\n'
115                           '        ExampleBug\n'
116                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
117                           '\n'
118                           '        *  Source/Tools/another-file: Done\n'
119                           '        *  Source/Tools/random-script.py:Fixed\n'
120                           '        *  Source/Tools/one-morefile:\n')
121
122     def test_no_new_tests(self):
123         self.assert_error(5, range(1, 20), 'changelog/nonewtests',
124                           '2011-01-01 Dmitry Lomov  <dslomov@google.com>\n'
125                           '        ExampleBug\n'
126                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
127                           '\n'
128                           '        No new tests (OOPS!).\n'
129                           '        *  Source/Tools/random-script.py: Fixed')
130
131     def test_no_error(self):
132         self.assert_no_error([],
133                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
134                              '\n'
135                              '        Example ChangeLog entry out of range\n'
136                              '        http://example.com/\n')
137         self.assert_no_error([],
138                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
139                              '\n'
140                              '        Example bug\n'
141                              '        http://bugs.webkit.org/show_bug.cgi?id=12345\n')
142         self.assert_no_error(range(1, 20),
143                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
144                              '\n'
145                              '        Example bug\n'
146                              '        http://bugs.webkit.org/show_bug.cgi?id=12345\n')
147         self.assert_no_error(range(1, 20),
148                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
149                              '\n'
150                              '        Example bug\n'
151                              '        https://bugs.webkit.org/show_bug.cgi?id=12345\n')
152         self.assert_no_error(range(1, 20),
153                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
154                              '\n'
155                              '        Example bug\n'
156                              '        http://webkit.org/b/12345\n')
157         self.assert_no_error(range(1, 20),
158                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
159                              '\n'
160                              '        Unreview build fix for r12345.\n')
161         self.assert_no_error(range(1, 20),
162                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
163                              '\n'
164                              '        Fix build after a bad change.\n')
165         self.assert_no_error(range(1, 20),
166                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
167                              '\n'
168                              '        Fix example port build.\n')
169         self.assert_no_error(range(2, 6),
170                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
171                              '        Example bug\n'
172                              '        https://bugs.webkit.org/show_bug.cgi?id=12345\n'
173                              '\n'
174                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
175                              '        No bug here!\n')
176         self.assert_no_error(range(1, 20),
177                              '2011-01-01  Patrick Gansterer  <paroga@paroga.com>\n'
178                              '        Example bug\n'
179                              '        https://bugs.webkit.org/show_bug.cgi?id=12345\n'
180                              '        * Source/WebKitLegacy/foo.cpp:    \n'
181                              '        * Source/WebKitLegacy/bar.cpp:\n'
182                              '        * Source/WebKitLegacy/foobar.cpp: Description\n')
183
184     def test_unwanted_security_terms(self):
185         self.assert_error(5, range(1, 20), 'changelog/unwantedsecurityterms',
186                           '2016-11-11 Bogus Person <bperson@example.com>\n'
187                           '        ExampleBug\n'
188                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
189                           '\n'
190                           '        A buffer overflow existed in code.\n')
191         self.assert_error(9, range(1, 20), 'changelog/unwantedsecurityterms',
192                           '2016-11-11 Bogus Person <bperson@example.com>\n'
193                           '        ExampleBug\n'
194                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
195                           '\n'
196                           '        This patch addresses a great number of issues.\n'
197                           '        Therefore there is a lot to say here about a great\n'
198                           '        many things such as the weather, the latest and\n'
199                           '        greatest in sports, and the mood of fiction\n'
200                           '        characters. Anyway the patch fixes a use after\n'
201                           '        free which is not good. Or rather, it is good\n'
202                           '        that it is fixed but not good that it existed.\n')
203         self.assert_error(5, range(1, 20), 'changelog/unwantedsecurityterms',
204                           '2016-11-11 Bogus Person <bperson@example.com>\n'
205                           '        ExampleBug\n'
206                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
207                           '\n'
208                           '        This patch addresses a pretty bad buffer\n'
209                           '        overflow in\n')
210         self.assert_error(2, range(1, 20), 'changelog/unwantedsecurityterms',
211                           '2016-11-11 Bogus Person <bperson@example.com>\n'
212                           '        Fix use after free\n'
213                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
214                           '\n'
215                           '        A good fix.\n')
216         self.assert_error(5, range(1, 20), 'changelog/unwantedsecurityterms',
217                           '2016-11-11 Bogus Person <bperson@example.com>\n'
218                           '        ExampleBug\n'
219                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
220                           '\n'
221                           '        Bug found through fuzzing.\n')
222         self.assert_error(11, range(1, 20), 'changelog/unwantedsecurityterms',
223                           '2016-11-11 Bogus Person <bperson@example.com>\n'
224                           '        ExampleBug\n'
225                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
226                           '\n'
227                           '        Bug found through testing.\n'
228                           '\n'
229                           '        Several new tests added.\n'
230                           '\n'
231                           '        * Source/WebKitLegacy/foo.cpp:    \n'
232                           '        * Source/WebKitLegacy/bar.cpp:\n'
233                           '        * Source/WebKitLegacy/foobar.cpp: Vulnerabilities fixed\n')
234         self.assert_error(5, range(1, 20), 'changelog/unwantedsecurityterms',
235                           '2016-11-11 Bogus Person <bperson@example.com>\n'
236                           '        ExampleBug with several security sensitive terms in change log\n'
237                           '        http://bugs.webkit.org/show_bug.cgi?id=12345\n'
238                           '\n'
239                           '        Use-after-free found through testing.\n'
240                           '\n'
241                           '        Several new tests added to check double free.\n'
242                           '\n'
243                           '        * Source/WebKitLegacy/foo.cpp:    \n'
244                           '        * Source/WebKitLegacy/bar.cpp:\n'
245                           '        * Source/WebKitLegacy/foobar.cpp: memory CORRUPTION fixed\n')