Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add some more SetupEnvironment failure/skip demos
These were used in illustrating the issue discussed in: google/googletest#2189 . While here, remove a duplicate "#define" for `GTEST_THREADSAFE` and move setup_environment_fail_demo.cc to setup_environment_nonfatal_fail_demo.cc, since I now know that I was testing for non-fatal failures (which don't cause the test to abort). Contributed (in part) by @asomers.
- Loading branch information
Showing
5 changed files
with
76 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
24 changes: 24 additions & 0 deletions
24
programming/c++/gtest/setup_environment_fatal_fail_demo.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <gtest/gtest.h> | ||
|
||
class SetupEnvironment : public testing::Environment { | ||
public: | ||
void SetUp() override { | ||
GTEST_FAIL() << "Calling a fatal failure"; | ||
} | ||
}; | ||
|
||
TEST(Test, AlwaysPasses) { | ||
EXPECT_EQ(true, true); | ||
} | ||
|
||
TEST(Test, AlwaysFails) { | ||
EXPECT_EQ(true, false); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
testing::InitGoogleTest(&argc, argv); | ||
|
||
testing::AddGlobalTestEnvironment(new SetupEnvironment()); | ||
|
||
return (RUN_ALL_TESTS()); | ||
} |
24 changes: 24 additions & 0 deletions
24
programming/c++/gtest/setup_environment_nonfatal_fail_demo.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <gtest/gtest.h> | ||
|
||
class SetupEnvironment : public ::testing::Environment { | ||
public: | ||
void SetUp() override { | ||
EXPECT_EQ(false, true); | ||
} | ||
}; | ||
|
||
TEST(Test, AlwaysPasses) { | ||
EXPECT_EQ(true, true); | ||
} | ||
|
||
TEST(Test, AlwaysFails) { | ||
EXPECT_EQ(true, false); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
testing::InitGoogleTest(&argc, argv); | ||
|
||
testing::AddGlobalTestEnvironment(new SetupEnvironment()); | ||
|
||
return RUN_ALL_TESTS(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <gtest/gtest.h> | ||
|
||
class SetupEnvironment : public testing::Environment { | ||
public: | ||
void SetUp() override { | ||
GTEST_SKIP() << "Skipping the entire environment"; | ||
} | ||
}; | ||
|
||
TEST(Test, AlwaysPasses) { | ||
EXPECT_EQ(true, true); | ||
} | ||
|
||
TEST(Test, AlwaysFails) { | ||
EXPECT_EQ(true, false); | ||
} | ||
|
||
int main(int argc, char **argv) { | ||
testing::InitGoogleTest(&argc, argv); | ||
|
||
testing::AddGlobalTestEnvironment(new SetupEnvironment()); | ||
|
||
return (RUN_ALL_TESTS()); | ||
} |