[include-fixer] Don't add missing header if the unindentified symbol isn't from the main file.
Summary:
The further solution is to add the missing header to the file where the
symbol comes from.
Reviewers: bkramer
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D20950
llvm-svn: 271660
diff --git a/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp b/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp
index 37a741a..4b9c117 100644
--- a/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp
+++ b/clang-tools-extra/unittests/include-fixer/IncludeFixerTest.cpp
@@ -44,6 +44,8 @@
llvm::MemoryBuffer::getMemBuffer("\n"));
InMemoryFileSystem->addFile("dir/otherdir/qux.h", 0,
llvm::MemoryBuffer::getMemBuffer("\n"));
+ InMemoryFileSystem->addFile("header.h", 0,
+ llvm::MemoryBuffer::getMemBuffer("bar b;"));
return Invocation.run();
}
@@ -186,6 +188,11 @@
runIncludeFixer("int test = a::b::Green;\n"));
}
+TEST(IncludeFixer, IgnoreSymbolFromHeader) {
+ std::string Code = "#include \"header.h\"";
+ EXPECT_EQ(Code, runIncludeFixer(Code));
+}
+
// FIXME: add test cases for inserting and sorting multiple headers when
// include-fixer supports multiple headers insertion.
TEST(IncludeFixer, InsertAndSortSingleHeader) {