Skip to content

Commit ff230d5

Browse files
committed
Tweak macros passed on command line to avoid confusing lit on Windows
On at least Windows, the `%s` in the macros passed on the command line for the tests are being replaced with the filename for the test. Let's try to avoid that by removing the `%` prefix from all the test macros. This makes them consistent with the <inttypes.h> macros too.
1 parent 996b124 commit ff230d5

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// RUN: -std=c++20 %s modernize-use-std-format %t -- \
33
// RUN: -config="{CheckOptions: {StrictMode: true}}" \
44
// RUN: -- -isystem %clang_tidy_headers \
5-
// RUN: -DPRI_CMDLINE_MACRO="\"%s\"" \
6-
// RUN: -D__PRI_CMDLINE_MACRO="\"%s\""
5+
// RUN: -DPRI_CMDLINE_MACRO="\"s\"" \
6+
// RUN: -D__PRI_CMDLINE_MACRO="\"s\""
77
// RUN: %check_clang_tidy \
88
// RUN: -std=c++20 %s modernize-use-std-format %t -- \
99
// RUN: -config="{CheckOptions: {StrictMode: false}}" \
1010
// RUN: -- -isystem %clang_tidy_headers \
11-
// RUN: -DPRI_CMDLINE_MACRO="\"%s\"" \
12-
// RUN: -D__PRI_CMDLINE_MACRO="\"%s\""
11+
// RUN: -DPRI_CMDLINE_MACRO="\"s\"" \
12+
// RUN: -D__PRI_CMDLINE_MACRO="\"s\""
1313
#include <string>
1414
// CHECK-FIXES: #include <format>
1515
#include <inttypes.h>
@@ -130,26 +130,26 @@ std::string StrFormat_macros() {
130130

131131
// These need PRI and __PRI prefixes so that the check get as far as looking for
132132
// where the macro comes from.
133-
#define PRI_FMT_MACRO "%s"
134-
#define __PRI_FMT_MACRO "%s"
133+
#define PRI_FMT_MACRO "s"
134+
#define __PRI_FMT_MACRO "s"
135135

136-
auto s6 = absl::StrFormat("Unreplaceable macro at end " PRI_FMT_MACRO, s.c_str());
136+
auto s6 = absl::StrFormat("Unreplaceable macro at end %" PRI_FMT_MACRO, s.c_str());
137137
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: unable to use 'std::format' instead of 'StrFormat' because format string contains unreplaceable macro 'PRI_FMT_MACRO' [modernize-use-std-format]
138138

139-
auto s7 = absl::StrFormat(__PRI_FMT_MACRO " Unreplaceable macro at beginning", s);
139+
auto s7 = absl::StrFormat(__PRI_FMT_MACRO " Unreplaceable macro at beginning %s", s);
140140
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: unable to use 'std::format' instead of 'StrFormat' because format string contains unreplaceable macro '__PRI_FMT_MACRO' [modernize-use-std-format]
141141

142-
auto s8 = absl::StrFormat("Unreplacemable macro " PRI_FMT_MACRO " in the middle", s);
142+
auto s8 = absl::StrFormat("Unreplacemable macro %" PRI_FMT_MACRO " in the middle", s);
143143
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: unable to use 'std::format' instead of 'StrFormat' because format string contains unreplaceable macro 'PRI_FMT_MACRO' [modernize-use-std-format]
144144

145-
auto s9 = absl::StrFormat("First macro is replaceable %" PRIu64 " but second one is not " __PRI_FMT_MACRO, u64, s);
145+
auto s9 = absl::StrFormat("First macro is replaceable %" PRIu64 " but second one is not %" __PRI_FMT_MACRO, u64, s);
146146
// CHECK-MESSAGES: [[@LINE-1]]:13: warning: unable to use 'std::format' instead of 'StrFormat' because format string contains unreplaceable macro '__PRI_FMT_MACRO' [modernize-use-std-format]
147147

148148
// Needs a PRI prefix so that we get as far as looking for where the macro comes from
149-
auto s10 = absl::StrFormat(" macro from command line " PRI_CMDLINE_MACRO, s);
149+
auto s10 = absl::StrFormat(" macro from command line %" PRI_CMDLINE_MACRO, s);
150150
// CHECK-MESSAGES: [[@LINE-1]]:14: warning: unable to use 'std::format' instead of 'StrFormat' because format string contains unreplaceable macro 'PRI_CMDLINE_MACRO' [modernize-use-std-format]
151151

152152
// Needs a __PRI prefix so that we get as far as looking for where the macro comes from
153-
auto s11 = absl::StrFormat(" macro from command line " __PRI_CMDLINE_MACRO, s);
153+
auto s11 = absl::StrFormat(" macro from command line %" __PRI_CMDLINE_MACRO, s);
154154
// CHECK-MESSAGES: [[@LINE-1]]:14: warning: unable to use 'std::format' instead of 'StrFormat' because format string contains unreplaceable macro '__PRI_CMDLINE_MACRO' [modernize-use-std-format]
155155
}

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// RUN: -std=c++23 %s modernize-use-std-print %t -- \
33
// RUN: -config="{CheckOptions: {StrictMode: true}}" \
44
// RUN: -- -isystem %clang_tidy_headers -fexceptions \
5-
// RUN: -DPRI_CMDLINE_MACRO="\"%s\"" \
6-
// RUN: -D__PRI_CMDLINE_MACRO="\"%s\""
5+
// RUN: -DPRI_CMDLINE_MACRO="\"s\"" \
6+
// RUN: -D__PRI_CMDLINE_MACRO="\"s\""
77
// RUN: %check_clang_tidy -check-suffixes=,NOTSTRICT \
88
// RUN: -std=c++23 %s modernize-use-std-print %t -- \
99
// RUN: -config="{CheckOptions: {StrictMode: false}}" \
1010
// RUN: -- -isystem %clang_tidy_headers -fexceptions \
11-
// RUN: -DPRI_CMDLINE_MACRO="\"%s\"" \
12-
// RUN: -D__PRI_CMDLINE_MACRO="\"%s\""
11+
// RUN: -DPRI_CMDLINE_MACRO="\"s\"" \
12+
// RUN: -D__PRI_CMDLINE_MACRO="\"s\""
1313
#include <cstddef>
1414
#include <cstdint>
1515
#include <cstdio>
@@ -1578,8 +1578,8 @@ void p(S s1, S *s2)
15781578

