Skip to content

Commit

Permalink
googletest: Add testonly alias of :gtest for testonly cc_libraries to…
Browse files Browse the repository at this point in the history
… use.

While a testonly library can certainly depend on a non-testonly library, gtest
itself is logically testonly, but is not tagged as such for historical
reasons. Having a testonly target allows gradual migrations towards a
testonly-only world.

PiperOrigin-RevId: 731807655
Change-Id: Ie16f17fb74b80bb6200767a3ac5bafa424162146
  • Loading branch information
pizzud authored and copybara-github committed Feb 27, 2025
1 parent 144d335 commit 7218908
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ cc_library(
)

# Google Test including Google Mock

# For an actual test, use `gtest` and also `gtest_main` if you depend on gtest's
# main(). For a library, use `gtest_for_library` instead if the library can be
# testonly.
cc_library(
name = "gtest",
srcs = glob(
Expand Down Expand Up @@ -167,6 +171,16 @@ cc_library(
}),
)

# `gtest`, but testonly. See guidance on `gtest` for when to use this.
alias(
name = "gtest_for_library",
actual = ":gtest",
testonly = True,
)

# Implements main() for tests using gtest. Prefer to depend on `gtest` as well
# to ensure compliance with the layering_check Bazel feature where only the
# direct hdrs values are available.
cc_library(
name = "gtest_main",
srcs = ["googlemock/src/gmock_main.cc"],
Expand Down

0 comments on commit 7218908

Please sign in to comment.