mirror of
https://github.com/google/googletest.git
synced 2025-12-06 16:57:00 +08:00
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:
parent
175c1b55cf
commit
35b75a2cba
@ -1448,17 +1448,19 @@ are two cases to consider:
|
|||||||
To test them, we use the following special techniques:
|
To test them, we use the following special techniques:
|
||||||
|
|
||||||
* Both static functions and definitions/declarations in an unnamed namespace
|
* Both static functions and definitions/declarations in an unnamed namespace
|
||||||
are only visible within the same translation unit. To test them, you can
|
are only visible within the same translation unit. To test them, move the
|
||||||
`#include` the entire `.cc` file being tested in your `*_test.cc` file.
|
private code into the `foo::internal` namespace, where `foo` is the
|
||||||
(#including `.cc` files is not a good way to reuse code - you should not do
|
namespace your project normally uses, and put the private declarations in a
|
||||||
this in production code!)
|
`*-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
|
{: .callout .note}
|
||||||
`foo::internal` namespace, where `foo` is the namespace your project
|
NOTE: It is also technically *possible* to `#include` the entire `.cc` file
|
||||||
normally uses, and put the private declarations in a `*-internal.h` file.
|
being tested in your `*_test.cc` file to test static functions and
|
||||||
Your production `.cc` files and your tests are allowed to include this
|
definitions/declarations in an unnamed namespace. However, this technique is
|
||||||
internal header, but your clients are not. This way, you can fully test your
|
**not recommended** by this documentation and it is only presented here for the
|
||||||
internal implementation without leaking it to your clients.
|
sake of completeness.
|
||||||
|
|
||||||
* Private class members are only accessible from within the class or by
|
* Private class members are only accessible from within the class or by
|
||||||
friends. To access a class' private members, you can declare your test
|
friends. To access a class' private members, you can declare your test
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user