[clang] [clang][analyzer] Fix alignment of entries in -analyzer-help (PR #190570)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 7 18:57:27 PDT 2026
https://github.com/filaka771 updated https://github.com/llvm/llvm-project/pull/190570
>From d61767e1f97af2cae72d8dfdc0e0301f3873cb05 Mon Sep 17 00:00:00 2001
From: Alex Filak <filaka771 at gmail.com>
Date: Sun, 5 Apr 2026 19:27:56 +0300
Subject: [PATCH 1/5] [clang][analyzer] Fix alignment of entries in
-analyzer-help
---
.../StaticAnalyzer/Core/AnalyzerOptions.cpp | 11 +-
.../StaticAnalyzer/AnalyzerFormattingTest.cpp | 180 ++++++++++++++++++
clang/unittests/StaticAnalyzer/CMakeLists.txt | 1 +
3 files changed, 189 insertions(+), 3 deletions(-)
create mode 100644 clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
diff --git a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
index 6ba67f8d11d57..20bcbdb4762d0 100644
--- a/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
+++ b/clang/lib/StaticAnalyzer/Core/AnalyzerOptions.cpp
@@ -37,9 +37,14 @@ void AnalyzerOptions::printFormattedEntry(
const size_t PadForDesc = InitialPad + EntryWidth;
- FOut.PadToColumn(InitialPad) << EntryDescPair.first;
- // If the buffer's length is greater than PadForDesc, print a newline.
- if (FOut.getColumn() > PadForDesc)
+ if (InitialPad != 0)
+ FOut.PadToColumn(InitialPad);
+
+ FOut << EntryDescPair.first;
+
+ // If the buffer's length is greater than or equal to PadForDesc,
+ // print a newline.
+ if (FOut.getColumn() >= PadForDesc)
FOut << '\n';
FOut.PadToColumn(PadForDesc);
diff --git a/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
new file mode 100644
index 0000000000000..707e3197d0eab
--- /dev/null
+++ b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
@@ -0,0 +1,180 @@
+//===- AnalyzerFormattingTest.cpp - SA Formatting test --------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// This file contains tests for printFormattedEntry function, which is used for
+// printing available analyzers and their descriptions.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/StaticAnalyzer/Core/AnalyzerOptions.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/raw_ostream.h"
+#include "gtest/gtest.h"
+
+using namespace clang::ento;
+
+static void runPrintFormattedEntry(
+ std::pair<llvm::StringRef, llvm::StringRef> EntryDescPair,
+ size_t InitialPad, size_t EntryWidth, size_t MinLineWidth,
+ llvm::SmallString<256> &OutBuffer) {
+ llvm::raw_svector_ostream Out(OutBuffer);
+ clang::AnalyzerOptions::printFormattedEntry(Out, EntryDescPair, InitialPad,
+ EntryWidth, MinLineWidth);
+}
+
+// No wrapping after checker's name.
+// No initial pad.
+TEST(PrintFormattedEntryTest, SimplePrint) {
+ llvm::SmallString<256> Buffer;
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+ /*InitialPad=*/0,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/0,
+ /*OutBuffer=*/Buffer);
+
+ EXPECT_EQ(Buffer, "Checkers A description");
+}
+
+// With wrapping after checker's name.
+// No initial pad.
+TEST(PrintFormattedEntryTest, EntryLongerThanWidth) {
+ llvm::SmallString<256> Buffer;
+ runPrintFormattedEntry(
+ {/*EntryDescPair=*/"VeryLongCheckerName", "A description"},
+ /*InitialPad=*/0,
+ /*EntryWidth=*/10,
+ /*MinLineWidth=*/0,
+ /*OutBuffer=*/Buffer);
+
+ EXPECT_EQ(Buffer, "VeryLongCheckerName\n"
+ " A description");
+}
+
+// With wrapping after checker's name.
+// No initial pad.
+// Corner case, when checker's name length equal to EntryWidth.
+TEST(PrintFormattedEntryTest, ExactFillWidth) {
+ llvm::SmallString<256> Buffer;
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+ /*InitialPad=*/0,
+ /*EntryWidth=*/8,
+ /*MinLineWidth=*/0,
+ /*OutBuffer=*/Buffer);
+
+ EXPECT_EQ(Buffer, "Checkers\n"
+ " A description");
+}
+
+// No wrapping after checker's name.
+// With initial pad.
+TEST(PrintFormattedEntryTest, WithInitialPadding) {
+ llvm::SmallString<256> Buffer;
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+ /*InitialPad=*/2,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/0,
+ /*OutBuffer=*/Buffer);
+
+ EXPECT_EQ(Buffer, " Checkers A description");
+}
+
+// No wrapping after checker's name.
+// With initial pad.
+// With wrapping in checker's description (MinLineWidth > 0).
+TEST(PrintFormattedEntryTest, WrapDescription) {
+ llvm::SmallString<256> Buffer;
+ llvm::StringRef Desc =
+ "This is a long description that should be wrapped into multiple lines.";
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", Desc},
+ /*InitialPad=*/2,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/40,
+ /*OutBuffer=*/Buffer);
+
+ llvm::StringRef Expected =
+ " Checkers This is a long description\n"
+ " that should be wrapped\n"
+ " into multiple lines.";
+ EXPECT_EQ(Buffer, Expected);
+}
+
+// No wrapping after checker's name.
+// With initial pad.
+// No wrapping in checker's descriptions (MinLineWdth = 0).
+TEST(PrintFormattedEntryTest, NoWrap) {
+ llvm::SmallString<256> Buffer;
+ llvm::StringRef Desc = "This is a very long description that will not be "
+ "wrapped because MinLineWidth=0.";
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", Desc},
+ /*InitialPad=*/2,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/0,
+ /*OutBuffer=*/Buffer);
+
+ std::string Expected = " Checkers " + Desc.str();
+ EXPECT_EQ(Buffer, Expected);
+}
+
+// No wrapping after checker's name.
+// No initial pad.
+// Corner case with empty descriptions.
+TEST(PrintFormattedEntryTest, EmptyDescription) {
+ llvm::SmallString<256> Buffer;
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", ""},
+ /*InitialPad=*/0,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/0,
+ /*OutBuffer=*/Buffer);
+
+ EXPECT_EQ(Buffer, "Checkers ");
+}
+
+// No wrapping after checker's name.
+// No initial pad.
+// Corner case with empty checker's name.
+TEST(PrintFormattedEntryTest, EmptyEntry) {
+ llvm::SmallString<256> Buffer;
+ runPrintFormattedEntry(/*EntryDescPair=*/{"", "Some description"},
+ /*InitialPad=*/0,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/0,
+ /*OutBuffer=*/Buffer);
+
+ EXPECT_EQ(Buffer, " Some description");
+}
+
+// No wrapping after checker's name.
+// With initial pad.
+// Narrow MinLineWidth with a word without spaces (no break).
+TEST(PrintFormattedEntryTest, NarrowMinLineWidthNoSpaces) {
+ llvm::SmallString<256> Buffer;
+ runPrintFormattedEntry(
+ /*EntryDescPair=*/{"Checkers", "This_is_a_long_word_without_spaces"},
+ /*InitialPad=*/2,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/10,
+ /*OutBuffer=*/Buffer);
+
+ EXPECT_EQ(Buffer, " Checkers This_is_a_long_word_without_spaces");
+}
+
+// No wrapping after checker's name.
+// With initial pad.
+// With wrapping in checker's description.
+TEST(PrintFormattedEntryTest, MinLineWidthLessThanPad) {
+ llvm::SmallString<256> Buffer;
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "short phrase"},
+ /*InitialPad=*/2,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/15,
+ /*OutBuffer=*/Buffer);
+
+ llvm::StringRef Expected = " Checkers short\n"
+ " phrase";
+ EXPECT_EQ(Buffer, Expected);
+}
diff --git a/clang/unittests/StaticAnalyzer/CMakeLists.txt b/clang/unittests/StaticAnalyzer/CMakeLists.txt
index caf686e2a92e2..ed16a1372bea2 100644
--- a/clang/unittests/StaticAnalyzer/CMakeLists.txt
+++ b/clang/unittests/StaticAnalyzer/CMakeLists.txt
@@ -1,4 +1,5 @@
add_clang_unittest(StaticAnalysisTests
+ AnalyzerFormattingTest.cpp
AnalyzerOptionsTest.cpp
APSIntTypeTest.cpp
BlockEntranceCallbackTest.cpp
>From 7013ef28a10be495732fd1167ffcd42a469095f0 Mon Sep 17 00:00:00 2001
From: Alex Filak <filaka771 at gmail.com>
Date: Tue, 7 Apr 2026 18:12:40 +0300
Subject: [PATCH 2/5] Fix spelling
---
clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
index 707e3197d0eab..d908c5aa7126b 100644
--- a/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
+++ b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
@@ -105,7 +105,7 @@ TEST(PrintFormattedEntryTest, WrapDescription) {
// No wrapping after checker's name.
// With initial pad.
-// No wrapping in checker's descriptions (MinLineWdth = 0).
+// No wrapping in checker's descriptions (MinLineWidth = 0).
TEST(PrintFormattedEntryTest, NoWrap) {
llvm::SmallString<256> Buffer;
llvm::StringRef Desc = "This is a very long description that will not be "
>From 6002052864ed7dda2aeefed95ac9ed05cf0f7e0c Mon Sep 17 00:00:00 2001
From: Alex Filak <filaka771 at gmail.com>
Date: Tue, 7 Apr 2026 18:12:56 +0300
Subject: [PATCH 3/5] Add test for how printFormattedEntry was used in
-analyzer-checker-help
---
.../StaticAnalyzer/AnalyzerFormattingTest.cpp | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
index d908c5aa7126b..67a26b80dd9f6 100644
--- a/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
+++ b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
@@ -70,6 +70,23 @@ TEST(PrintFormattedEntryTest, ExactFillWidth) {
" A description");
}
+// With wrapping after checker's name.
+// With initial pad.
+// Corner case, when checker's name length equal to EntryWidth.
+// This test matches how printFormattedEntry was called
+// in -analyzer-checker-help, which led to a formatting bug.
+TEST(PrintFormattedEntryTest, ExactFillWidthWithInitialPad) {
+ llvm::SmallString<256> Buffer;
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+ /*InitialPad=*/2,
+ /*EntryWidth=*/8,
+ /*MinLineWidth=*/0,
+ /*OutBuffer=*/Buffer);
+
+ EXPECT_EQ(Buffer, " Checkers\n"
+ " A description");
+}
+
// No wrapping after checker's name.
// With initial pad.
TEST(PrintFormattedEntryTest, WithInitialPadding) {
>From 44f7537254bde71a163b7ff1d6dd4226e7741f1c Mon Sep 17 00:00:00 2001
From: Alex Filak <filaka771 at gmail.com>
Date: Wed, 8 Apr 2026 04:36:36 +0300
Subject: [PATCH 4/5] Fix spelling
---
.../StaticAnalyzer/AnalyzerFormattingTest.cpp | 44 +++++++++----------
1 file changed, 22 insertions(+), 22 deletions(-)
diff --git a/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
index 67a26b80dd9f6..74e03a2850514 100644
--- a/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
+++ b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
@@ -31,13 +31,13 @@ static void runPrintFormattedEntry(
// No initial pad.
TEST(PrintFormattedEntryTest, SimplePrint) {
llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
/*InitialPad=*/0,
/*EntryWidth=*/20,
/*MinLineWidth=*/0,
/*OutBuffer=*/Buffer);
- EXPECT_EQ(Buffer, "Checkers A description");
+ EXPECT_EQ(Buffer, "Checker A description");
}
// With wrapping after checker's name.
@@ -60,14 +60,14 @@ TEST(PrintFormattedEntryTest, EntryLongerThanWidth) {
// Corner case, when checker's name length equal to EntryWidth.
TEST(PrintFormattedEntryTest, ExactFillWidth) {
llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
/*InitialPad=*/0,
- /*EntryWidth=*/8,
+ /*EntryWidth=*/7,
/*MinLineWidth=*/0,
/*OutBuffer=*/Buffer);
- EXPECT_EQ(Buffer, "Checkers\n"
- " A description");
+ EXPECT_EQ(Buffer, "Checker\n"
+ " A description");
}
// With wrapping after checker's name.
@@ -77,27 +77,27 @@ TEST(PrintFormattedEntryTest, ExactFillWidth) {
// in -analyzer-checker-help, which led to a formatting bug.
TEST(PrintFormattedEntryTest, ExactFillWidthWithInitialPad) {
llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
/*InitialPad=*/2,
- /*EntryWidth=*/8,
+ /*EntryWidth=*/7,
/*MinLineWidth=*/0,
/*OutBuffer=*/Buffer);
- EXPECT_EQ(Buffer, " Checkers\n"
- " A description");
+ EXPECT_EQ(Buffer, " Checker\n"
+ " A description");
}
// No wrapping after checker's name.
// With initial pad.
TEST(PrintFormattedEntryTest, WithInitialPadding) {
llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "A description"},
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
/*InitialPad=*/2,
/*EntryWidth=*/20,
/*MinLineWidth=*/0,
/*OutBuffer=*/Buffer);
- EXPECT_EQ(Buffer, " Checkers A description");
+ EXPECT_EQ(Buffer, " Checker A description");
}
// No wrapping after checker's name.
@@ -107,14 +107,14 @@ TEST(PrintFormattedEntryTest, WrapDescription) {
llvm::SmallString<256> Buffer;
llvm::StringRef Desc =
"This is a long description that should be wrapped into multiple lines.";
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", Desc},
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", Desc},
/*InitialPad=*/2,
/*EntryWidth=*/20,
/*MinLineWidth=*/40,
/*OutBuffer=*/Buffer);
llvm::StringRef Expected =
- " Checkers This is a long description\n"
+ " Checker This is a long description\n"
" that should be wrapped\n"
" into multiple lines.";
EXPECT_EQ(Buffer, Expected);
@@ -127,13 +127,13 @@ TEST(PrintFormattedEntryTest, NoWrap) {
llvm::SmallString<256> Buffer;
llvm::StringRef Desc = "This is a very long description that will not be "
"wrapped because MinLineWidth=0.";
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", Desc},
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", Desc},
/*InitialPad=*/2,
/*EntryWidth=*/20,
/*MinLineWidth=*/0,
/*OutBuffer=*/Buffer);
- std::string Expected = " Checkers " + Desc.str();
+ std::string Expected = " Checker " + Desc.str();
EXPECT_EQ(Buffer, Expected);
}
@@ -142,13 +142,13 @@ TEST(PrintFormattedEntryTest, NoWrap) {
// Corner case with empty descriptions.
TEST(PrintFormattedEntryTest, EmptyDescription) {
llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", ""},
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", ""},
/*InitialPad=*/0,
/*EntryWidth=*/20,
/*MinLineWidth=*/0,
/*OutBuffer=*/Buffer);
- EXPECT_EQ(Buffer, "Checkers ");
+ EXPECT_EQ(Buffer, "Checker ");
}
// No wrapping after checker's name.
@@ -171,13 +171,13 @@ TEST(PrintFormattedEntryTest, EmptyEntry) {
TEST(PrintFormattedEntryTest, NarrowMinLineWidthNoSpaces) {
llvm::SmallString<256> Buffer;
runPrintFormattedEntry(
- /*EntryDescPair=*/{"Checkers", "This_is_a_long_word_without_spaces"},
+ /*EntryDescPair=*/{"Checker", "This_is_a_long_word_without_spaces"},
/*InitialPad=*/2,
/*EntryWidth=*/20,
/*MinLineWidth=*/10,
/*OutBuffer=*/Buffer);
- EXPECT_EQ(Buffer, " Checkers This_is_a_long_word_without_spaces");
+ EXPECT_EQ(Buffer, " Checker This_is_a_long_word_without_spaces");
}
// No wrapping after checker's name.
@@ -185,13 +185,13 @@ TEST(PrintFormattedEntryTest, NarrowMinLineWidthNoSpaces) {
// With wrapping in checker's description.
TEST(PrintFormattedEntryTest, MinLineWidthLessThanPad) {
llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checkers", "short phrase"},
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "short phrase"},
/*InitialPad=*/2,
/*EntryWidth=*/20,
/*MinLineWidth=*/15,
/*OutBuffer=*/Buffer);
- llvm::StringRef Expected = " Checkers short\n"
+ llvm::StringRef Expected = " Checker short\n"
" phrase";
EXPECT_EQ(Buffer, Expected);
}
>From 1bad6ea97def03ad032123ddcb009747d901270b Mon Sep 17 00:00:00 2001
From: Alex Filak <filaka771 at gmail.com>
Date: Wed, 8 Apr 2026 04:57:10 +0300
Subject: [PATCH 5/5] Refactor tests to return string by value
---
.../StaticAnalyzer/AnalyzerFormattingTest.cpp | 123 ++++++++----------
1 file changed, 55 insertions(+), 68 deletions(-)
diff --git a/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
index 74e03a2850514..71af93aa0eb42 100644
--- a/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
+++ b/clang/unittests/StaticAnalyzer/AnalyzerFormattingTest.cpp
@@ -15,27 +15,29 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
+#include <string>
using namespace clang::ento;
-static void runPrintFormattedEntry(
+static std::string runPrintFormattedEntry(
std::pair<llvm::StringRef, llvm::StringRef> EntryDescPair,
- size_t InitialPad, size_t EntryWidth, size_t MinLineWidth,
- llvm::SmallString<256> &OutBuffer) {
- llvm::raw_svector_ostream Out(OutBuffer);
+ size_t InitialPad, size_t EntryWidth, size_t MinLineWidth) {
+
+ std::string OutBuffer;
+ llvm::raw_string_ostream Out(OutBuffer);
clang::AnalyzerOptions::printFormattedEntry(Out, EntryDescPair, InitialPad,
EntryWidth, MinLineWidth);
+ return OutBuffer;
}
// No wrapping after checker's name.
// No initial pad.
TEST(PrintFormattedEntryTest, SimplePrint) {
- llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
- /*InitialPad=*/0,
- /*EntryWidth=*/20,
- /*MinLineWidth=*/0,
- /*OutBuffer=*/Buffer);
+ std::string Buffer =
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
+ /*InitialPad=*/0,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/0);
EXPECT_EQ(Buffer, "Checker A description");
}
@@ -43,13 +45,11 @@ TEST(PrintFormattedEntryTest, SimplePrint) {
// With wrapping after checker's name.
// No initial pad.
TEST(PrintFormattedEntryTest, EntryLongerThanWidth) {
- llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(
+ std::string Buffer = runPrintFormattedEntry(
{/*EntryDescPair=*/"VeryLongCheckerName", "A description"},
/*InitialPad=*/0,
/*EntryWidth=*/10,
- /*MinLineWidth=*/0,
- /*OutBuffer=*/Buffer);
+ /*MinLineWidth=*/0);
EXPECT_EQ(Buffer, "VeryLongCheckerName\n"
" A description");
@@ -59,12 +59,11 @@ TEST(PrintFormattedEntryTest, EntryLongerThanWidth) {
// No initial pad.
// Corner case, when checker's name length equal to EntryWidth.
TEST(PrintFormattedEntryTest, ExactFillWidth) {
- llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
- /*InitialPad=*/0,
- /*EntryWidth=*/7,
- /*MinLineWidth=*/0,
- /*OutBuffer=*/Buffer);
+ std::string Buffer =
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
+ /*InitialPad=*/0,
+ /*EntryWidth=*/7,
+ /*MinLineWidth=*/0);
EXPECT_EQ(Buffer, "Checker\n"
" A description");
@@ -76,12 +75,11 @@ TEST(PrintFormattedEntryTest, ExactFillWidth) {
// This test matches how printFormattedEntry was called
// in -analyzer-checker-help, which led to a formatting bug.
TEST(PrintFormattedEntryTest, ExactFillWidthWithInitialPad) {
- llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
- /*InitialPad=*/2,
- /*EntryWidth=*/7,
- /*MinLineWidth=*/0,
- /*OutBuffer=*/Buffer);
+ std::string Buffer =
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
+ /*InitialPad=*/2,
+ /*EntryWidth=*/7,
+ /*MinLineWidth=*/0);
EXPECT_EQ(Buffer, " Checker\n"
" A description");
@@ -90,12 +88,11 @@ TEST(PrintFormattedEntryTest, ExactFillWidthWithInitialPad) {
// No wrapping after checker's name.
// With initial pad.
TEST(PrintFormattedEntryTest, WithInitialPadding) {
- llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
- /*InitialPad=*/2,
- /*EntryWidth=*/20,
- /*MinLineWidth=*/0,
- /*OutBuffer=*/Buffer);
+ std::string Buffer =
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "A description"},
+ /*InitialPad=*/2,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/0);
EXPECT_EQ(Buffer, " Checker A description");
}
@@ -104,19 +101,16 @@ TEST(PrintFormattedEntryTest, WithInitialPadding) {
// With initial pad.
// With wrapping in checker's description (MinLineWidth > 0).
TEST(PrintFormattedEntryTest, WrapDescription) {
- llvm::SmallString<256> Buffer;
- llvm::StringRef Desc =
+ std::string Buffer = std::string Desc =
"This is a long description that should be wrapped into multiple lines.";
runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", Desc},
/*InitialPad=*/2,
/*EntryWidth=*/20,
- /*MinLineWidth=*/40,
- /*OutBuffer=*/Buffer);
+ /*MinLineWidth=*/40);
- llvm::StringRef Expected =
- " Checker This is a long description\n"
- " that should be wrapped\n"
- " into multiple lines.";
+ std::string Expected = " Checker This is a long description\n"
+ " that should be wrapped\n"
+ " into multiple lines.";
EXPECT_EQ(Buffer, Expected);
}
@@ -124,16 +118,15 @@ TEST(PrintFormattedEntryTest, WrapDescription) {
// With initial pad.
// No wrapping in checker's descriptions (MinLineWidth = 0).
TEST(PrintFormattedEntryTest, NoWrap) {
- llvm::SmallString<256> Buffer;
- llvm::StringRef Desc = "This is a very long description that will not be "
- "wrapped because MinLineWidth=0.";
+ std::string Buffer = std::string Desc =
+ "This is a very long description that will not be "
+ "wrapped because MinLineWidth=0.";
runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", Desc},
/*InitialPad=*/2,
/*EntryWidth=*/20,
- /*MinLineWidth=*/0,
- /*OutBuffer=*/Buffer);
+ /*MinLineWidth=*/0);
- std::string Expected = " Checker " + Desc.str();
+ std::string Expected = " Checker " + Desc;
EXPECT_EQ(Buffer, Expected);
}
@@ -141,12 +134,10 @@ TEST(PrintFormattedEntryTest, NoWrap) {
// No initial pad.
// Corner case with empty descriptions.
TEST(PrintFormattedEntryTest, EmptyDescription) {
- llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", ""},
- /*InitialPad=*/0,
- /*EntryWidth=*/20,
- /*MinLineWidth=*/0,
- /*OutBuffer=*/Buffer);
+ std::string Buffer = runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", ""},
+ /*InitialPad=*/0,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/0);
EXPECT_EQ(Buffer, "Checker ");
}
@@ -155,12 +146,11 @@ TEST(PrintFormattedEntryTest, EmptyDescription) {
// No initial pad.
// Corner case with empty checker's name.
TEST(PrintFormattedEntryTest, EmptyEntry) {
- llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"", "Some description"},
- /*InitialPad=*/0,
- /*EntryWidth=*/20,
- /*MinLineWidth=*/0,
- /*OutBuffer=*/Buffer);
+ std::string Buffer =
+ runPrintFormattedEntry(/*EntryDescPair=*/{"", "Some description"},
+ /*InitialPad=*/0,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/0);
EXPECT_EQ(Buffer, " Some description");
}
@@ -169,13 +159,11 @@ TEST(PrintFormattedEntryTest, EmptyEntry) {
// With initial pad.
// Narrow MinLineWidth with a word without spaces (no break).
TEST(PrintFormattedEntryTest, NarrowMinLineWidthNoSpaces) {
- llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(
+ std::string Buffer = runPrintFormattedEntry(
/*EntryDescPair=*/{"Checker", "This_is_a_long_word_without_spaces"},
/*InitialPad=*/2,
/*EntryWidth=*/20,
- /*MinLineWidth=*/10,
- /*OutBuffer=*/Buffer);
+ /*MinLineWidth=*/10);
EXPECT_EQ(Buffer, " Checker This_is_a_long_word_without_spaces");
}
@@ -184,12 +172,11 @@ TEST(PrintFormattedEntryTest, NarrowMinLineWidthNoSpaces) {
// With initial pad.
// With wrapping in checker's description.
TEST(PrintFormattedEntryTest, MinLineWidthLessThanPad) {
- llvm::SmallString<256> Buffer;
- runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "short phrase"},
- /*InitialPad=*/2,
- /*EntryWidth=*/20,
- /*MinLineWidth=*/15,
- /*OutBuffer=*/Buffer);
+ std::string Buffer =
+ runPrintFormattedEntry(/*EntryDescPair=*/{"Checker", "short phrase"},
+ /*InitialPad=*/2,
+ /*EntryWidth=*/20,
+ /*MinLineWidth=*/15);
llvm::StringRef Expected = " Checker short\n"
" phrase";
More information about the cfe-commits
mailing list