15791579
// These need PRI and __PRI prefixes so that the check gets as far as looking
15801580
// for where the macro comes from.
1581-
#define PRI_FMT_MACRO "%s"
1582-
#define __PRI_FMT_MACRO "%s"
1581+
#define PRI_FMT_MACRO "s"
1582+
#define __PRI_FMT_MACRO "s"
15831583

15841584
void macro_expansion(const char *s)
15851585
{
@@ -1594,23 +1594,23 @@ void macro_expansion(const char *s)
15941594
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'std::println' instead of 'printf' [modernize-use-std-print]
15951595
// CHECK-FIXES: std::println("Replaceable macros in middle {} {}", u64, u32);
15961596

1597-
printf("Unreplaceable macro at end " PRI_FMT_MACRO, s);
1597+
printf("Unreplaceable macro at end %" PRI_FMT_MACRO, s);
15981598
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: unable to use 'std::print' instead of 'printf' because format string contains unreplaceable macro 'PRI_FMT_MACRO' [modernize-use-std-print]
15991599

1600-
printf(PRI_FMT_MACRO " Unreplaceable macro at beginning", s);
1600+
printf(PRI_FMT_MACRO " Unreplaceable macro at beginning %s", s);
16011601
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: unable to use 'std::print' instead of 'printf' because format string contains unreplaceable macro 'PRI_FMT_MACRO' [modernize-use-std-print]
16021602

1603-
printf("Unreplacemable macro " __PRI_FMT_MACRO " in the middle", s);
1603+
printf("Unreplacemable macro %" __PRI_FMT_MACRO " in the middle", s);
16041604
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: unable to use 'std::print' instead of 'printf' because format string contains unreplaceable macro '__PRI_FMT_MACRO' [modernize-use-std-print]
16051605

1606-
printf("First macro is replaceable %" PRIu64 " but second one is not " PRI_FMT_MACRO, u64, s);
1606+
printf("First macro is replaceable %" PRIu64 " but second one is not %" PRI_FMT_MACRO, u64, s);
16071607
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: unable to use 'std::print' instead of 'printf' because format string contains unreplaceable macro 'PRI_FMT_MACRO' [modernize-use-std-print]
16081608

16091609
// Needs a PRI prefix so that we get as far as looking for where the macro comes from
1610-
printf(" macro from command line " PRI_CMDLINE_MACRO, s);
1610+
printf(" macro from command line %" PRI_CMDLINE_MACRO, s);
16111611
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: unable to use 'std::print' instead of 'printf' because format string contains unreplaceable macro 'PRI_CMDLINE_MACRO' [modernize-use-std-print]
16121612

16131613
// Needs a __PRI prefix so that we get as far as looking for where the macro comes from
1614-
printf(" macro from command line " __PRI_CMDLINE_MACRO, s);
1614+
printf(" macro from command line %" __PRI_CMDLINE_MACRO, s);
16151615
// CHECK-MESSAGES: [[@LINE-1]]:3: warning: unable to use 'std::print' instead of 'printf' because format string contains unreplaceable macro '__PRI_CMDLINE_MACRO' [modernize-use-std-print]
16161616
}

0 commit comments

Comments
 (0)