Index: test/clang-apply-replacements/Inputs/basic/file1.yaml =================================================================== --- test/clang-apply-replacements/Inputs/basic/file1.yaml +++ test/clang-apply-replacements/Inputs/basic/file1.yaml @@ -2,6 +2,9 @@ MainSourceFile: source1.cpp Diagnostics: - DiagnosticName: test-basic + Message: Fix + FilePath: $(path)/basic.h + FileOffset: 242 Replacements: - FilePath: $(path)/basic.h Offset: 242 Index: test/clang-apply-replacements/Inputs/basic/file2.yaml =================================================================== --- test/clang-apply-replacements/Inputs/basic/file2.yaml +++ test/clang-apply-replacements/Inputs/basic/file2.yaml @@ -2,6 +2,9 @@ MainSourceFile: source2.cpp Diagnostics: - DiagnosticName: test-basic + Message: Fix + FilePath: $(path)/basic.h + FileOffset: 148 Replacements: - FilePath: $(path)/basic.h Offset: 148 Index: test/clang-apply-replacements/Inputs/conflict/file1.yaml =================================================================== --- test/clang-apply-replacements/Inputs/conflict/file1.yaml +++ test/clang-apply-replacements/Inputs/conflict/file1.yaml @@ -2,6 +2,9 @@ MainSourceFile: source1.cpp Diagnostics: - DiagnosticName: test-conflict + Message: Fix + FilePath: $(path)/common.h + FileOffset: 106 Replacements: - FilePath: $(path)/common.h Offset: 106 Index: test/clang-apply-replacements/Inputs/conflict/file2.yaml =================================================================== --- test/clang-apply-replacements/Inputs/conflict/file2.yaml +++ test/clang-apply-replacements/Inputs/conflict/file2.yaml @@ -2,6 +2,9 @@ MainSourceFile: source2.cpp Diagnostics: - DiagnosticName: test-conflict + Message: Fix + FilePath: $(path)/common.h + FileOffset: 106 Replacements: - FilePath: $(path)/common.h Offset: 106 Index: test/clang-apply-replacements/Inputs/conflict/file3.yaml =================================================================== --- test/clang-apply-replacements/Inputs/conflict/file3.yaml +++ test/clang-apply-replacements/Inputs/conflict/file3.yaml @@ -2,6 +2,9 @@ MainSourceFile: source1.cpp Diagnostics: - DiagnosticName: test-conflict + Message: Fix + FilePath: $(path)/common.h + FileOffset: 169 Replacements: - FilePath: $(path)/common.h Offset: 169 Index: test/clang-apply-replacements/Inputs/crlf/file1.yaml =================================================================== --- test/clang-apply-replacements/Inputs/crlf/file1.yaml +++ test/clang-apply-replacements/Inputs/crlf/file1.yaml @@ -2,6 +2,9 @@ MainSourceFile: source1.cpp Diagnostics: - DiagnosticName: test-crlf + Message: Fix + FilePath: $(path)/crlf.cpp + FileOffset: 79 Replacements: - FilePath: $(path)/crlf.cpp Offset: 79 Index: test/clang-apply-replacements/Inputs/format/no.yaml =================================================================== --- test/clang-apply-replacements/Inputs/format/no.yaml +++ test/clang-apply-replacements/Inputs/format/no.yaml @@ -2,6 +2,9 @@ MainSourceFile: no.cpp Diagnostics: - DiagnosticName: test-no + Message: Fix + FilePath: $(path)/no.cpp + FileOffset: 94 Replacements: - FilePath: $(path)/no.cpp Offset: 94 Index: test/clang-apply-replacements/Inputs/format/yes.yaml =================================================================== --- test/clang-apply-replacements/Inputs/format/yes.yaml +++ test/clang-apply-replacements/Inputs/format/yes.yaml @@ -4,6 +4,9 @@ MainSourceFile: yes.cpp Diagnostics: - DiagnosticName: test-yes + Message: Fix + FilePath: $(path)/yes.cpp + FileOffset: 494 Replacements: - FilePath: $(path)/yes.cpp Offset: 494 Index: unittests/clang-apply-replacements/ApplyReplacementsTest.cpp =================================================================== --- /dev/null +++ unittests/clang-apply-replacements/ApplyReplacementsTest.cpp @@ -0,0 +1,49 @@ +//===- clang-apply-replacements/ApplyReplacementsTest.cpp ----------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "clang-apply-replacements/Tooling/ApplyReplacements.h" +#include "gtest/gtest.h" + +using namespace clang::replace; +using namespace llvm; + +namespace clang { +namespace tooling { + +static TUDiagnostics makeTUDiagnostics(const std::string &MainSourceFile, + StringRef DiagnosticName, + const DiagnosticMessage &Message, + const StringMap &Replacements, + StringRef BuildDirectory) { + TUDiagnostics TUs; + TUs.push_back({ MainSourceFile, + { { DiagnosticName, Message, Replacements, {}, + Diagnostic::Warning, BuildDirectory } } + }); + return TUs; +} + +// Test to ensure diagnostics with no fixes, will be merged correctly +// before applying. +TEST(ApplyReplacementsTest, mergeDiagnosticsWithNoFixes) { + IntrusiveRefCntPtr DiagOpts(new DiagnosticOptions()); + DiagnosticsEngine Diagnostics( + IntrusiveRefCntPtr(new DiagnosticIDs()), DiagOpts.get()); + FileManager Files((FileSystemOptions())); + SourceManager SM(Diagnostics, Files); + TUDiagnostics TUs = makeTUDiagnostics("path/to/source.cpp", "diagnostic", + {}, {}, "path/to"); + FileToReplacementsMap ReplacementsMap; + + EXPECT_TRUE(mergeAndDeduplicate(TUs, ReplacementsMap, SM)); + EXPECT_TRUE(ReplacementsMap.empty()); +} + +} // end namespace tooling +} // end namespace clang Index: unittests/clang-apply-replacements/CMakeLists.txt =================================================================== --- unittests/clang-apply-replacements/CMakeLists.txt +++ unittests/clang-apply-replacements/CMakeLists.txt @@ -8,6 +8,7 @@ ) add_extra_unittest(ClangApplyReplacementsTests + ApplyReplacementsTest.cpp ReformattingTest.cpp )