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