Skip to content

Commit 69ecd24

Browse files
committed
[clang-format] Indicate source location on test failure. NFC.
1 parent 304cfc7 commit 69ecd24

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

clang/unittests/Format/DefinitionBlockSeparatorTest.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ class DefinitionBlockSeparatorTest : public ::testing::Test {
4141
/*Ranges=*/{1, tooling::Range(0, Code.size())}, Style);
4242
}
4343

44-
static void verifyFormat(llvm::StringRef Code,
45-
const FormatStyle &Style = getLLVMStyle(),
46-
llvm::StringRef ExpectedCode = "") {
44+
static void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
45+
const FormatStyle &Style = getLLVMStyle(),
46+
llvm::StringRef ExpectedCode = "") {
47+
::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
4748
bool HasOriginalCode = true;
4849
if (ExpectedCode == "") {
4950
ExpectedCode = Code;
@@ -83,6 +84,8 @@ class DefinitionBlockSeparatorTest : public ::testing::Test {
8384
}
8485
};
8586

87+
#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
88+
8689
TEST_F(DefinitionBlockSeparatorTest, Basic) {
8790
FormatStyle Style = getLLVMStyle();
8891
Style.SeparateDefinitionBlocks = FormatStyle::SDS_Always;

clang/unittests/Format/FormatTestTextProto.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,22 @@ class FormatTestTextProto : public ::testing::Test {
3434
return format(Code, 0, Code.size(), Style);
3535
}
3636

37-
static void verifyFormat(llvm::StringRef Code, const FormatStyle &Style) {
37+
static void _verifyFormat(const char *File, int Line, llvm::StringRef Code,
38+
const FormatStyle &Style) {
39+
::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
3840
EXPECT_EQ(Code.str(), format(Code, Style)) << "Expected code is not stable";
3941
EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
4042
}
4143

42-
static void verifyFormat(llvm::StringRef Code) {
44+
static void _verifyFormat(const char *File, int Line, llvm::StringRef Code) {
4345
FormatStyle Style = getGoogleStyle(FormatStyle::LK_TextProto);
4446
Style.ColumnLimit = 60; // To make writing tests easier.
45-
verifyFormat(Code, Style);
47+
_verifyFormat(File, Line, Code, Style);
4648
}
4749
};
4850

51+
#define verifyFormat(...) _verifyFormat(__FILE__, __LINE__, __VA_ARGS__)
52+
4953
TEST_F(FormatTestTextProto, KeepsTopLevelEntriesFittingALine) {
5054
verifyFormat("field_a: OK field_b: OK field_c: OK field_d: OK field_e: OK");
5155
}

clang/unittests/Format/SortImportsTestJS.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,10 @@ class SortImportsTestJS : public ::testing::Test {
3333
return *Formatted;
3434
}
3535

36-
void verifySort(llvm::StringRef Expected, llvm::StringRef Code,
37-
unsigned Offset = 0, unsigned Length = 0) {
36+
void _verifySort(const char *File, int Line, llvm::StringRef Expected,
37+
llvm::StringRef Code, unsigned Offset = 0,
38+
unsigned Length = 0) {
39+
::testing::ScopedTrace t(File, Line, ::testing::Message() << Code.str());
3840
std::string Result = sort(Code, Offset, Length);
3941
EXPECT_EQ(Expected.str(), Result) << "Expected:\n"
4042
<< Expected << "\nActual:\n"
@@ -44,6 +46,8 @@ class SortImportsTestJS : public ::testing::Test {
4446
FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
4547
};
4648

49+
#define verifySort(...) _verifySort(__FILE__, __LINE__, __VA_ARGS__)
50+
4751
TEST_F(SortImportsTestJS, AlreadySorted) {
4852
verifySort("import {sym} from 'a';\n"
4953
"import {sym} from 'b';\n"

0 commit comments

Comments
 (0)