Hash :
e815afbf
Author :
Date :
2020-09-07T22:09:22
First pass at increasing inclusivity Link to the inclusivity rules https://source.android.com/setup/contribute/respectful-code Bug: b/162834212 Bug: chromium:1097198 Change-Id: Ied5a9e3879d72bff3f77ea6fcda9b82f30c32c2f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2396737 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Trevor Black <vantablack@google.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
#!/usr/bin/env python
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
angle_presubmit_utils_unittest.py: Top-level unittest script for ANGLE presubmit checks.
"""
import imp
import os
import unittest
from angle_presubmit_utils import *
def SetCWDToAngleFolder():
angle_folder = "angle"
cwd = os.path.dirname(os.path.abspath(__file__))
cwd = cwd.split(angle_folder)[0] + angle_folder
os.chdir(cwd)
SetCWDToAngleFolder()
PRESUBMIT = imp.load_source('PRESUBMIT', 'PRESUBMIT.py')
class CommitMessageFormattingCheckTest(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(CommitMessageFormattingCheckTest, self).__init__(*args, **kwargs)
self.output_api = OutputAPI_mock()
def run_check_commit_message_formatting(self, commit_msg):
input_api = InputAPI_mock(commit_msg)
return PRESUBMIT._CheckCommitMessageFormatting(input_api, self.output_api)
def test_correct_commit_message(self):
commit_msg = """a
b
Bug: angleproject:4662
Change-Id: I966c79d96175da9eee92ef6da20db50d488137b2
"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
def test_missing_description_body_and_description_summary(self):
commit_msg = """Change-Id: I966c79d96175da9eee92ef6da20db50d488137b2"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 1)
self.assertEqual(
errors[0],
self.output_api.PresubmitError(
"Commit 1:Please ensure that your" +
" description summary and description body are not blank."))
def test_missing_description_body(self):
commit_msg = """
a
b: d
c: e
"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
def test_missing_tag_paragraph(self):
commit_msg = """a
bd
efgh"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 1)
self.assertEqual(
errors[0],
self.output_api.PresubmitError(
"Commit 1:Please ensure that there are tags (e.g., Bug:, Test:) in your description."
))
def test_missing_tag_paragraph_and_description_body(self):
commit_msg = "a"
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 1)
self.assertEqual(
errors[0],
self.output_api.PresubmitError(
"Commit 1:Please ensure that there are tags (e.g., Bug:, Test:) in your description."
))
def test_missing_blank_line_between_description_summary_and_description_body(self):
commit_msg = """a
b
Change-Id: I925cdb45779a9cdebe4e14f9e81e4211ade37c12"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 1)
self.assertEqual(errors[0], self.output_api.PresubmitError(
"Commit 1:Please ensure the summary is only 1 line and there is 1 blank line" + \
" between the summary and description body."))
def test_missing_blank_line_between_description_body_and_tags_paragraph(self):
commit_msg = """a
b
Change-Id: I925cdb45779a9cdebe4e14f9e81e4211ade37c12"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
def test_multiple_blank_lines_before_and_after_commit_message(self):
commit_msg = """
a
b
Change-Id: I925cdb45779a9cdebe4e14f9e81e4211ade37c12
"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
def test_newlines_within_description_body(self):
commit_msg = """a
b
d
e
for
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
# Summary description in warning threshold(at 65 characters)
def test_summmary_description_in_warning_thresholds(self):
commit_msg = """aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
b
Change-Id: I925cdb45779a9cdebe4e14f9e81e4211ade37c12
"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 1)
self.assertEqual(
errors[0],
self.output_api.PresubmitPromptWarning(
"Commit 1:Your description summary should be on one line of 64 or less characters."
))
# Summary description in error threshold(at 71 characters)
def test_summary_description_in_error_threshold(self):
commit_msg = """aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
b
Change-Id: I925cdb45779a9cdebe4e14f9e81e4211ade37c12"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 1)
self.assertEqual(
errors[0],
self.output_api.PresubmitError(
"Commit 1:Please ensure that your description summary is on one line of 64 or less characters."
))
def test_description_body_exceeds_line_count_limit(self):
commit_msg = """a
bbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 2)
self.assertEqual(
errors[0],
self.output_api.PresubmitError(
"Commit 1:Please ensure that there exists only 1 blank line between tags and description body."
))
self.assertEqual(
errors[1],
self.output_api.PresubmitError("""Commit 1:Line 3 is too long.
"bbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
Please wrap it to 72 characters. Lines without spaces or lines starting with 4 spaces are exempt."""
))
def test_description_body_exceeds_line_count_limit_but_with_4_spaces_prefix(self):
commit_msg = """a
cc
dddd
bbbbbbbbbbbbbbbbbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
def test_description_body_exceeds_line_count_limit_but_without_space(self):
commit_msg = """a
cc
dddd
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
a: d"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
def test_tabs_in_commit_message(self):
commit_msg = """ a
bbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 1)
self.assertEqual(
errors[0],
self.output_api.PresubmitError("Commit 1:Tabs are not allowed in commit message."))
def test_allowlist_revert(self):
commit_msg = """Revert "sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssa
bbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
def test_allowlist_roll(self):
commit_msg = """Roll sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssadd
bbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
def test_allowlist_reland(self):
commit_msg = """Reland sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssadd
bbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
def test_multiple_commits_with_errors_in_multiple_commits(self):
commit_msg = """a
bbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b
a
cccccccccccccccccccccccccccccc cccccccccccccccccccccccccccccccccccccccccccc
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 2)
self.assertEqual(
errors[0],
self.output_api.PresubmitError("""Commit 2:Line 3 is too long.
"bbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
Please wrap it to 72 characters. Lines without spaces or lines starting with 4 spaces are exempt."""
))
self.assertEqual(
errors[1],
self.output_api.PresubmitError("""Commit 1:Line 4 is too long.
"cccccccccccccccccccccccccccccc cccccccccccccccccccccccccccccccccccccccccccc"
Please wrap it to 72 characters. Lines without spaces or lines starting with 4 spaces are exempt."""
))
def test_multiple_commits_with_error_in_one_commit(self):
commit_msg = """a
bbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b
Roll sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssadd
bbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 1)
self.assertEqual(
errors[0],
self.output_api.PresubmitError("""Commit 2:Line 3 is too long.
"bbbbbbbb bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
Please wrap it to 72 characters. Lines without spaces or lines starting with 4 spaces are exempt."""
))
def test_multiple_commits_with_no_error(self):
commit_msg = """Reland sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssadd
bbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b
Roll sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssadd
bbbbbbbbbbbbbbbbbbbb
Change-Id: I443c36aaa8956c20da1abddf7aea613659e2cd5b"""
errors = self.run_check_commit_message_formatting(commit_msg)
self.assertEqual(len(errors), 0)
if __name__ == '__main__':
unittest.main()