Googletest export

Editorial cleanup of the "write the main function" section

PiperOrigin-RevId: 277102507
This commit is contained in:
Abseil Team 2019-10-28 14:09:47 -04:00 committed by vslashg
parent 755f853c6b
commit 2bee6da24e

View File

@ -491,15 +491,18 @@ You can start from this boilerplate:
```c++ ```c++
#include "this/package/foo.h" #include "this/package/foo.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
namespace my {
namespace project {
namespace { namespace {
// The fixture for testing class Foo. // The fixture for testing class Foo.
class FooTest : public ::testing::Test { class FooTest : public ::testing::Test {
protected: protected:
// You can remove any or all of the following functions if its body // You can remove any or all of the following functions if their bodies would
// is empty. // be empty.
FooTest() { FooTest() {
// You can do set-up work for each test here. // You can do set-up work for each test here.
@ -522,7 +525,8 @@ class FooTest : public ::testing::Test {
// before the destructor). // before the destructor).
} }
// Objects declared here can be used by all tests in the test suite for Foo. // Class members declared here can be used by all tests in the test suite
// for Foo.
}; };
// Tests that the Foo::Bar() method does Abc. // Tests that the Foo::Bar() method does Abc.
@ -539,6 +543,8 @@ TEST_F(FooTest, DoesXyz) {
} }
} // namespace } // namespace
} // namespace project
} // namespace my
int main(int argc, char **argv) { int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv); ::testing::InitGoogleTest(&argc, argv);
@ -555,10 +561,10 @@ the [AdvancedGuide](advanced.md). You **must** call this function before calling
On Windows, `InitGoogleTest()` also works with wide strings, so it can be used On Windows, `InitGoogleTest()` also works with wide strings, so it can be used
in programs compiled in `UNICODE` mode as well. in programs compiled in `UNICODE` mode as well.
But maybe you think that writing all those main() functions is too much work? We But maybe you think that writing all those `main` functions is too much work? We
agree with you completely, and that's why Google Test provides a basic agree with you completely, and that's why Google Test provides a basic
implementation of main(). If it fits your needs, then just link your test with implementation of main(). If it fits your needs, then just link your test with
gtest\_main library and you are good to go. the `gtest_main` library and you are good to go.
NOTE: `ParseGUnitFlags()` is deprecated in favor of `InitGoogleTest()`. NOTE: `ParseGUnitFlags()` is deprecated in favor of `InitGoogleTest()`.