Skip to content

Commit 15750a0

Browse files
authored
[clang-tidy] Use --match-full-lines instead of --strict-whitespace in check_clang_tidy (#133756)
See Discourse post here: https://discourse.llvm.org/t/rfc-using-match-full-lines-in-clang-tidy-tests/85553 I've added `--match-partial-fixes` to all tests that were failing, unless I noticed the fix was quick and trivial.
1 parent 9222607 commit 15750a0

File tree

97 files changed

+164
-146
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+164
-146
lines changed

clang-tools-extra/docs/ReleaseNotes.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ Improvements to clang-query
9191
Improvements to clang-tidy
9292
--------------------------
9393

94+
- Changed the :program:`check_clang_tidy.py` tool to use FileCheck's
95+
``--match-full-lines`` instead of ``strict-whitespace`` for ``CHECK-FIXES``
96+
clauses. Added a ``--match-partial-fixes`` option to keep previous behavior on
97+
specific tests. This may break tests for users with custom out-of-tree checks
98+
who use :program:`check_clang_tidy.py` as-is.
99+
94100
- Improved :program:`clang-tidy-diff.py` script. Add the `-warnings-as-errors`
95101
argument to treat warnings as errors.
96102

clang-tools-extra/test/clang-tidy/check_clang_tidy.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(self, args: argparse.Namespace, extra_args: List[str]) -> None:
105105
self.fixes = MessagePrefix("CHECK-FIXES")
106106
self.messages = MessagePrefix("CHECK-MESSAGES")
107107
self.notes = MessagePrefix("CHECK-NOTES")
108+
self.match_partial_fixes = args.match_partial_fixes
108109

109110
file_name_with_extension = self.assume_file_name or self.input_file_name
110111
_, extension = os.path.splitext(file_name_with_extension)
@@ -248,10 +249,14 @@ def check_fixes(self) -> None:
248249
try_run(
249250
[
250251
"FileCheck",
251-
"-input-file=" + self.temp_file_name,
252+
"--input-file=" + self.temp_file_name,
252253
self.input_file_name,
253-
"-check-prefixes=" + ",".join(self.fixes.prefixes),
254-
"-strict-whitespace",
254+
"--check-prefixes=" + ",".join(self.fixes.prefixes),
255+
(
256+
"--match-full-lines"
257+
if not self.match_partial_fixes
258+
else "--strict-whitespace" # Keeping past behavior.
259+
),
255260
]
256261
)
257262

@@ -372,6 +377,11 @@ def parse_arguments() -> Tuple[argparse.Namespace, List[str]]:
372377
default=["c++11-or-later"],
373378
help="Passed to clang. Special -or-later values are expanded.",
374379
)
380+
parser.add_argument(
381+
"--match-partial-fixes",
382+
action="store_true",
383+
help="allow partial line matches for fixes",
384+
)
375385
return parser.parse_known_args()
376386

377387

clang-tools-extra/test/clang-tidy/checkers/abseil/duration-addition.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s abseil-duration-addition %t -- -- -I%S/Inputs
1+
// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-addition %t -- -- -I%S/Inputs
22

33
#include "absl/time/time.h"
44

clang-tools-extra/test/clang-tidy/checkers/abseil/duration-comparison.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s abseil-duration-comparison %t -- -- -I%S/Inputs
1+
// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-comparison %t -- -- -I%S/Inputs
22

33
#include "absl/time/time.h"
44

clang-tools-extra/test/clang-tidy/checkers/abseil/duration-conversion-cast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s abseil-duration-conversion-cast %t -- -- -I%S/Inputs
1+
// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-conversion-cast %t -- -- -I%S/Inputs
22

33
#include "absl/time/time.h"
44

clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-float.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s abseil-duration-factory-float %t -- -- -I%S/Inputs
1+
// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-factory-float %t -- -- -I%S/Inputs
22

33
#include "absl/time/time.h"
44

clang-tools-extra/test/clang-tidy/checkers/abseil/duration-factory-scale.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s abseil-duration-factory-scale %t -- -- -I%S/Inputs
1+
// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-factory-scale %t -- -- -I%S/Inputs
22

33
#include "absl/time/time.h"
44

clang-tools-extra/test/clang-tidy/checkers/abseil/duration-subtraction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s abseil-duration-subtraction %t -- -- -I %S/Inputs
1+
// RUN: %check_clang_tidy --match-partial-fixes %s abseil-duration-subtraction %t -- -- -I %S/Inputs
22

33
#include "absl/time/time.h"
44

clang-tools-extra/test/clang-tidy/checkers/abseil/duration-unnecessary-conversion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy -std=c++11-or-later %s abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
1+
// RUN: %check_clang_tidy --match-partial-fixes -std=c++11-or-later %s abseil-duration-unnecessary-conversion %t -- -- -I %S/Inputs
22

33
#include "absl/time/time.h"
44

clang-tools-extra/test/clang-tidy/checkers/abseil/redundant-strcat-calls.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %check_clang_tidy %s abseil-redundant-strcat-calls %t -- -- -isystem %clang_tidy_headers
1+
// RUN: %check_clang_tidy --match-partial-fixes %s abseil-redundant-strcat-calls %t -- -- -isystem %clang_tidy_headers
22
#include <string>
33

44
namespace absl {

0 commit comments

Comments
 (0)