@@ -76,7 +76,7 @@ for simplicity we just say that it cannot start with `_`.).
...
@@ -76,7 +76,7 @@ for simplicity we just say that it cannot start with `_`.).
It may seem fine for `TestCaseName` and `TestName` to contain `_` in the
It may seem fine for `TestCaseName` and `TestName` to contain `_` in the
middle. However, consider this:
middle. However, consider this:
``` cpp
```c++
TEST(Time,Flies_Like_An_Arrow){...}
TEST(Time,Flies_Like_An_Arrow){...}
TEST(Time_Flies,Like_An_Arrow){...}
TEST(Time_Flies,Like_An_Arrow){...}
```
```
...
@@ -242,7 +242,7 @@ of this approach:
...
@@ -242,7 +242,7 @@ of this approach:
1. Throwing in a destructor is undefined behavior in C++. Not using exceptions means Google Test's assertions are safe to use in destructors.
1. Throwing in a destructor is undefined behavior in C++. Not using exceptions means Google Test's assertions are safe to use in destructors.
1. The `EXPECT_*` family of macros will continue even after a failure, allowing multiple failures in a `TEST` to be reported in a single run. This is a popular feature, as in C++ the edit-compile-test cycle is usually quite long and being able to fixing more than one thing at a time is a blessing.
1. The `EXPECT_*` family of macros will continue even after a failure, allowing multiple failures in a `TEST` to be reported in a single run. This is a popular feature, as in C++ the edit-compile-test cycle is usually quite long and being able to fixing more than one thing at a time is a blessing.
1. If assertions are implemented using exceptions, a test may falsely ignore a failure if it's caught by user code:
1. If assertions are implemented using exceptions, a test may falsely ignore a failure if it's caught by user code:
``` cpp
```c++
try{...ASSERT_TRUE(...)...}
try{...ASSERT_TRUE(...)...}
catch(...){...}
catch(...){...}
```
```
...
@@ -259,13 +259,13 @@ macro for both cases. One possibility is to provide only one macro
...
@@ -259,13 +259,13 @@ macro for both cases. One possibility is to provide only one macro
for tests with fixtures, and require the user to define an empty
for tests with fixtures, and require the user to define an empty
fixture sometimes:
fixture sometimes:
``` cpp
```c++
classFooTest:public::testing::Test{};
classFooTest:public::testing::Test{};
TEST_F(FooTest,DoesThis){...}
TEST_F(FooTest,DoesThis){...}
```
```
or
or
``` cpp
```c++
typedef::testing::TestFooTest;
typedef::testing::TestFooTest;
TEST_F(FooTest,DoesThat){...}
TEST_F(FooTest,DoesThat){...}
...
@@ -293,7 +293,7 @@ possibly allows. In particular:
...
@@ -293,7 +293,7 @@ possibly allows. In particular:
* The runner-style requires to split the information into two pieces: the definition of the death test itself, and the specification for the runner on how to run the death test and what to expect. The death test would be written in C++, while the runner spec may or may not be. A user needs to carefully keep the two in sync. `ASSERT_DEATH(statement, expected_message)` specifies all necessary information in one place, in one language, without boilerplate code. It is very declarative.
* The runner-style requires to split the information into two pieces: the definition of the death test itself, and the specification for the runner on how to run the death test and what to expect. The death test would be written in C++, while the runner spec may or may not be. A user needs to carefully keep the two in sync. `ASSERT_DEATH(statement, expected_message)` specifies all necessary information in one place, in one language, without boilerplate code. It is very declarative.
*`ASSERT_DEATH` has a similar syntax and error-reporting semantics as other Google Test assertions, and thus is easy to learn.
*`ASSERT_DEATH` has a similar syntax and error-reporting semantics as other Google Test assertions, and thus is easy to learn.
*`ASSERT_DEATH` can be mixed with other assertions and other logic at your will. You are not limited to one death test per test method. For example, you can write something like:
*`ASSERT_DEATH` can be mixed with other assertions and other logic at your will. You are not limited to one death test per test method. For example, you can write something like:
``` cpp
```c++
if(FooCondition()){
if(FooCondition()){
ASSERT_DEATH(Bar(),"blah");
ASSERT_DEATH(Bar(),"blah");
}else{
}else{
...
@@ -302,7 +302,7 @@ possibly allows. In particular:
...
@@ -302,7 +302,7 @@ possibly allows. In particular:
```
```
If you prefer one death test per test method, you can write your tests in that style too, but we don't want to impose that on the users. The fewer artificial limitations the better.
If you prefer one death test per test method, you can write your tests in that style too, but we don't want to impose that on the users. The fewer artificial limitations the better.
*`ASSERT_DEATH` can reference local variables in the current function, and you can decide how many death tests you want based on run-time information. For example,
*`ASSERT_DEATH` can reference local variables in the current function, and you can decide how many death tests you want based on run-time information. For example,
``` cpp
```c++
constintcount=GetCount();// Only known at run time.
constintcount=GetCount();// Only known at run time.
for(inti=1;i<=count;i++){
for(inti=1;i<=count;i++){
ASSERT_DEATH({
ASSERT_DEATH({
...
@@ -335,7 +335,7 @@ as running in a parallel universe, more or less.
...
@@ -335,7 +335,7 @@ as running in a parallel universe, more or less.
If your class has a static data member:
If your class has a static data member:
``` cpp
```c++
// foo.h
// foo.h
classFoo{
classFoo{
...
...
...
@@ -345,7 +345,7 @@ class Foo {
...
@@ -345,7 +345,7 @@ class Foo {
You also need to define it _outside_ of the class body in `foo.cc`:
You also need to define it _outside_ of the class body in `foo.cc`:
``` cpp
```c++
constintFoo::kBar;// No initializer here.
constintFoo::kBar;// No initializer here.
```
```
...
@@ -376,7 +376,7 @@ to write tests using each derived fixture.
...
@@ -376,7 +376,7 @@ to write tests using each derived fixture.
Typically, your code looks like this:
Typically, your code looks like this:
``` cpp
```c++
// Defines a base test fixture.
// Defines a base test fixture.
classBaseTest:public::testing::Test{
classBaseTest:public::testing::Test{
protected:
protected:
...
@@ -476,7 +476,7 @@ explicitly telling the compiler which version to pick.
...
@@ -476,7 +476,7 @@ explicitly telling the compiler which version to pick.