xref: /llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-fmt.cpp (revision ec89cb9a81529fd41fb37b8e62203a2e9f23bd54)
1 // RUN: %check_clang_tidy %s modernize-use-std-print %t -- \
2 // RUN:   -config="{CheckOptions: \
3 // RUN:             [ \
4 // RUN:              { \
5 // RUN:               key: modernize-use-std-print.ReplacementPrintFunction, \
6 // RUN:               value: 'fmt::print' \
7 // RUN:              }, \
8 // RUN:              { \
9 // RUN:               key: modernize-use-std-print.ReplacementPrintlnFunction, \
10 // RUN:               value: 'fmt::println' \
11 // RUN:              }, \
12 // RUN:              { \
13 // RUN:               key: modernize-use-std-print.PrintHeader, \
14 // RUN:               value: '<fmt/core.h>' \
15 // RUN:              } \
16 // RUN:             ] \
17 // RUN:            }" \
18 // RUN:   -- -isystem %clang_tidy_headers
19 
20 #include <cstdio>
21 // CHECK-FIXES: #include <fmt/core.h>
22 #include <string.h>
23 
24 void printf_simple() {
25   printf("Hello %s %d", "world", 42);
26   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'fmt::print' instead of 'printf' [modernize-use-std-print]
27   // CHECK-FIXES: fmt::print("Hello {} {}", "world", 42);
28 }
29 
30 void printf_newline() {
31   printf("Hello %s %d\n", "world", 42);
32   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'fmt::println' instead of 'printf' [modernize-use-std-print]
33   // CHECK-FIXES: fmt::println("Hello {} {}", "world", 42);
34 }
35 
36 void fprintf_simple(FILE *fp) {
37   fprintf(fp, "Hello %s %d", "world", 42);
38   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'fmt::print' instead of 'fprintf' [modernize-use-std-print]
39   // CHECK-FIXES: fmt::print(fp, "Hello {} {}", "world", 42);
40 }
41 
42 void fprintf_newline(FILE *fp) {
43   fprintf(fp, "Hello %s %d\n", "world", 42);
44   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: use 'fmt::println' instead of 'fprintf' [modernize-use-std-print]
45   // CHECK-FIXES: fmt::println(fp, "Hello {} {}", "world", 42);
46 }
47