From d3568a42bffc1cdbc361a1274432546fcc3821c6 Mon Sep 17 00:00:00 2001 From: Gavin Mak Date: Wed, 26 Apr 2023 22:32:49 +0000 Subject: [PATCH] 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 Commit-Queue: Gavin Mak --- presubmit_canned_checks.py | 6 +++++- tests/presubmit_canned_checks_test.py | 16 ++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/presubmit_canned_checks.py b/presubmit_canned_checks.py index 3f7ac0cddf..213ba33051 100644 --- a/presubmit_canned_checks.py +++ b/presubmit_canned_checks.py @@ -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): diff --git a/tests/presubmit_canned_checks_test.py b/tests/presubmit_canned_checks_test.py index a03e640a16..cee18da784 100644 --- a/tests/presubmit_canned_checks_test.py +++ b/tests/presubmit_canned_checks_test.py @@ -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'),