summaryrefslogtreecommitdiffstats
path: root/googletest/src
diff options
context:
space:
mode:
authorEnji Cooper <yaneurabeya@gmail.com>2019-03-30 04:36:28 (GMT)
committerEnji Cooper <yaneurabeya@gmail.com>2019-03-30 18:38:03 (GMT)
commit67c75ff8baf4228e857c09d3aaacd3f1ddf53a8f (patch)
treea53f146cd4c51e7a51b0e2ca73e6c1e1bdcdaff2 /googletest/src
parent5b752b1947bbb4df571848a1afad00f9b06f30e0 (diff)
downloadgoogletest-67c75ff8baf4228e857c09d3aaacd3f1ddf53a8f.zip
googletest-67c75ff8baf4228e857c09d3aaacd3f1ddf53a8f.tar.gz
googletest-67c75ff8baf4228e857c09d3aaacd3f1ddf53a8f.tar.bz2
Handle GTEST_SKIP() when calling `Environment::SetUp()`refs/pull/2203/head
gtest prior to this change would completely ignore `GTEST_SKIP()` if called in `Environment::SetUp()`, instead of bailing out early, unlike `Test::SetUp()`, which would cause the tests themselves to be skipped. The only way (prior to this change) to skip the tests would be to trigger a fatal error via `GTEST_FAIL()`. Desirable behavior, in this case, when dealing with `Environment::SetUp()` is to check for prerequisites on a system (example, kernel supports a particular featureset, e.g., capsicum), and skip the tests. The alternatives prior to this change would be undesirable: - Failing sends the wrong message to the test user, as the result of the tests is indeterminate, not failed. - Having to add per-test class abstractions that override `SetUp()` to test for the capsicum feature set, then skip all of the tests in their respective SetUp fixtures, would be a lot of human and computational work; checking for the feature would need to be done for all of the tests, instead of once for all of the tests. For those reasons, making `Environment::SetUp()` handle `GTEST_SKIP()`, by not executing the testcases, is the most desirable solution. In order to properly diagnose what happened when running the tests if they are skipped, print out the diagnostics in an ad hoc manner. Update the documentation to note this change and integrate a new test, gtest_skip_in_environment_setup_test, into the test suite. This change addresses #2189. Signed-off-by: Enji Cooper <yaneurabeya@gmail.com>
Diffstat (limited to 'googletest/src')
-rw-r--r--googletest/src/gtest.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 0a04860..745f075 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -5263,9 +5263,23 @@ bool UnitTestImpl::RunAllTests() {
ForEach(environments_, SetUpEnvironment);
repeater->OnEnvironmentsSetUpEnd(*parent_);
- // Runs the tests only if there was no fatal failure during global
- // set-up.
- if (!Test::HasFatalFailure()) {
+ // Runs the tests only if there was no fatal failure or skip triggered
+ // during global set-up.
+ if (Test::IsSkipped()) {
+ // Emit diagnostics when global set-up calls skip, as it will not be
+ // emitted by default.
+ TestResult& test_result =
+ *internal::GetUnitTestImpl()->current_test_result();
+ for (int j = 0; j < test_result.total_part_count(); ++j) {
+ const TestPartResult& test_part_result =
+ test_result.GetTestPartResult(j);
+ if (test_part_result.type() == TestPartResult::kSkip) {
+ const std::string& result = test_part_result.message();
+ printf("%s\n", result.c_str());
+ }
+ }
+ fflush(stdout);
+ } else if (!Test::HasFatalFailure()) {
for (int test_index = 0; test_index < total_test_suite_count();
test_index++) {
GetMutableSuiteCase(test_index)->Run();