It seems namespace usage in unit tests is inconsistent.A) No namespaceExample: base/atomicops_unittest.ccB) Wrap everything with anonymous namespaceExample: base/barrier_closure_unittest.ccC) Wrap everything with the namespace same as the target codeExample: base/big_endian_unittest.ccWhat's recommended?
Google C++ style guid doesn't mention this.
A Googletest document mentions that C is required to use FRIEND_TEST macro.
--TAMURA Kent
Software Engineer, Google
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
It seems namespace usage in unit tests is inconsistent.A) No namespaceExample: base/atomicops_unittest.ccB) Wrap everything with anonymous namespaceExample: base/barrier_closure_unittest.ccC) Wrap everything with the namespace same as the target codeExample: base/big_endian_unittest.cc
In Blink repository, 134 files are wrap everything in anonymous namespace and have "using namespace blink".My concern is "using namespace" directive isn't match Google C++ coding style guide:
--
I found we had the same topic three years ago:
On Tue, Apr 21, 2015 at 6:10 PM, TAMURA, Kent <tk...@chromium.org> wrote:It seems namespace usage in unit tests is inconsistent.A) No namespaceExample: base/atomicops_unittest.ccB) Wrap everything with anonymous namespaceExample: base/barrier_closure_unittest.ccC) Wrap everything with the namespace same as the target codeExample: base/big_endian_unittest.ccWhat's recommended?My personal preference is to combine B) and C), e.g.,namespace foo {namespace {...
* Wrap test code with anonymous namespace additionally, like |namespace foo {\nnamespace {\n|.
You're right.I tested locally.- If I had duplicated test names not in anonymous namespaces, I had link errors.- If I had duplicated test names in anonymous namespaces, I had no link errors and no runtime errors on running the test binary. --gtest_filter=<the duplicated name> looked to run both of the tests. It's confusing.So, I correct as follows:* Wrap helper functions/classes in test files with anonymous namespace additionally, like |namespace foo {\nnamespace {\n|.- it's recommended to avoid ODR violation.- We shouldn't wrap test fixture class and tests
We have the same problem with tests in different namespaces (e.g. base vs. base::i18n), so forbidding anonymous namespace doesn't solve the problem.