Although the following paragraph explains there is a better solution, having this technique in the bullet point seems to suggest that this technique is considered as a valid alternative. It would be better to drop it or make it clear that this technique is not recommended.

PiperOrigin-RevId: 771116391
Change-Id: I753560115ed65e8858b749473935df57b6a50488
This commit is contained in:
Abseil Team
2025-06-13 09:13:10 -07:00
committed by Copybara-Service
parent 175c1b55cf
commit 35b75a2cba

View File

@@ -1448,17 +1448,19 @@ are two cases to consider:
To test them, we use the following special techniques:
* Both static functions and definitions/declarations in an unnamed namespace
are only visible within the same translation unit. To test them, you can
`#include` the entire `.cc` file being tested in your `*_test.cc` file.
(#including `.cc` files is not a good way to reuse code - you should not do
this in production code!)
are only visible within the same translation unit. To test them, move the
private code into the `foo::internal` namespace, where `foo` is the
namespace your project normally uses, and put the private declarations in a
`*-internal.h` file. Your production `.cc` files and your tests are allowed
to include this internal header, but your clients are not. This way, you can
fully test your internal implementation without leaking it to your clients.
However, a better approach is to move the private code into the
`foo::internal` namespace, where `foo` is the namespace your project
normally uses, and put the private declarations in a `*-internal.h` file.
Your production `.cc` files and your tests are allowed to include this
internal header, but your clients are not. This way, you can fully test your
internal implementation without leaking it to your clients.
{: .callout .note}
NOTE: It is also technically *possible* to `#include` the entire `.cc` file
being tested in your `*_test.cc` file to test static functions and
definitions/declarations in an unnamed namespace. However, this technique is
**not recommended** by this documentation and it is only presented here for the
sake of completeness.
* Private class members are only accessible from within the class or by
friends. To access a class' private members, you can declare your test