diff options
author | Eric Liu <ioeric@google.com> | 2016-07-11 13:53:12 +0000 |
---|---|---|
committer | Eric Liu <ioeric@google.com> | 2016-07-11 13:53:12 +0000 |
commit | 4f8d99433da80161f85988052f96bc7dc621c4eb (patch) | |
tree | e926d386edbf05c0d8346483a53ac49678e2f284 /clang/unittests/Format/FormatTest.cpp | |
parent | 4d8500396454334975ab8bb6766d6521c5140b13 (diff) | |
download | bcm5719-llvm-4f8d99433da80161f85988052f96bc7dc621c4eb.tar.gz bcm5719-llvm-4f8d99433da80161f85988052f96bc7dc621c4eb.zip |
Make tooling::applyAllReplacements return llvm::Expected<string> instead of empty string to indicate potential error.
Summary:
return llvm::Expected<> to carry error status and error information.
This is the first step towards introducing "Error" into tooling::Replacements.
Reviewers: djasper, klimek
Subscribers: ioeric, klimek, cfe-commits
Differential Revision: http://reviews.llvm.org/D21601
llvm-svn: 275062
Diffstat (limited to 'clang/unittests/Format/FormatTest.cpp')
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 218243380c3..8d46ba6efcf 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -47,10 +47,10 @@ protected: EXPECT_EQ(ExpectedIncompleteFormat, IncompleteFormat) << Code << "\n\n"; } ReplacementCount = Replaces.size(); - std::string Result = applyAllReplacements(Code, Replaces); - EXPECT_NE("", Result); - DEBUG(llvm::errs() << "\n" << Result << "\n\n"); - return Result; + auto Result = applyAllReplacements(Code, Replaces); + EXPECT_TRUE(static_cast<bool>(Result)); + DEBUG(llvm::errs() << "\n" << *Result << "\n\n"); + return *Result; } FormatStyle getLLVMStyleWithColumns(unsigned ColumnLimit) { @@ -11553,8 +11553,12 @@ TEST_F(ReplacementTest, FormatCodeAfterReplacements) { format::FormatStyle Style = format::getLLVMStyle(); Style.ColumnLimit = 20; // Set column limit to 20 to increase readibility. - EXPECT_EQ(Expected, applyAllReplacements( - Code, formatReplacements(Code, Replaces, Style))); + auto FormattedReplaces = formatReplacements(Code, Replaces, Style); + EXPECT_TRUE(static_cast<bool>(FormattedReplaces)) + << llvm::toString(FormattedReplaces.takeError()) << "\n"; + auto Result = applyAllReplacements(Code, *FormattedReplaces); + EXPECT_TRUE(static_cast<bool>(Result)); + EXPECT_EQ(Expected, *Result); } TEST_F(ReplacementTest, SortIncludesAfterReplacement) { @@ -11578,8 +11582,12 @@ TEST_F(ReplacementTest, SortIncludesAfterReplacement) { format::FormatStyle Style = format::getLLVMStyle(); Style.SortIncludes = true; - auto FinalReplaces = formatReplacements(Code, Replaces, Style); - EXPECT_EQ(Expected, applyAllReplacements(Code, FinalReplaces)); + auto FormattedReplaces = formatReplacements(Code, Replaces, Style); + EXPECT_TRUE(static_cast<bool>(FormattedReplaces)) + << llvm::toString(FormattedReplaces.takeError()) << "\n"; + auto Result = applyAllReplacements(Code, *FormattedReplaces); + EXPECT_TRUE(static_cast<bool>(Result)); + EXPECT_EQ(Expected, *Result); } } // end namespace |