Skip to content

Commit

Permalink
dwyu: Make sure includes in toplevel libraries are correctly recognized.
Browse files Browse the repository at this point in the history
  • Loading branch information
hzeller committed Aug 31, 2024
1 parent 80d5ee5 commit a054c04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bant/tool/dwyu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ bool IsHeaderInList(std::string_view header,
// so we always need to prepend that prefix_path.
for (const std::string_view list_item : list) {
if (header.ends_with(list_item) && // cheap first test before strcat
absl::StrCat(prefix_path, "/", list_item) == header) {
(header == list_item ||
absl::StrCat(prefix_path, "/", list_item) == header)) {
return true;
}
}
Expand Down
20 changes: 20 additions & 0 deletions bant/tool/dwyu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,26 @@ cc_library(
}
}

TEST(DWYUTest, ToplevelIncludesWithoutPrefixSlashWork) {
ParsedProjectTestUtil pp;
pp.Add("//", R"(
cc_library(
name = "foo",
srcs = ["foo.cc"],
hdrs = ["foo.h"]
)
)");

{
DWYUTestFixture tester(pp.project());
tester.AddSource("foo.h", "");
tester.AddSource("foo.cc", R"(
#include "foo.h"
)");
tester.RunForTarget("//:foo");
}
}

TEST(DWYUTest, ChooseMinimalDependencySetIfMultipleLibrariesProvideHeader) {
ParsedProjectTestUtil pp;
pp.Add("//path", R"(
Expand Down

0 comments on commit a054c04

Please sign in to comment.