Handle windows paths correctly in CheckInclusiveLanguage

Exclude file paths always use forward slash but tests currently change
based on which OS is running them, so this bug never got caught.

Bug: 1440473
Change-Id: Iafd7e57c2dedd0c9990a1a620abd3ae38631a4f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4481518
Reviewed-by: Sean McCullough <seanmccullough@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
changes/18/4481518/4
Gavin Mak 3 years ago committed by LUCI CQ
parent f7b9e70a2e
commit d3568a42bf

@ -2130,11 +2130,15 @@ def CheckInclusiveLanguage(input_api, output_api,
]
# Note that this matches exact path prefixes, and does not match
# subdirectories. Only files directly in an exlcluded path will
# subdirectories. Only files directly in an excluded path will
# match.
def IsExcludedFile(affected_file, excluded_paths):
local_dir = input_api.os_path.dirname(affected_file.LocalPath())
# Excluded paths use forward slashes.
if input_api.platform == 'win32':
local_dir = local_dir.replace('\\', '/')
return local_dir in excluded_paths
def CheckForMatch(affected_file, line_num, line, term, message, error):

@ -29,8 +29,8 @@ class InclusiveLanguageCheckTest(unittest.TestCase):
MockFile(
os.path.normpath(
'infra/inclusive_language_presubmit_exempt_dirs.txt'), [
os.path.normpath('some/dir') + ' 2 1',
os.path.normpath('some/other/dir') + ' 2 1',
'some/dir 2 1',
'some/other/dir 2 1',
]),
MockFile(
os.path.normpath('some/ios/file.mm'),
@ -133,8 +133,8 @@ class InclusiveLanguageCheckTest(unittest.TestCase):
MockFile(
os.path.normpath(
'infra/inclusive_language_presubmit_exempt_dirs.txt'), [
os.path.normpath('some/ios') + ' 2 1',
os.path.normpath('some/other/dir') + ' 2 1',
'some/ios 2 1',
'some/other/dir 2 1',
]),
MockFile(
os.path.normpath('some/ios/file.mm'),
@ -186,8 +186,8 @@ class InclusiveLanguageCheckTest(unittest.TestCase):
MockFile(
os.path.normpath(
'infra/inclusive_language_presubmit_exempt_dirs.txt'), [
os.path.normpath('some/dir') + ' 2 1',
os.path.normpath('some/other/dir') + ' 2 1',
'some/dir 2 1',
'some/other/dir 2 1',
]),
MockFile(
os.path.normpath('some/ios/file.mm'),
@ -249,8 +249,8 @@ class InclusiveLanguageCheckTest(unittest.TestCase):
MockFile(
os.path.normpath(
'infra/inclusive_language_presubmit_exempt_dirs.txt'), [
os.path.normpath('.') + ' 2 1',
os.path.normpath('some/other/dir') + ' 2 1',
'. 2 1',
'some/other/dir 2 1',
]),
MockFile(
os.path.normpath('presubmit_canned_checks_test.py'),

Loading…
Cancel
Save