Skip to content

Commit

Permalink
Add test to show that visible alias can point to invisible library.
Browse files Browse the repository at this point in the history
If an alias is used to point to a library, the visibility of the
alias determines if a library can be added.
  • Loading branch information
hzeller committed Jul 2, 2024
1 parent 0dc034f commit 2650675
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions bant/tool/dwyu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,40 @@ cc_library(
}
}

// Often aliasse are used to redirect to otherwise private libraries. The
// visibility of the alias determines if it can be linked.
TEST(DWYUTest, VisibilityOfAliasAllowsToBeLinkedEvenIfTargetIsNotVisible) {
ParsedProjectTestUtil pp;
pp.Add("//some/lib", R"(
alias(
name = "visible_foo_alias",
actual = ":private_foo",
visibility = ["//visibility:public"], # points to lib with correct header
)
cc_library(
name = "private_foo",
srcs = ["foo.cc"],
hdrs = ["foo.h"],
visibility = ["//visibility:private"], # can't use this directly
)
)");

pp.Add("//user", R"(
cc_binary(
name = "hello",
srcs = ["hello.cc"],
)
)");

{
DWYUTestFixture tester(pp.project());
tester.ExpectAdd("//some/lib:visible_foo_alias");
tester.AddSource("user/hello.cc", R"(#include "some/lib/foo.h")");
tester.RunForTarget("//user:hello");
}
}

// If we can't expand, err on the 'public' side.
TEST(DWYUTest, ConsiderUnknownVisibilityVariableToAllowPublic) {
ParsedProjectTestUtil pp;
Expand Down

0 comments on commit 2650675

Please sign in to comment.