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
15void printf_simple() {
16 printf(format: "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
21void printf_newline() {
22 printf(format: "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
27void fprintf_simple(FILE *fp) {
28 fprintf(stream: fp, format: "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
33void fprintf_newline(FILE *fp) {
34 fprintf(stream: fp, format: "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

source code of clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-print-fmt.cpp