mirror of
https://github.com/intrepidcs/libicsneo.git
synced 2026-08-05 09:28:40 +02:00
ThirdParty: Update included gtest
This commit is contained in:
+75
-3
@@ -28,12 +28,15 @@
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
#
|
||||
# Author: misterg@google.com (Gennadiy Civil)
|
||||
#
|
||||
# Bazel BUILD for The Google C++ Testing Framework (Google Test)
|
||||
|
||||
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_test")
|
||||
load("@rules_python//python:defs.bzl", "py_library", "py_test")
|
||||
|
||||
licenses(["notice"])
|
||||
|
||||
package(default_visibility = ["//:__subpackages__"])
|
||||
|
||||
#on windows exclude gtest-tuple.h
|
||||
cc_test(
|
||||
name = "gtest_all_test",
|
||||
@@ -53,15 +56,19 @@ cc_test(
|
||||
"gtest-listener_test.cc",
|
||||
"gtest-unittest-api_test.cc",
|
||||
"googletest-param-test-test.cc",
|
||||
"googletest-param-test2-test.cc",
|
||||
"googletest-catch-exceptions-test_.cc",
|
||||
"googletest-color-test_.cc",
|
||||
"googletest-env-var-test_.cc",
|
||||
"googletest-failfast-unittest_.cc",
|
||||
"googletest-filter-unittest_.cc",
|
||||
"googletest-global-environment-unittest_.cc",
|
||||
"googletest-break-on-failure-unittest_.cc",
|
||||
"googletest-listener-test.cc",
|
||||
"googletest-output-test_.cc",
|
||||
"googletest-list-tests-unittest_.cc",
|
||||
"googletest-shuffle-test_.cc",
|
||||
"googletest-setuptestsuite-test_.cc",
|
||||
"googletest-uninitialized-test_.cc",
|
||||
"googletest-death-test_ex_test.cc",
|
||||
"googletest-param-test-test",
|
||||
@@ -76,6 +83,10 @@ cc_test(
|
||||
copts = select({
|
||||
"//:windows": ["-DGTEST_USE_OWN_TR1_TUPLE=0"],
|
||||
"//conditions:default": ["-DGTEST_USE_OWN_TR1_TUPLE=1"],
|
||||
}) + select({
|
||||
# Ensure MSVC treats source files as UTF-8 encoded.
|
||||
"//:msvc_compiler": ["-utf-8"],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
includes = [
|
||||
"googletest",
|
||||
@@ -139,7 +150,6 @@ cc_test(
|
||||
name = "gtest_unittest",
|
||||
size = "small",
|
||||
srcs = ["gtest_unittest.cc"],
|
||||
args = ["--heap_check=strict"],
|
||||
shard_count = 2,
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
@@ -150,6 +160,7 @@ py_library(
|
||||
name = "gtest_test_utils",
|
||||
testonly = 1,
|
||||
srcs = ["gtest_test_utils.py"],
|
||||
imports = ["."],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
@@ -219,6 +230,21 @@ py_test(
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-failfast-unittest_",
|
||||
testonly = 1,
|
||||
srcs = ["googletest-failfast-unittest_.cc"],
|
||||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "googletest-failfast-unittest",
|
||||
size = "medium",
|
||||
srcs = ["googletest-failfast-unittest.py"],
|
||||
data = [":googletest-failfast-unittest_"],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-filter-unittest_",
|
||||
testonly = 1,
|
||||
@@ -234,6 +260,21 @@ py_test(
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-global-environment-unittest_",
|
||||
testonly = 1,
|
||||
srcs = ["googletest-global-environment-unittest_.cc"],
|
||||
deps = ["//:gtest"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "googletest-global-environment-unittest",
|
||||
size = "medium",
|
||||
srcs = ["googletest-global-environment-unittest.py"],
|
||||
data = [":googletest-global-environment-unittest_"],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-break-on-failure-unittest_",
|
||||
testonly = 1,
|
||||
@@ -292,6 +333,14 @@ cc_test(
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "gtest_skip_check_output_test",
|
||||
size = "small",
|
||||
srcs = ["gtest_skip_check_output_test.py"],
|
||||
data = [":gtest_skip_test"],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "gtest_skip_environment_check_output_test",
|
||||
size = "small",
|
||||
@@ -412,6 +461,21 @@ py_test(
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-setuptestsuite-test_",
|
||||
testonly = 1,
|
||||
srcs = ["googletest-setuptestsuite-test_.cc"],
|
||||
deps = ["//:gtest_main"],
|
||||
)
|
||||
|
||||
py_test(
|
||||
name = "googletest-setuptestsuite-test",
|
||||
size = "medium",
|
||||
srcs = ["googletest-setuptestsuite-test.py"],
|
||||
data = [":googletest-setuptestsuite-test_"],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
cc_binary(
|
||||
name = "googletest-uninitialized-test_",
|
||||
testonly = 1,
|
||||
@@ -506,6 +570,10 @@ py_test(
|
||||
size = "small",
|
||||
srcs = ["googletest-param-test-invalid-name1-test.py"],
|
||||
data = [":googletest-param-test-invalid-name1-test_"],
|
||||
tags = [
|
||||
"no_test_msvc2015",
|
||||
"no_test_msvc2017",
|
||||
],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
@@ -514,5 +582,9 @@ py_test(
|
||||
size = "small",
|
||||
srcs = ["googletest-param-test-invalid-name2-test.py"],
|
||||
data = [":googletest-param-test-invalid-name2-test_"],
|
||||
tags = [
|
||||
"no_test_msvc2015",
|
||||
"no_test_msvc2017",
|
||||
],
|
||||
deps = [":gtest_test_utils"],
|
||||
)
|
||||
|
||||
Vendored
Regular → Executable
Vendored
Regular → Executable
Vendored
Regular → Executable
+91
-9
@@ -41,7 +41,9 @@ using testing::internal::AlwaysTrue;
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
# include <fcntl.h> // For O_BINARY
|
||||
# include <direct.h> // For chdir().
|
||||
# include <io.h>
|
||||
# else
|
||||
# include <unistd.h>
|
||||
# include <sys/wait.h> // For waitpid.
|
||||
@@ -139,7 +141,7 @@ class TestForDeathTest : public testing::Test {
|
||||
DieInside("MemberFunction");
|
||||
}
|
||||
|
||||
// True iff MemberFunction() should die.
|
||||
// True if and only if MemberFunction() should die.
|
||||
bool should_die_;
|
||||
const FilePath original_dir_;
|
||||
};
|
||||
@@ -156,7 +158,7 @@ class MayDie {
|
||||
}
|
||||
|
||||
private:
|
||||
// True iff MemberFunction() should die.
|
||||
// True if and only if MemberFunction() should die.
|
||||
bool should_die_;
|
||||
};
|
||||
|
||||
@@ -202,6 +204,26 @@ int DieInDebugElse12(int* sideeffect) {
|
||||
return 12;
|
||||
}
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
// Death in dbg due to Windows CRT assertion failure, not opt.
|
||||
int DieInCRTDebugElse12(int* sideeffect) {
|
||||
if (sideeffect) *sideeffect = 12;
|
||||
|
||||
// Create an invalid fd by closing a valid one
|
||||
int fdpipe[2];
|
||||
EXPECT_EQ(_pipe(fdpipe, 256, O_BINARY), 0);
|
||||
EXPECT_EQ(_close(fdpipe[0]), 0);
|
||||
EXPECT_EQ(_close(fdpipe[1]), 0);
|
||||
|
||||
// _dup() should crash in debug mode
|
||||
EXPECT_EQ(_dup(fdpipe[0]), -1);
|
||||
|
||||
return 12;
|
||||
}
|
||||
|
||||
#endif // GTEST_OS_WINDOWS
|
||||
|
||||
# if GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
// Tests the ExitedWithCode predicate.
|
||||
@@ -276,6 +298,13 @@ TEST(ExitStatusPredicateTest, KilledBySignal) {
|
||||
|
||||
# endif // GTEST_OS_WINDOWS || GTEST_OS_FUCHSIA
|
||||
|
||||
// The following code intentionally tests a suboptimal syntax.
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-else"
|
||||
#pragma GCC diagnostic ignored "-Wempty-body"
|
||||
#pragma GCC diagnostic ignored "-Wpragmas"
|
||||
#endif
|
||||
// Tests that the death test macros expand to code which may or may not
|
||||
// be followed by operator<<, and that in either case the complete text
|
||||
// comprises only a single C++ statement.
|
||||
@@ -299,6 +328,9 @@ TEST_F(TestForDeathTest, SingleStatement) {
|
||||
else
|
||||
EXPECT_DEATH(_exit(1), "") << 1 << 2 << 3;
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
# if GTEST_USES_PCRE
|
||||
|
||||
@@ -369,17 +401,19 @@ void SigprofAction(int, siginfo_t*, void*) { /* no op */ }
|
||||
|
||||
// Sets SIGPROF action and ITIMER_PROF timer (interval: 1ms).
|
||||
void SetSigprofActionAndTimer() {
|
||||
struct itimerval timer;
|
||||
timer.it_interval.tv_sec = 0;
|
||||
timer.it_interval.tv_usec = 1;
|
||||
timer.it_value = timer.it_interval;
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
|
||||
struct sigaction signal_action;
|
||||
memset(&signal_action, 0, sizeof(signal_action));
|
||||
sigemptyset(&signal_action.sa_mask);
|
||||
signal_action.sa_sigaction = SigprofAction;
|
||||
signal_action.sa_flags = SA_RESTART | SA_SIGINFO;
|
||||
ASSERT_EQ(0, sigaction(SIGPROF, &signal_action, nullptr));
|
||||
// timer comes second, to avoid SIGPROF premature delivery, as suggested at
|
||||
// https://www.gnu.org/software/libc/manual/html_node/Setting-an-Alarm.html
|
||||
struct itimerval timer;
|
||||
timer.it_interval.tv_sec = 0;
|
||||
timer.it_interval.tv_usec = 1;
|
||||
timer.it_value = timer.it_interval;
|
||||
ASSERT_EQ(0, setitimer(ITIMER_PROF, &timer, nullptr));
|
||||
}
|
||||
|
||||
// Disables ITIMER_PROF timer and ignores SIGPROF signal.
|
||||
@@ -551,8 +585,8 @@ TEST_F(TestForDeathTest, ErrorMessageMismatch) {
|
||||
}, "died but not with expected error");
|
||||
}
|
||||
|
||||
// On exit, *aborted will be true iff the EXPECT_DEATH() statement
|
||||
// aborted the function.
|
||||
// On exit, *aborted will be true if and only if the EXPECT_DEATH()
|
||||
// statement aborted the function.
|
||||
void ExpectDeathTestHelper(bool* aborted) {
|
||||
*aborted = true;
|
||||
EXPECT_DEATH(DieIf(false), "DieIf"); // This assertion should fail.
|
||||
@@ -632,6 +666,40 @@ TEST_F(TestForDeathTest, TestExpectDebugDeath) {
|
||||
# endif
|
||||
}
|
||||
|
||||
# if GTEST_OS_WINDOWS
|
||||
|
||||
// Tests that EXPECT_DEBUG_DEATH works as expected when in debug mode
|
||||
// the Windows CRT crashes the process with an assertion failure.
|
||||
// 1. Asserts on death.
|
||||
// 2. Has no side effect (doesn't pop up a window or wait for user input).
|
||||
//
|
||||
// And in opt mode, it:
|
||||
// 1. Has side effects but does not assert.
|
||||
TEST_F(TestForDeathTest, CRTDebugDeath) {
|
||||
int sideeffect = 0;
|
||||
|
||||
// Put the regex in a local variable to make sure we don't get an "unused"
|
||||
// warning in opt mode.
|
||||
const char* regex = "dup.* : Assertion failed";
|
||||
|
||||
EXPECT_DEBUG_DEATH(DieInCRTDebugElse12(&sideeffect), regex)
|
||||
<< "Must accept a streamed message";
|
||||
|
||||
# ifdef NDEBUG
|
||||
|
||||
// Checks that the assignment occurs in opt mode (sideeffect).
|
||||
EXPECT_EQ(12, sideeffect);
|
||||
|
||||
# else
|
||||
|
||||
// Checks that the assignment does not occur in dbg mode (no sideeffect).
|
||||
EXPECT_EQ(0, sideeffect);
|
||||
|
||||
# endif
|
||||
}
|
||||
|
||||
# endif // GTEST_OS_WINDOWS
|
||||
|
||||
// Tests that ASSERT_DEBUG_DEATH works as expected, that is, you can stream a
|
||||
// message to it, and in debug mode it:
|
||||
// 1. Asserts on death.
|
||||
@@ -1318,7 +1386,11 @@ void DieWithMessage(const char* message) {
|
||||
TEST(MatcherDeathTest, DoesNotBreakBareRegexMatching) {
|
||||
// googletest tests this, of course; here we ensure that including googlemock
|
||||
// has not broken it.
|
||||
#if GTEST_USES_POSIX_RE
|
||||
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I d[aeiou]e");
|
||||
#else
|
||||
EXPECT_DEATH(DieWithMessage("O, I die, Horatio."), "I di?e");
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(MatcherDeathTest, MonomorphicMatcherMatches) {
|
||||
@@ -1406,6 +1478,13 @@ TEST(ConditionalDeathMacrosTest, AssertDeatDoesNotReturnhIfUnsupported) {
|
||||
|
||||
namespace {
|
||||
|
||||
// The following code intentionally tests a suboptimal syntax.
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-else"
|
||||
#pragma GCC diagnostic ignored "-Wempty-body"
|
||||
#pragma GCC diagnostic ignored "-Wpragmas"
|
||||
#endif
|
||||
// Tests that the death test macros expand to code which may or may not
|
||||
// be followed by operator<<, and that in either case the complete text
|
||||
// comprises only a single C++ statement.
|
||||
@@ -1431,6 +1510,9 @@ TEST(ConditionalDeathMacrosSyntaxDeathTest, SingleStatement) {
|
||||
else
|
||||
EXPECT_DEATH_IF_SUPPORTED(_exit(1), "") << 1 << 2 << 3;
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
// Tests that conditional death test macros expand to code which interacts
|
||||
// well with switch statements.
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ TEST(CxxExceptionDeathTest, ExceptionIsFailure) {
|
||||
|
||||
class TestException : public std::exception {
|
||||
public:
|
||||
const char* what() const throw() override { return "exceptional message"; }
|
||||
const char* what() const noexcept override { return "exceptional message"; }
|
||||
};
|
||||
|
||||
TEST(CxxExceptionDeathTest, PrintsMessageForStdExceptions) {
|
||||
|
||||
Vendored
Regular → Executable
+3
@@ -85,9 +85,12 @@ class GTestEnvVarTest(gtest_test_utils.TestCase):
|
||||
|
||||
TestFlag('break_on_failure', '1', '0')
|
||||
TestFlag('color', 'yes', 'auto')
|
||||
SetEnvVar('TESTBRIDGE_TEST_RUNNER_FAIL_FAST', None) # For 'fail_fast' test
|
||||
TestFlag('fail_fast', '1', '0')
|
||||
TestFlag('filter', 'FooTest.Bar', '*')
|
||||
SetEnvVar('XML_OUTPUT_FILE', None) # For 'output' test
|
||||
TestFlag('output', 'xml:tmp/foo.xml', '')
|
||||
TestFlag('brief', '1', '0')
|
||||
TestFlag('print_time', '0', '1')
|
||||
TestFlag('repeat', '999', '1')
|
||||
TestFlag('throw_on_failure', '1', '0')
|
||||
|
||||
@@ -72,6 +72,11 @@ void PrintFlag(const char* flag) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(flag, "fail_fast") == 0) {
|
||||
cout << GTEST_FLAG(fail_fast);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(flag, "filter") == 0) {
|
||||
cout << GTEST_FLAG(filter);
|
||||
return;
|
||||
@@ -82,6 +87,11 @@ void PrintFlag(const char* flag) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(flag, "brief") == 0) {
|
||||
cout << GTEST_FLAG(brief);
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(flag, "print_time") == 0) {
|
||||
cout << GTEST_FLAG(print_time);
|
||||
return;
|
||||
|
||||
+410
@@ -0,0 +1,410 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2020 Google Inc. All Rights Reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""Unit test for Google Test fail_fast.
|
||||
|
||||
A user can specify if a Google Test program should continue test execution
|
||||
after a test failure via the GTEST_FAIL_FAST environment variable or the
|
||||
--gtest_fail_fast flag. The default value of the flag can also be changed
|
||||
by Bazel fail fast environment variable TESTBRIDGE_TEST_RUNNER_FAIL_FAST.
|
||||
|
||||
This script tests such functionality by invoking googletest-failfast-unittest_
|
||||
(a program written with Google Test) with different environments and command
|
||||
line flags.
|
||||
"""
|
||||
|
||||
import os
|
||||
import gtest_test_utils
|
||||
|
||||
# Constants.
|
||||
|
||||
# Bazel testbridge environment variable for fail fast
|
||||
BAZEL_FAIL_FAST_ENV_VAR = 'TESTBRIDGE_TEST_RUNNER_FAIL_FAST'
|
||||
|
||||
# The environment variable for specifying fail fast.
|
||||
FAIL_FAST_ENV_VAR = 'GTEST_FAIL_FAST'
|
||||
|
||||
# The command line flag for specifying fail fast.
|
||||
FAIL_FAST_FLAG = 'gtest_fail_fast'
|
||||
|
||||
# The command line flag to run disabled tests.
|
||||
RUN_DISABLED_FLAG = 'gtest_also_run_disabled_tests'
|
||||
|
||||
# The command line flag for specifying a filter.
|
||||
FILTER_FLAG = 'gtest_filter'
|
||||
|
||||
# Command to run the googletest-failfast-unittest_ program.
|
||||
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
||||
'googletest-failfast-unittest_')
|
||||
|
||||
# The command line flag to tell Google Test to output the list of tests it
|
||||
# will run.
|
||||
LIST_TESTS_FLAG = '--gtest_list_tests'
|
||||
|
||||
# Indicates whether Google Test supports death tests.
|
||||
SUPPORTS_DEATH_TESTS = 'HasDeathTest' in gtest_test_utils.Subprocess(
|
||||
[COMMAND, LIST_TESTS_FLAG]).output
|
||||
|
||||
# Utilities.
|
||||
|
||||
environ = os.environ.copy()
|
||||
|
||||
|
||||
def SetEnvVar(env_var, value):
|
||||
"""Sets the env variable to 'value'; unsets it when 'value' is None."""
|
||||
|
||||
if value is not None:
|
||||
environ[env_var] = value
|
||||
elif env_var in environ:
|
||||
del environ[env_var]
|
||||
|
||||
|
||||
def RunAndReturnOutput(test_suite=None, fail_fast=None, run_disabled=False):
|
||||
"""Runs the test program and returns its output."""
|
||||
|
||||
args = []
|
||||
xml_path = os.path.join(gtest_test_utils.GetTempDir(),
|
||||
'.GTestFailFastUnitTest.xml')
|
||||
args += ['--gtest_output=xml:' + xml_path]
|
||||
if fail_fast is not None:
|
||||
if isinstance(fail_fast, str):
|
||||
args += ['--%s=%s' % (FAIL_FAST_FLAG, fail_fast)]
|
||||
elif fail_fast:
|
||||
args += ['--%s' % FAIL_FAST_FLAG]
|
||||
else:
|
||||
args += ['--no%s' % FAIL_FAST_FLAG]
|
||||
if test_suite:
|
||||
args += ['--%s=%s.*' % (FILTER_FLAG, test_suite)]
|
||||
if run_disabled:
|
||||
args += ['--%s' % RUN_DISABLED_FLAG]
|
||||
txt_out = gtest_test_utils.Subprocess([COMMAND] + args, env=environ).output
|
||||
with open(xml_path) as xml_file:
|
||||
return txt_out, xml_file.read()
|
||||
|
||||
|
||||
# The unit test.
|
||||
class GTestFailFastUnitTest(gtest_test_utils.TestCase):
|
||||
"""Tests the env variable or the command line flag for fail_fast."""
|
||||
|
||||
def testDefaultBehavior(self):
|
||||
"""Tests the behavior of not specifying the fail_fast."""
|
||||
|
||||
txt, _ = RunAndReturnOutput()
|
||||
self.assertIn('22 FAILED TEST', txt)
|
||||
|
||||
def testGoogletestFlag(self):
|
||||
txt, _ = RunAndReturnOutput(test_suite='HasSimpleTest', fail_fast=True)
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
|
||||
txt, _ = RunAndReturnOutput(test_suite='HasSimpleTest', fail_fast=False)
|
||||
self.assertIn('4 FAILED TEST', txt)
|
||||
self.assertNotIn('[ SKIPPED ]', txt)
|
||||
|
||||
def testGoogletestEnvVar(self):
|
||||
"""Tests the behavior of specifying fail_fast via Googletest env var."""
|
||||
|
||||
try:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, '1')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, '0')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('4 FAILED TEST', txt)
|
||||
self.assertNotIn('[ SKIPPED ]', txt)
|
||||
finally:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, None)
|
||||
|
||||
def testBazelEnvVar(self):
|
||||
"""Tests the behavior of specifying fail_fast via Bazel testbridge."""
|
||||
|
||||
try:
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, '1')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, '0')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('4 FAILED TEST', txt)
|
||||
self.assertNotIn('[ SKIPPED ]', txt)
|
||||
finally:
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, None)
|
||||
|
||||
def testFlagOverridesEnvVar(self):
|
||||
"""Tests precedence of flag over env var."""
|
||||
|
||||
try:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, '0')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest', True)
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
finally:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, None)
|
||||
|
||||
def testGoogletestEnvVarOverridesBazelEnvVar(self):
|
||||
"""Tests that the Googletest native env var over Bazel testbridge."""
|
||||
|
||||
try:
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, '0')
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, '1')
|
||||
txt, _ = RunAndReturnOutput('HasSimpleTest')
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
finally:
|
||||
SetEnvVar(FAIL_FAST_ENV_VAR, None)
|
||||
SetEnvVar(BAZEL_FAIL_FAST_ENV_VAR, None)
|
||||
|
||||
def testEventListener(self):
|
||||
txt, _ = RunAndReturnOutput(test_suite='HasSkipTest', fail_fast=True)
|
||||
self.assertIn('1 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 3 tests', txt)
|
||||
for expected_count, callback in [(1, 'OnTestSuiteStart'),
|
||||
(5, 'OnTestStart'),
|
||||
(5, 'OnTestEnd'),
|
||||
(5, 'OnTestPartResult'),
|
||||
(1, 'OnTestSuiteEnd')]:
|
||||
self.assertEqual(
|
||||
expected_count, txt.count(callback),
|
||||
'Expected %d calls to callback %s match count on output: %s ' %
|
||||
(expected_count, callback, txt))
|
||||
|
||||
txt, _ = RunAndReturnOutput(test_suite='HasSkipTest', fail_fast=False)
|
||||
self.assertIn('3 FAILED TEST', txt)
|
||||
self.assertIn('[ SKIPPED ] 1 test', txt)
|
||||
for expected_count, callback in [(1, 'OnTestSuiteStart'),
|
||||
(5, 'OnTestStart'),
|
||||
(5, 'OnTestEnd'),
|
||||
(5, 'OnTestPartResult'),
|
||||
(1, 'OnTestSuiteEnd')]:
|
||||
self.assertEqual(
|
||||
expected_count, txt.count(callback),
|
||||
'Expected %d calls to callback %s match count on output: %s ' %
|
||||
(expected_count, callback, txt))
|
||||
|
||||
def assertXmlResultCount(self, result, count, xml):
|
||||
self.assertEqual(
|
||||
count, xml.count('result="%s"' % result),
|
||||
'Expected \'result="%s"\' match count of %s: %s ' %
|
||||
(result, count, xml))
|
||||
|
||||
def assertXmlStatusCount(self, status, count, xml):
|
||||
self.assertEqual(
|
||||
count, xml.count('status="%s"' % status),
|
||||
'Expected \'status="%s"\' match count of %s: %s ' %
|
||||
(status, count, xml))
|
||||
|
||||
def assertFailFastXmlAndTxtOutput(self,
|
||||
fail_fast,
|
||||
test_suite,
|
||||
passed_count,
|
||||
failure_count,
|
||||
skipped_count,
|
||||
suppressed_count,
|
||||
run_disabled=False):
|
||||
"""Assert XML and text output of a test execution."""
|
||||
|
||||
txt, xml = RunAndReturnOutput(test_suite, fail_fast, run_disabled)
|
||||
if failure_count > 0:
|
||||
self.assertIn('%s FAILED TEST' % failure_count, txt)
|
||||
if suppressed_count > 0:
|
||||
self.assertIn('%s DISABLED TEST' % suppressed_count, txt)
|
||||
if skipped_count > 0:
|
||||
self.assertIn('[ SKIPPED ] %s tests' % skipped_count, txt)
|
||||
self.assertXmlStatusCount('run',
|
||||
passed_count + failure_count + skipped_count, xml)
|
||||
self.assertXmlStatusCount('notrun', suppressed_count, xml)
|
||||
self.assertXmlResultCount('completed', passed_count + failure_count, xml)
|
||||
self.assertXmlResultCount('skipped', skipped_count, xml)
|
||||
self.assertXmlResultCount('suppressed', suppressed_count, xml)
|
||||
|
||||
def assertFailFastBehavior(self,
|
||||
test_suite,
|
||||
passed_count,
|
||||
failure_count,
|
||||
skipped_count,
|
||||
suppressed_count,
|
||||
run_disabled=False):
|
||||
"""Assert --fail_fast via flag."""
|
||||
|
||||
for fail_fast in ('true', '1', 't', True):
|
||||
self.assertFailFastXmlAndTxtOutput(fail_fast, test_suite, passed_count,
|
||||
failure_count, skipped_count,
|
||||
suppressed_count, run_disabled)
|
||||
|
||||
def assertNotFailFastBehavior(self,
|
||||
test_suite,
|
||||
passed_count,
|
||||
failure_count,
|
||||
skipped_count,
|
||||
suppressed_count,
|
||||
run_disabled=False):
|
||||
"""Assert --nofail_fast via flag."""
|
||||
|
||||
for fail_fast in ('false', '0', 'f', False):
|
||||
self.assertFailFastXmlAndTxtOutput(fail_fast, test_suite, passed_count,
|
||||
failure_count, skipped_count,
|
||||
suppressed_count, run_disabled)
|
||||
|
||||
def testFlag_HasFixtureTest(self):
|
||||
"""Tests the behavior of fail_fast and TEST_F."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasFixtureTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasFixtureTest',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0)
|
||||
|
||||
def testFlag_HasSimpleTest(self):
|
||||
"""Tests the behavior of fail_fast and TEST."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasSimpleTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasSimpleTest',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0)
|
||||
|
||||
def testFlag_HasParametersTest(self):
|
||||
"""Tests the behavior of fail_fast and TEST_P."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasParametersSuite/HasParametersTest',
|
||||
passed_count=0,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasParametersSuite/HasParametersTest',
|
||||
passed_count=0,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0)
|
||||
|
||||
def testFlag_HasDisabledTest(self):
|
||||
"""Tests the behavior of fail_fast and Disabled test cases."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasDisabledTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=2,
|
||||
suppressed_count=1,
|
||||
run_disabled=False)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasDisabledTest',
|
||||
passed_count=1,
|
||||
failure_count=3,
|
||||
skipped_count=0,
|
||||
suppressed_count=1,
|
||||
run_disabled=False)
|
||||
|
||||
def testFlag_HasDisabledRunDisabledTest(self):
|
||||
"""Tests the behavior of fail_fast and Disabled test cases enabled."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasDisabledTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0,
|
||||
run_disabled=True)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasDisabledTest',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0,
|
||||
run_disabled=True)
|
||||
|
||||
def testFlag_HasDisabledSuiteTest(self):
|
||||
"""Tests the behavior of fail_fast and Disabled test suites."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='DISABLED_HasDisabledSuite',
|
||||
passed_count=0,
|
||||
failure_count=0,
|
||||
skipped_count=0,
|
||||
suppressed_count=5,
|
||||
run_disabled=False)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='DISABLED_HasDisabledSuite',
|
||||
passed_count=0,
|
||||
failure_count=0,
|
||||
skipped_count=0,
|
||||
suppressed_count=5,
|
||||
run_disabled=False)
|
||||
|
||||
def testFlag_HasDisabledSuiteRunDisabledTest(self):
|
||||
"""Tests the behavior of fail_fast and Disabled test suites enabled."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='DISABLED_HasDisabledSuite',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0,
|
||||
run_disabled=True)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='DISABLED_HasDisabledSuite',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0,
|
||||
run_disabled=True)
|
||||
|
||||
if SUPPORTS_DEATH_TESTS:
|
||||
|
||||
def testFlag_HasDeathTest(self):
|
||||
"""Tests the behavior of fail_fast and death tests."""
|
||||
self.assertFailFastBehavior(
|
||||
test_suite='HasDeathTest',
|
||||
passed_count=1,
|
||||
failure_count=1,
|
||||
skipped_count=3,
|
||||
suppressed_count=0)
|
||||
self.assertNotFailFastBehavior(
|
||||
test_suite='HasDeathTest',
|
||||
passed_count=1,
|
||||
failure_count=4,
|
||||
skipped_count=0,
|
||||
suppressed_count=0)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
+167
@@ -0,0 +1,167 @@
|
||||
// Copyright 2005, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
// Unit test for Google Test test filters.
|
||||
//
|
||||
// A user can specify which test(s) in a Google Test program to run via
|
||||
// either the GTEST_FILTER environment variable or the --gtest_filter
|
||||
// flag. This is used for testing such functionality.
|
||||
//
|
||||
// The program will be invoked from a Python unit test. Don't run it
|
||||
// directly.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Test HasFixtureTest.
|
||||
|
||||
class HasFixtureTest : public testing::Test {};
|
||||
|
||||
TEST_F(HasFixtureTest, Test0) {}
|
||||
|
||||
TEST_F(HasFixtureTest, Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST_F(HasFixtureTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST_F(HasFixtureTest, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST_F(HasFixtureTest, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
// Test HasSimpleTest.
|
||||
|
||||
TEST(HasSimpleTest, Test0) {}
|
||||
|
||||
TEST(HasSimpleTest, Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSimpleTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSimpleTest, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSimpleTest, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
// Test HasDisabledTest.
|
||||
|
||||
TEST(HasDisabledTest, Test0) {}
|
||||
|
||||
TEST(HasDisabledTest, DISABLED_Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasDisabledTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasDisabledTest, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasDisabledTest, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
// Test HasDeathTest
|
||||
|
||||
TEST(HasDeathTest, Test0) { EXPECT_DEATH_IF_SUPPORTED(exit(1), ".*"); }
|
||||
|
||||
TEST(HasDeathTest, Test1) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
|
||||
}
|
||||
|
||||
TEST(HasDeathTest, Test2) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
|
||||
}
|
||||
|
||||
TEST(HasDeathTest, Test3) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
|
||||
}
|
||||
|
||||
TEST(HasDeathTest, Test4) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(FAIL() << "Expected failure.", ".*");
|
||||
}
|
||||
|
||||
// Test DISABLED_HasDisabledSuite
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test0) {}
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(DISABLED_HasDisabledSuite, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
// Test HasParametersTest
|
||||
|
||||
class HasParametersTest : public testing::TestWithParam<int> {};
|
||||
|
||||
TEST_P(HasParametersTest, Test1) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST_P(HasParametersTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(HasParametersSuite, HasParametersTest,
|
||||
testing::Values(1, 2));
|
||||
|
||||
class MyTestListener : public ::testing::EmptyTestEventListener {
|
||||
void OnTestSuiteStart(const ::testing::TestSuite& test_suite) override {
|
||||
printf("We are in OnTestSuiteStart of %s.\n", test_suite.name());
|
||||
}
|
||||
|
||||
void OnTestStart(const ::testing::TestInfo& test_info) override {
|
||||
printf("We are in OnTestStart of %s.%s.\n", test_info.test_suite_name(),
|
||||
test_info.name());
|
||||
}
|
||||
|
||||
void OnTestPartResult(
|
||||
const ::testing::TestPartResult& test_part_result) override {
|
||||
printf("We are in OnTestPartResult %s:%d.\n", test_part_result.file_name(),
|
||||
test_part_result.line_number());
|
||||
}
|
||||
|
||||
void OnTestEnd(const ::testing::TestInfo& test_info) override {
|
||||
printf("We are in OnTestEnd of %s.%s.\n", test_info.test_suite_name(),
|
||||
test_info.name());
|
||||
}
|
||||
|
||||
void OnTestSuiteEnd(const ::testing::TestSuite& test_suite) override {
|
||||
printf("We are in OnTestSuiteEnd of %s.\n", test_suite.name());
|
||||
}
|
||||
};
|
||||
|
||||
TEST(HasSkipTest, Test0) { SUCCEED() << "Expected success."; }
|
||||
|
||||
TEST(HasSkipTest, Test1) { GTEST_SKIP() << "Expected skip."; }
|
||||
|
||||
TEST(HasSkipTest, Test2) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSkipTest, Test3) { FAIL() << "Expected failure."; }
|
||||
|
||||
TEST(HasSkipTest, Test4) { FAIL() << "Expected failure."; }
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
::testing::UnitTest::GetInstance()->listeners().Append(new MyTestListener());
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Vendored
Regular → Executable
+72
@@ -0,0 +1,72 @@
|
||||
# Copyright 2021 Google Inc. All Rights Reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""Unit test for Google Test's global test environment behavior.
|
||||
|
||||
A user can specify a global test environment via
|
||||
testing::AddGlobalTestEnvironment. Failures in the global environment should
|
||||
result in all unit tests being skipped.
|
||||
|
||||
This script tests such functionality by invoking
|
||||
googletest-global-environment-unittest_ (a program written with Google Test).
|
||||
"""
|
||||
|
||||
import gtest_test_utils
|
||||
|
||||
|
||||
def RunAndReturnOutput():
|
||||
"""Runs the test program and returns its output."""
|
||||
|
||||
return gtest_test_utils.Subprocess([
|
||||
gtest_test_utils.GetTestExecutablePath(
|
||||
'googletest-global-environment-unittest_')
|
||||
]).output
|
||||
|
||||
|
||||
class GTestGlobalEnvironmentUnitTest(gtest_test_utils.TestCase):
|
||||
"""Tests global test environment failures."""
|
||||
|
||||
def testEnvironmentSetUpFails(self):
|
||||
"""Tests the behavior of not specifying the fail_fast."""
|
||||
|
||||
# Run the test.
|
||||
txt = RunAndReturnOutput()
|
||||
|
||||
# We should see the text of the global environment setup error.
|
||||
self.assertIn('Canned environment setup error', txt)
|
||||
|
||||
# Our test should have been skipped due to the error, and not treated as a
|
||||
# pass.
|
||||
self.assertIn('[ SKIPPED ] 1 test', txt)
|
||||
self.assertIn('[ PASSED ] 0 tests', txt)
|
||||
|
||||
# The test case shouldn't have been run.
|
||||
self.assertNotIn('Unexpected call', txt)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
// Copyright 2005, Google Inc.
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are
|
||||
// met:
|
||||
//
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above
|
||||
// copyright notice, this list of conditions and the following disclaimer
|
||||
// in the documentation and/or other materials provided with the
|
||||
// distribution.
|
||||
// * Neither the name of Google Inc. nor the names of its
|
||||
// contributors may be used to endorse or promote products derived from
|
||||
// this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// Unit test for Google Test global test environments.
|
||||
//
|
||||
// The program will be invoked from a Python unit test. Don't run it
|
||||
// directly.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// An environment that always fails in its SetUp method.
|
||||
class FailingEnvironment final : public ::testing::Environment {
|
||||
public:
|
||||
void SetUp() override { FAIL() << "Canned environment setup error"; }
|
||||
};
|
||||
|
||||
// Register the environment.
|
||||
auto* const g_environment_ =
|
||||
::testing::AddGlobalTestEnvironment(new FailingEnvironment);
|
||||
|
||||
// A test that doesn't actually run.
|
||||
TEST(SomeTest, DoesFoo) { FAIL() << "Unexpected call"; }
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
+6
@@ -67,11 +67,14 @@ EXPECTED_1 = {
|
||||
0,
|
||||
u'time':
|
||||
u'*',
|
||||
u'timestamp':
|
||||
u'*',
|
||||
u'testsuite': [{
|
||||
u'name': u'TestSomeProperties',
|
||||
u'status': u'RUN',
|
||||
u'result': u'COMPLETED',
|
||||
u'time': u'*',
|
||||
u'timestamp': u'*',
|
||||
u'classname': u'PropertyOne',
|
||||
u'SetUpProp': u'1',
|
||||
u'TestSomeProperty': u'1',
|
||||
@@ -108,10 +111,13 @@ EXPECTED_2 = {
|
||||
0,
|
||||
u'time':
|
||||
u'*',
|
||||
u'timestamp':
|
||||
u'*',
|
||||
u'testsuite': [{
|
||||
u'name': u'TestSomeProperties',
|
||||
u'status': u'RUN',
|
||||
u'result': u'COMPLETED',
|
||||
u'timestamp': u'*',
|
||||
u'time': u'*',
|
||||
u'classname': u'PropertyTwo',
|
||||
u'SetUpProp': u'2',
|
||||
|
||||
+538
-448
File diff suppressed because it is too large
Load Diff
Vendored
Regular → Executable
+112
-1
@@ -35,6 +35,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "gtest/internal/custom/gtest.h"
|
||||
|
||||
using ::testing::AddGlobalTestEnvironment;
|
||||
using ::testing::Environment;
|
||||
@@ -76,10 +77,11 @@ class EventRecordingListener : public TestEventListener {
|
||||
void OnEnvironmentsSetUpEnd(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsSetUpEnd"));
|
||||
}
|
||||
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
void OnTestCaseStart(const TestCase& /*test_case*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestCaseStart"));
|
||||
}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
void OnTestStart(const TestInfo& /*test_info*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestStart"));
|
||||
@@ -93,9 +95,11 @@ class EventRecordingListener : public TestEventListener {
|
||||
g_events->push_back(GetFullMethodName("OnTestEnd"));
|
||||
}
|
||||
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
void OnTestCaseEnd(const TestCase& /*test_case*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnTestCaseEnd"));
|
||||
}
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
void OnEnvironmentsTearDownStart(const UnitTest& /*unit_test*/) override {
|
||||
g_events->push_back(GetFullMethodName("OnEnvironmentsTearDownStart"));
|
||||
@@ -283,6 +287,9 @@ int main(int argc, char **argv) {
|
||||
::testing::GTEST_FLAG(repeat) = 2;
|
||||
int ret_val = RUN_ALL_TESTS();
|
||||
|
||||
#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
// The deprecated OnTestSuiteStart/OnTestCaseStart events are included
|
||||
const char* const expected_events[] = {"1st.OnTestProgramStart",
|
||||
"2nd.OnTestProgramStart",
|
||||
"3rd.OnTestProgramStart",
|
||||
@@ -393,6 +400,110 @@ int main(int argc, char **argv) {
|
||||
"3rd.OnTestProgramEnd",
|
||||
"2nd.OnTestProgramEnd",
|
||||
"1st.OnTestProgramEnd"};
|
||||
#else
|
||||
const char* const expected_events[] = {"1st.OnTestProgramStart",
|
||||
"2nd.OnTestProgramStart",
|
||||
"3rd.OnTestProgramStart",
|
||||
"1st.OnTestIterationStart(0)",
|
||||
"2nd.OnTestIterationStart(0)",
|
||||
"3rd.OnTestIterationStart(0)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"3rd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"3rd.OnEnvironmentsSetUpEnd",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"3rd.OnTestSuiteStart",
|
||||
"ListenerTest::SetUpTestSuite",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestSuite",
|
||||
"3rd.OnTestSuiteEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"3rd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"3rd.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"3rd.OnTestIterationEnd(0)",
|
||||
"2nd.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationEnd(0)",
|
||||
"1st.OnTestIterationStart(1)",
|
||||
"2nd.OnTestIterationStart(1)",
|
||||
"3rd.OnTestIterationStart(1)",
|
||||
"1st.OnEnvironmentsSetUpStart",
|
||||
"2nd.OnEnvironmentsSetUpStart",
|
||||
"3rd.OnEnvironmentsSetUpStart",
|
||||
"Environment::SetUp",
|
||||
"3rd.OnEnvironmentsSetUpEnd",
|
||||
"2nd.OnEnvironmentsSetUpEnd",
|
||||
"1st.OnEnvironmentsSetUpEnd",
|
||||
"3rd.OnTestSuiteStart",
|
||||
"ListenerTest::SetUpTestSuite",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"1st.OnTestStart",
|
||||
"2nd.OnTestStart",
|
||||
"3rd.OnTestStart",
|
||||
"ListenerTest::SetUp",
|
||||
"ListenerTest::* Test Body",
|
||||
"1st.OnTestPartResult",
|
||||
"2nd.OnTestPartResult",
|
||||
"3rd.OnTestPartResult",
|
||||
"ListenerTest::TearDown",
|
||||
"3rd.OnTestEnd",
|
||||
"2nd.OnTestEnd",
|
||||
"1st.OnTestEnd",
|
||||
"ListenerTest::TearDownTestSuite",
|
||||
"3rd.OnTestSuiteEnd",
|
||||
"1st.OnEnvironmentsTearDownStart",
|
||||
"2nd.OnEnvironmentsTearDownStart",
|
||||
"3rd.OnEnvironmentsTearDownStart",
|
||||
"Environment::TearDown",
|
||||
"3rd.OnEnvironmentsTearDownEnd",
|
||||
"2nd.OnEnvironmentsTearDownEnd",
|
||||
"1st.OnEnvironmentsTearDownEnd",
|
||||
"3rd.OnTestIterationEnd(1)",
|
||||
"2nd.OnTestIterationEnd(1)",
|
||||
"1st.OnTestIterationEnd(1)",
|
||||
"3rd.OnTestProgramEnd",
|
||||
"2nd.OnTestProgramEnd",
|
||||
"1st.OnTestProgramEnd"};
|
||||
#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_
|
||||
|
||||
VerifyResults(events,
|
||||
expected_events,
|
||||
|
||||
@@ -42,6 +42,9 @@
|
||||
# include <windows.h>
|
||||
#elif GTEST_OS_WINDOWS
|
||||
# include <direct.h>
|
||||
#elif GTEST_OS_OS2
|
||||
// For strcasecmp on OS/2
|
||||
#include <strings.h>
|
||||
#endif // GTEST_OS_WINDOWS_MOBILE
|
||||
|
||||
#include "src/gtest-internal-inl.h"
|
||||
|
||||
+48
-5
@@ -12,7 +12,7 @@ Expected equality of these values:
|
||||
3
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [mRunning 84 tests from 39 test suites.
|
||||
[0;32m[==========] [mRunning 88 tests from 41 test suites.
|
||||
[0;32m[----------] [mGlobal test environment set-up.
|
||||
FooEnvironment::SetUp() called.
|
||||
BarEnvironment::SetUp() called.
|
||||
@@ -966,6 +966,9 @@ Expected equality of these values:
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
|
||||
[0;32m[----------] [m1 test from EmptyBasenameParamInst
|
||||
[0;32m[ RUN ] [mEmptyBasenameParamInst.Passes/0
|
||||
[0;32m[ OK ] [mEmptyBasenameParamInst.Passes/0
|
||||
[0;32m[----------] [m2 tests from PrintingStrings/ParamTest
|
||||
[0;32m[ RUN ] [mPrintingStrings/ParamTest.Success/a
|
||||
[0;32m[ OK ] [mPrintingStrings/ParamTest.Success/a
|
||||
@@ -979,6 +982,43 @@ Expected failure
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
|
||||
[0;32m[----------] [m3 tests from GoogleTestVerification
|
||||
[0;32m[ RUN ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<NoTests>
|
||||
googletest-output-test_.cc:#: Failure
|
||||
Parameterized test suite NoTests is instantiated via INSTANTIATE_TEST_SUITE_P, but no tests are defined via TEST_P . No test cases will run.
|
||||
|
||||
Ideally, INSTANTIATE_TEST_SUITE_P should only ever be invoked from code that always depend on code that provides TEST_P. Failing to do so is often an indication of dead code, e.g. the last TEST_P was removed but the rest got left behind.
|
||||
|
||||
To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in:
|
||||
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NoTests);
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<NoTests>
|
||||
[0;32m[ RUN ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<DetectNotInstantiatedTest>
|
||||
googletest-output-test_.cc:#: Failure
|
||||
Parameterized test suite DetectNotInstantiatedTest is defined via TEST_P, but never instantiated. None of the test cases will run. Either no INSTANTIATE_TEST_SUITE_P is provided or the only ones provided expand to nothing.
|
||||
|
||||
Ideally, TEST_P definitions should only ever be included as part of binaries that intend to use them. (As opposed to, for example, being placed in a library that may be linked in to get other utilities.)
|
||||
|
||||
To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in:
|
||||
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DetectNotInstantiatedTest);
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<DetectNotInstantiatedTest>
|
||||
[0;32m[ RUN ] [mGoogleTestVerification.UninstantiatedTypeParameterizedTestSuite<DetectNotInstantiatedTypesTest>
|
||||
googletest-output-test_.cc:#: Failure
|
||||
Type parameterized test suite DetectNotInstantiatedTypesTest is defined via REGISTER_TYPED_TEST_SUITE_P, but never instantiated via INSTANTIATE_TYPED_TEST_SUITE_P. None of the test cases will run.
|
||||
|
||||
Ideally, TYPED_TEST_P definitions should only ever be included as part of binaries that intend to use them. (As opposed to, for example, being placed in a library that may be linked in to get other utilities.)
|
||||
|
||||
To suppress this error for this test suite, insert the following line (in a non-header) in the namespace it is defined in:
|
||||
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(DetectNotInstantiatedTypesTest);
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedTypeParameterizedTestSuite<DetectNotInstantiatedTypesTest>
|
||||
[0;32m[----------] [mGlobal test environment tear-down
|
||||
BarEnvironment::TearDown() called.
|
||||
googletest-output-test_.cc:#: Failure
|
||||
@@ -992,9 +1032,9 @@ Failed
|
||||
Expected fatal failure.
|
||||
Stack trace: (omitted)
|
||||
|
||||
[0;32m[==========] [m84 tests from 39 test suites ran.
|
||||
[0;32m[ PASSED ] [m30 tests.
|
||||
[0;31m[ FAILED ] [m54 tests, listed below:
|
||||
[0;32m[==========] [m88 tests from 41 test suites ran.
|
||||
[0;32m[ PASSED ] [m31 tests.
|
||||
[0;31m[ FAILED ] [m57 tests, listed below:
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.EscapesStringOperands
|
||||
[0;31m[ FAILED ] [mNonfatalFailureTest.DiffForLongStrings
|
||||
[0;31m[ FAILED ] [mFatalFailureTest.FatalFailureInSubroutine
|
||||
@@ -1049,8 +1089,11 @@ Stack trace: (omitted)
|
||||
[0;31m[ FAILED ] [mBadDynamicFixture2.Derived
|
||||
[0;31m[ FAILED ] [mPrintingFailingParams/FailingParamTest.Fails/0, where GetParam() = 2
|
||||
[0;31m[ FAILED ] [mPrintingStrings/ParamTest.Failure/a, where GetParam() = "a"
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<NoTests>
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedParameterizedTestSuite<DetectNotInstantiatedTest>
|
||||
[0;31m[ FAILED ] [mGoogleTestVerification.UninstantiatedTypeParameterizedTestSuite<DetectNotInstantiatedTypesTest>
|
||||
|
||||
54 FAILED TESTS
|
||||
57 FAILED TESTS
|
||||
[0;33m YOU HAVE 1 DISABLED TEST
|
||||
|
||||
[mNote: Google Test filter = FatalFailureTest.*:LoggingTest.*
|
||||
|
||||
Vendored
Regular → Executable
+2
-2
@@ -29,7 +29,7 @@
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""Tests the text output of Google C++ Testing and Mocking Framework.
|
||||
r"""Tests the text output of Google C++ Testing and Mocking Framework.
|
||||
|
||||
To update the golden file:
|
||||
googletest_output_test.py --build_dir=BUILD/DIR --gengolden
|
||||
@@ -331,7 +331,7 @@ if __name__ == '__main__':
|
||||
if CAN_GENERATE_GOLDEN_FILE:
|
||||
output = GetOutputOfAllCommands()
|
||||
golden_file = open(GOLDEN_PATH, 'wb')
|
||||
golden_file.write(output)
|
||||
golden_file.write(output.encode())
|
||||
golden_file.close()
|
||||
else:
|
||||
message = (
|
||||
|
||||
@@ -96,6 +96,14 @@ INSTANTIATE_TEST_SUITE_P(PrintingFailingParams,
|
||||
FailingParamTest,
|
||||
testing::Values(2));
|
||||
|
||||
// Tests that an empty value for the test suite basename yields just
|
||||
// the test name without any prior /
|
||||
class EmptyBasenameParamInst : public testing::TestWithParam<int> {};
|
||||
|
||||
TEST_P(EmptyBasenameParamInst, Passes) { EXPECT_EQ(1, GetParam()); }
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(, EmptyBasenameParamInst, testing::Values(1));
|
||||
|
||||
static const char kGoldenString[] = "\"Line\0 1\"\nLine 2";
|
||||
|
||||
TEST(NonfatalFailureTest, EscapesStringOperands) {
|
||||
@@ -468,63 +476,6 @@ TEST(GtestFailAtTest, MessageContainsSpecifiedFileAndLineNumber) {
|
||||
GTEST_FAIL_AT("foo.cc", 42) << "Expected fatal failure in foo.cc";
|
||||
}
|
||||
|
||||
#if GTEST_IS_THREADSAFE
|
||||
|
||||
// A unary function that may die.
|
||||
void DieIf(bool should_die) {
|
||||
GTEST_CHECK_(!should_die) << " - death inside DieIf().";
|
||||
}
|
||||
|
||||
// Tests running death tests in a multi-threaded context.
|
||||
|
||||
// Used for coordination between the main and the spawn thread.
|
||||
struct SpawnThreadNotifications {
|
||||
SpawnThreadNotifications() {}
|
||||
|
||||
Notification spawn_thread_started;
|
||||
Notification spawn_thread_ok_to_terminate;
|
||||
|
||||
private:
|
||||
GTEST_DISALLOW_COPY_AND_ASSIGN_(SpawnThreadNotifications);
|
||||
};
|
||||
|
||||
// The function to be executed in the thread spawn by the
|
||||
// MultipleThreads test (below).
|
||||
static void ThreadRoutine(SpawnThreadNotifications* notifications) {
|
||||
// Signals the main thread that this thread has started.
|
||||
notifications->spawn_thread_started.Notify();
|
||||
|
||||
// Waits for permission to finish from the main thread.
|
||||
notifications->spawn_thread_ok_to_terminate.WaitForNotification();
|
||||
}
|
||||
|
||||
// This is a death-test test, but it's not named with a DeathTest
|
||||
// suffix. It starts threads which might interfere with later
|
||||
// death tests, so it must run after all other death tests.
|
||||
class DeathTestAndMultiThreadsTest : public testing::Test {
|
||||
protected:
|
||||
// Starts a thread and waits for it to begin.
|
||||
void SetUp() override {
|
||||
thread_.reset(new ThreadWithParam<SpawnThreadNotifications*>(
|
||||
&ThreadRoutine, ¬ifications_, nullptr));
|
||||
notifications_.spawn_thread_started.WaitForNotification();
|
||||
}
|
||||
// Tells the thread to finish, and reaps it.
|
||||
// Depending on the version of the thread library in use,
|
||||
// a manager thread might still be left running that will interfere
|
||||
// with later death tests. This is unfortunate, but this class
|
||||
// cleans up after itself as best it can.
|
||||
void TearDown() override {
|
||||
notifications_.spawn_thread_ok_to_terminate.Notify();
|
||||
}
|
||||
|
||||
private:
|
||||
SpawnThreadNotifications notifications_;
|
||||
std::unique_ptr<ThreadWithParam<SpawnThreadNotifications*> > thread_;
|
||||
};
|
||||
|
||||
#endif // GTEST_IS_THREADSAFE
|
||||
|
||||
// The MixedUpTestSuiteTest test case verifies that Google Test will fail a
|
||||
// test if it uses a different fixture class than what other tests in
|
||||
// the same test case use. It deliberately contains two fixture
|
||||
@@ -782,8 +733,16 @@ INSTANTIATE_TEST_SUITE_P(PrintingStrings,
|
||||
testing::Values(std::string("a")),
|
||||
ParamNameFunc);
|
||||
|
||||
// This #ifdef block tests the output of typed tests.
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
// The case where a suite has INSTANTIATE_TEST_SUITE_P but not TEST_P.
|
||||
using NoTests = ParamTest;
|
||||
INSTANTIATE_TEST_SUITE_P(ThisIsOdd, NoTests, ::testing::Values("Hello"));
|
||||
|
||||
// fails under kErrorOnUninstantiatedParameterizedTest=true
|
||||
class DetectNotInstantiatedTest : public testing::TestWithParam<int> {};
|
||||
TEST_P(DetectNotInstantiatedTest, Used) { }
|
||||
|
||||
// This would make the test failure from the above go away.
|
||||
// INSTANTIATE_TEST_SUITE_P(Fix, DetectNotInstantiatedTest, testing::Values(1));
|
||||
|
||||
template <typename T>
|
||||
class TypedTest : public testing::Test {
|
||||
@@ -808,9 +767,9 @@ class TypedTestNames {
|
||||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int i) {
|
||||
if (testing::internal::IsSame<T, char>::value)
|
||||
if (std::is_same<T, char>::value)
|
||||
return std::string("char") + ::testing::PrintToString(i);
|
||||
if (testing::internal::IsSame<T, int>::value)
|
||||
if (std::is_same<T, int>::value)
|
||||
return std::string("int") + ::testing::PrintToString(i);
|
||||
}
|
||||
};
|
||||
@@ -821,11 +780,6 @@ TYPED_TEST(TypedTestWithNames, Success) {}
|
||||
|
||||
TYPED_TEST(TypedTestWithNames, Failure) { FAIL(); }
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
// This #ifdef block tests the output of type-parameterized tests.
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
template <typename T>
|
||||
class TypedTestP : public testing::Test {
|
||||
};
|
||||
@@ -849,10 +803,10 @@ class TypedTestPNames {
|
||||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int i) {
|
||||
if (testing::internal::IsSame<T, unsigned char>::value) {
|
||||
if (std::is_same<T, unsigned char>::value) {
|
||||
return std::string("unsignedChar") + ::testing::PrintToString(i);
|
||||
}
|
||||
if (testing::internal::IsSame<T, unsigned int>::value) {
|
||||
if (std::is_same<T, unsigned int>::value) {
|
||||
return std::string("unsignedInt") + ::testing::PrintToString(i);
|
||||
}
|
||||
}
|
||||
@@ -861,7 +815,20 @@ class TypedTestPNames {
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(UnsignedCustomName, TypedTestP, UnsignedTypes,
|
||||
TypedTestPNames);
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
template <typename T>
|
||||
class DetectNotInstantiatedTypesTest : public testing::Test {};
|
||||
TYPED_TEST_SUITE_P(DetectNotInstantiatedTypesTest);
|
||||
TYPED_TEST_P(DetectNotInstantiatedTypesTest, Used) {
|
||||
TypeParam instantiate;
|
||||
(void)instantiate;
|
||||
}
|
||||
REGISTER_TYPED_TEST_SUITE_P(DetectNotInstantiatedTypesTest, Used);
|
||||
|
||||
// kErrorOnUninstantiatedTypeParameterizedTest=true would make the above fail.
|
||||
// Adding the following would make that test failure go away.
|
||||
//
|
||||
// typedef ::testing::Types<char, int, unsigned int> MyTypes;
|
||||
// INSTANTIATE_TYPED_TEST_SUITE_P(All, DetectNotInstantiatedTypesTest, MyTypes);
|
||||
|
||||
#if GTEST_HAS_DEATH_TEST
|
||||
|
||||
@@ -871,8 +838,6 @@ INSTANTIATE_TYPED_TEST_SUITE_P(UnsignedCustomName, TypedTestP, UnsignedTypes,
|
||||
TEST(ADeathTest, ShouldRunFirst) {
|
||||
}
|
||||
|
||||
# if GTEST_HAS_TYPED_TEST
|
||||
|
||||
// We rely on the golden file to verify that typed tests whose test
|
||||
// case name ends with DeathTest are run first.
|
||||
|
||||
@@ -886,10 +851,6 @@ TYPED_TEST_SUITE(ATypedDeathTest, NumericTypes);
|
||||
TYPED_TEST(ATypedDeathTest, ShouldRunFirst) {
|
||||
}
|
||||
|
||||
# endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
# if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
|
||||
// We rely on the golden file to verify that type-parameterized tests
|
||||
// whose test case name ends with DeathTest are run first.
|
||||
@@ -907,8 +868,6 @@ REGISTER_TYPED_TEST_SUITE_P(ATypeParamDeathTest, ShouldRunFirst);
|
||||
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(My, ATypeParamDeathTest, NumericTypes);
|
||||
|
||||
# endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
#endif // GTEST_HAS_DEATH_TEST
|
||||
|
||||
// Tests various failure conditions of
|
||||
@@ -1070,7 +1029,7 @@ auto dynamic_test = (
|
||||
"BadDynamicFixture1", "TestBase", nullptr, nullptr, __FILE__, __LINE__,
|
||||
[]() -> testing::Test* { return new DynamicTest<true>; }),
|
||||
|
||||
// Register two tests with the same fixture incorrectly by ommiting the
|
||||
// Register two tests with the same fixture incorrectly by omitting the
|
||||
// return type.
|
||||
testing::RegisterTest(
|
||||
"BadDynamicFixture2", "FixtureBase", nullptr, nullptr, __FILE__,
|
||||
|
||||
+70
-6
@@ -37,6 +37,7 @@
|
||||
# include <algorithm>
|
||||
# include <iostream>
|
||||
# include <list>
|
||||
# include <set>
|
||||
# include <sstream>
|
||||
# include <string>
|
||||
# include <vector>
|
||||
@@ -489,16 +490,17 @@ TEST(CombineTest, CombineWithMaxNumberOfParameters) {
|
||||
class NonDefaultConstructAssignString {
|
||||
public:
|
||||
NonDefaultConstructAssignString(const std::string& s) : str_(s) {}
|
||||
NonDefaultConstructAssignString() = delete;
|
||||
NonDefaultConstructAssignString(const NonDefaultConstructAssignString&) =
|
||||
default;
|
||||
NonDefaultConstructAssignString& operator=(
|
||||
const NonDefaultConstructAssignString&) = delete;
|
||||
~NonDefaultConstructAssignString() = default;
|
||||
|
||||
const std::string& str() const { return str_; }
|
||||
|
||||
private:
|
||||
std::string str_;
|
||||
|
||||
// Not default constructible
|
||||
NonDefaultConstructAssignString();
|
||||
// Not assignable
|
||||
void operator=(const NonDefaultConstructAssignString&);
|
||||
};
|
||||
|
||||
TEST(CombineTest, NonDefaultConstructAssign) {
|
||||
@@ -802,7 +804,7 @@ TEST_P(PREFIX_WITH_MACRO(NamingTest), PREFIX_WITH_FOO(SomeTestName)) {
|
||||
::testing::UnitTest::GetInstance()->current_test_info();
|
||||
|
||||
EXPECT_STREQ("FortyTwo/MacroNamingTest", test_info->test_suite_name());
|
||||
EXPECT_STREQ("FooSomeTestName", test_info->name());
|
||||
EXPECT_STREQ("FooSomeTestName/0", test_info->name());
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_SUITE_P(FortyTwo, MacroNamingTest, Values(42));
|
||||
@@ -819,6 +821,36 @@ TEST_F(PREFIX_WITH_MACRO(NamingTestNonParametrized),
|
||||
EXPECT_STREQ("FooSomeTestName", test_info->name());
|
||||
}
|
||||
|
||||
TEST(MacroNameing, LookupNames) {
|
||||
std::set<std::string> know_suite_names, know_test_names;
|
||||
|
||||
auto ins = testing::UnitTest::GetInstance();
|
||||
int ts = 0;
|
||||
while (const testing::TestSuite* suite = ins->GetTestSuite(ts++)) {
|
||||
know_suite_names.insert(suite->name());
|
||||
|
||||
int ti = 0;
|
||||
while (const testing::TestInfo* info = suite->GetTestInfo(ti++)) {
|
||||
know_test_names.insert(std::string(suite->name()) + "." + info->name());
|
||||
}
|
||||
}
|
||||
|
||||
// Check that the expected form of the test suit name actually exists.
|
||||
EXPECT_NE( //
|
||||
know_suite_names.find("FortyTwo/MacroNamingTest"),
|
||||
know_suite_names.end());
|
||||
EXPECT_NE(
|
||||
know_suite_names.find("MacroNamingTestNonParametrized"),
|
||||
know_suite_names.end());
|
||||
// Check that the expected form of the test name actually exists.
|
||||
EXPECT_NE( //
|
||||
know_test_names.find("FortyTwo/MacroNamingTest.FooSomeTestName/0"),
|
||||
know_test_names.end());
|
||||
EXPECT_NE(
|
||||
know_test_names.find("MacroNamingTestNonParametrized.FooSomeTestName"),
|
||||
know_test_names.end());
|
||||
}
|
||||
|
||||
// Tests that user supplied custom parameter names are working correctly.
|
||||
// Runs the test with a builtin helper method which uses PrintToString,
|
||||
// as well as a custom function and custom functor to ensure all possible
|
||||
@@ -1037,6 +1069,38 @@ TEST_P(MyEnumTest, ChecksParamMoreThanZero) { EXPECT_GE(10, GetParam()); }
|
||||
INSTANTIATE_TEST_SUITE_P(MyEnumTests, MyEnumTest,
|
||||
::testing::Values(ENUM1, ENUM2, 0));
|
||||
|
||||
namespace works_here {
|
||||
// Never used not instantiated, this should work.
|
||||
class NotUsedTest : public testing::TestWithParam<int> {};
|
||||
|
||||
///////
|
||||
// Never used not instantiated, this should work.
|
||||
template <typename T>
|
||||
class NotUsedTypeTest : public testing::Test {};
|
||||
TYPED_TEST_SUITE_P(NotUsedTypeTest);
|
||||
|
||||
// Used but not instantiated, this would fail. but...
|
||||
class NotInstantiatedTest : public testing::TestWithParam<int> {};
|
||||
// ... we mark is as allowed.
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTest);
|
||||
|
||||
TEST_P(NotInstantiatedTest, Used) { }
|
||||
|
||||
using OtherName = NotInstantiatedTest;
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(OtherName);
|
||||
TEST_P(OtherName, Used) { }
|
||||
|
||||
// Used but not instantiated, this would fail. but...
|
||||
template <typename T>
|
||||
class NotInstantiatedTypeTest : public testing::Test {};
|
||||
TYPED_TEST_SUITE_P(NotInstantiatedTypeTest);
|
||||
// ... we mark is as allowed.
|
||||
GTEST_ALLOW_UNINSTANTIATED_PARAMETERIZED_TEST(NotInstantiatedTypeTest);
|
||||
|
||||
TYPED_TEST_P(NotInstantiatedTypeTest, Used) { }
|
||||
REGISTER_TYPED_TEST_SUITE_P(NotInstantiatedTypeTest, Used);
|
||||
} // namespace works_here
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
// Used in TestGenerationTest test suite.
|
||||
AddGlobalTestEnvironment(TestGenerationTest::Environment::Instance());
|
||||
|
||||
@@ -32,8 +32,8 @@
|
||||
// This header file provides classes and functions used internally
|
||||
// for testing Google Test itself.
|
||||
|
||||
#ifndef GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
|
||||
#define GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
|
||||
#ifndef GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_
|
||||
#define GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@@ -48,4 +48,4 @@ class InstantiationInMultipleTranslationUnitsTest
|
||||
: public ::testing::TestWithParam<int> {
|
||||
};
|
||||
|
||||
#endif // GTEST_TEST_GTEST_PARAM_TEST_TEST_H_
|
||||
#endif // GOOGLETEST_TEST_GOOGLETEST_PARAM_TEST_TEST_H_
|
||||
|
||||
@@ -90,10 +90,10 @@ TEST(IsXDigitTest, ReturnsFalseForWideNonAscii) {
|
||||
|
||||
class Base {
|
||||
public:
|
||||
// Copy constructor and assignment operator do exactly what we need, so we
|
||||
// use them.
|
||||
Base() : member_(0) {}
|
||||
explicit Base(int n) : member_(n) {}
|
||||
Base(const Base&) = default;
|
||||
Base& operator=(const Base&) = default;
|
||||
virtual ~Base() {}
|
||||
int member() { return member_; }
|
||||
|
||||
@@ -201,24 +201,13 @@ TEST(ImplicitCastTest, CanUseImplicitConstructor) {
|
||||
EXPECT_TRUE(converted);
|
||||
}
|
||||
|
||||
TEST(IteratorTraitsTest, WorksForSTLContainerIterators) {
|
||||
StaticAssertTypeEq<int,
|
||||
IteratorTraits< ::std::vector<int>::const_iterator>::value_type>();
|
||||
StaticAssertTypeEq<bool,
|
||||
IteratorTraits< ::std::list<bool>::iterator>::value_type>();
|
||||
}
|
||||
|
||||
TEST(IteratorTraitsTest, WorksForPointerToNonConst) {
|
||||
StaticAssertTypeEq<char, IteratorTraits<char*>::value_type>();
|
||||
StaticAssertTypeEq<const void*, IteratorTraits<const void**>::value_type>();
|
||||
}
|
||||
|
||||
TEST(IteratorTraitsTest, WorksForPointerToConst) {
|
||||
StaticAssertTypeEq<char, IteratorTraits<const char*>::value_type>();
|
||||
StaticAssertTypeEq<const void*,
|
||||
IteratorTraits<const void* const*>::value_type>();
|
||||
}
|
||||
|
||||
// The following code intentionally tests a suboptimal syntax.
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wdangling-else"
|
||||
#pragma GCC diagnostic ignored "-Wempty-body"
|
||||
#pragma GCC diagnostic ignored "-Wpragmas"
|
||||
#endif
|
||||
TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) {
|
||||
if (AlwaysFalse())
|
||||
GTEST_CHECK_(false) << "This should never be executed; "
|
||||
@@ -234,6 +223,9 @@ TEST(GtestCheckSyntaxTest, BehavesLikeASingleStatement) {
|
||||
else
|
||||
GTEST_CHECK_(true) << "";
|
||||
}
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
TEST(GtestCheckSyntaxTest, WorksWithSwitch) {
|
||||
switch (0) {
|
||||
@@ -381,8 +373,6 @@ TEST(RegexEngineSelectionTest, SelectsCorrectRegexEngine) {
|
||||
|
||||
#if GTEST_USES_POSIX_RE
|
||||
|
||||
# if GTEST_HAS_TYPED_TEST
|
||||
|
||||
template <typename Str>
|
||||
class RETest : public ::testing::Test {};
|
||||
|
||||
@@ -438,8 +428,6 @@ TYPED_TEST(RETest, PartialMatchWorks) {
|
||||
EXPECT_FALSE(RE::PartialMatch(TypeParam("zza"), re));
|
||||
}
|
||||
|
||||
# endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
#elif GTEST_USES_SIMPLE_RE
|
||||
|
||||
TEST(IsInSetTest, NulCharIsNotInAnySet) {
|
||||
@@ -1198,8 +1186,6 @@ class DestructorTracker {
|
||||
return DestructorCall::List().size() - 1;
|
||||
}
|
||||
const size_t index_;
|
||||
|
||||
GTEST_DISALLOW_ASSIGN_(DestructorTracker);
|
||||
};
|
||||
|
||||
typedef ThreadLocal<DestructorTracker>* ThreadParam;
|
||||
|
||||
+378
-36
@@ -32,14 +32,16 @@
|
||||
//
|
||||
// This file tests the universal value printer.
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include <forward_list>
|
||||
#include <limits>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -89,6 +91,18 @@ class BiggestIntConvertible {
|
||||
operator ::testing::internal::BiggestInt() const { return 42; }
|
||||
};
|
||||
|
||||
// A parent class with two child classes. The parent and one of the kids have
|
||||
// stream operators.
|
||||
class ParentClass {};
|
||||
class ChildClassWithStreamOperator : public ParentClass {};
|
||||
class ChildClassWithoutStreamOperator : public ParentClass {};
|
||||
static void operator<<(std::ostream& os, const ParentClass&) {
|
||||
os << "ParentClass";
|
||||
}
|
||||
static void operator<<(std::ostream& os, const ChildClassWithStreamOperator&) {
|
||||
os << "ChildClassWithStreamOperator";
|
||||
}
|
||||
|
||||
// A user-defined unprintable class template in the global namespace.
|
||||
template <typename T>
|
||||
class UnprintableTemplateInGlobal {
|
||||
@@ -176,7 +190,18 @@ inline ::std::ostream& operator<<(::std::ostream& os,
|
||||
return os << "StreamableTemplateInFoo: " << x.value();
|
||||
}
|
||||
|
||||
// A user-defined streamable but recursivly-defined container type in
|
||||
// A user-defined streamable type in a user namespace whose operator<< is
|
||||
// templated on the type of the output stream.
|
||||
struct TemplatedStreamableInFoo {};
|
||||
|
||||
template <typename OutputStream>
|
||||
OutputStream& operator<<(OutputStream& os,
|
||||
const TemplatedStreamableInFoo& /*ts*/) {
|
||||
os << "TemplatedStreamableInFoo";
|
||||
return os;
|
||||
}
|
||||
|
||||
// A user-defined streamable but recursively-defined container type in
|
||||
// a user namespace, it mimics therefore std::filesystem::path or
|
||||
// boost::filesystem::path.
|
||||
class PathLike {
|
||||
@@ -204,6 +229,33 @@ class PathLike {
|
||||
} // namespace foo
|
||||
|
||||
namespace testing {
|
||||
namespace {
|
||||
template <typename T>
|
||||
class Wrapper {
|
||||
public:
|
||||
explicit Wrapper(T&& value) : value_(std::forward<T>(value)) {}
|
||||
|
||||
const T& value() const { return value_; }
|
||||
|
||||
private:
|
||||
T value_;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
namespace internal {
|
||||
template <typename T>
|
||||
class UniversalPrinter<Wrapper<T>> {
|
||||
public:
|
||||
static void Print(const Wrapper<T>& w, ::std::ostream* os) {
|
||||
*os << "Wrapper(";
|
||||
UniversalPrint(w.value(), os);
|
||||
*os << ')';
|
||||
}
|
||||
};
|
||||
} // namespace internal
|
||||
|
||||
|
||||
namespace gtest_printers_test {
|
||||
|
||||
using ::std::deque;
|
||||
@@ -219,7 +271,6 @@ using ::testing::PrintToString;
|
||||
using ::testing::internal::FormatForComparisonFailureMessage;
|
||||
using ::testing::internal::ImplicitCast_;
|
||||
using ::testing::internal::NativeArray;
|
||||
using ::testing::internal::RE;
|
||||
using ::testing::internal::RelationToSourceReference;
|
||||
using ::testing::internal::Strings;
|
||||
using ::testing::internal::UniversalPrint;
|
||||
@@ -310,6 +361,20 @@ TEST(PrintCharTest, UnsignedChar) {
|
||||
Print(static_cast<unsigned char>('b')));
|
||||
}
|
||||
|
||||
TEST(PrintCharTest, Char16) {
|
||||
EXPECT_EQ("U+0041", Print(u'A'));
|
||||
}
|
||||
|
||||
TEST(PrintCharTest, Char32) {
|
||||
EXPECT_EQ("U+0041", Print(U'A'));
|
||||
}
|
||||
|
||||
#ifdef __cpp_char8_t
|
||||
TEST(PrintCharTest, Char8) {
|
||||
EXPECT_EQ("U+0041", Print(u8'A'));
|
||||
}
|
||||
#endif
|
||||
|
||||
// Tests printing other simple, built-in types.
|
||||
|
||||
// bool.
|
||||
@@ -340,23 +405,39 @@ TEST(PrintBuiltInTypeTest, Wchar_t) {
|
||||
EXPECT_EQ("L'\\xC74D' (51021)", Print(static_cast<wchar_t>(0xC74D)));
|
||||
}
|
||||
|
||||
// Test that Int64 provides more storage than wchar_t.
|
||||
// Test that int64_t provides more storage than wchar_t.
|
||||
TEST(PrintTypeSizeTest, Wchar_t) {
|
||||
EXPECT_LT(sizeof(wchar_t), sizeof(testing::internal::Int64));
|
||||
EXPECT_LT(sizeof(wchar_t), sizeof(int64_t));
|
||||
}
|
||||
|
||||
// Various integer types.
|
||||
TEST(PrintBuiltInTypeTest, Integer) {
|
||||
EXPECT_EQ("'\\xFF' (255)", Print(static_cast<unsigned char>(255))); // uint8
|
||||
EXPECT_EQ("'\\x80' (-128)", Print(static_cast<signed char>(-128))); // int8
|
||||
EXPECT_EQ("65535", Print(USHRT_MAX)); // uint16
|
||||
EXPECT_EQ("-32768", Print(SHRT_MIN)); // int16
|
||||
EXPECT_EQ("4294967295", Print(UINT_MAX)); // uint32
|
||||
EXPECT_EQ("-2147483648", Print(INT_MIN)); // int32
|
||||
EXPECT_EQ("65535", Print(std::numeric_limits<uint16_t>::max())); // uint16
|
||||
EXPECT_EQ("-32768", Print(std::numeric_limits<int16_t>::min())); // int16
|
||||
EXPECT_EQ("4294967295",
|
||||
Print(std::numeric_limits<uint32_t>::max())); // uint32
|
||||
EXPECT_EQ("-2147483648",
|
||||
Print(std::numeric_limits<int32_t>::min())); // int32
|
||||
EXPECT_EQ("18446744073709551615",
|
||||
Print(static_cast<testing::internal::UInt64>(-1))); // uint64
|
||||
Print(std::numeric_limits<uint64_t>::max())); // uint64
|
||||
EXPECT_EQ("-9223372036854775808",
|
||||
Print(static_cast<testing::internal::Int64>(1) << 63)); // int64
|
||||
Print(std::numeric_limits<int64_t>::min())); // int64
|
||||
#ifdef __cpp_char8_t
|
||||
EXPECT_EQ("U+0000",
|
||||
Print(std::numeric_limits<char8_t>::min())); // char8_t
|
||||
EXPECT_EQ("U+00FF",
|
||||
Print(std::numeric_limits<char8_t>::max())); // char8_t
|
||||
#endif
|
||||
EXPECT_EQ("U+0000",
|
||||
Print(std::numeric_limits<char16_t>::min())); // char16_t
|
||||
EXPECT_EQ("U+FFFF",
|
||||
Print(std::numeric_limits<char16_t>::max())); // char16_t
|
||||
EXPECT_EQ("U+0000",
|
||||
Print(std::numeric_limits<char32_t>::min())); // char32_t
|
||||
EXPECT_EQ("U+FFFFFFFF",
|
||||
Print(std::numeric_limits<char32_t>::max())); // char32_t
|
||||
}
|
||||
|
||||
// Size types.
|
||||
@@ -412,6 +493,92 @@ TEST(PrintCStringTest, EscapesProperly) {
|
||||
Print(p));
|
||||
}
|
||||
|
||||
#ifdef __cpp_char8_t
|
||||
// const char8_t*.
|
||||
TEST(PrintU8StringTest, Const) {
|
||||
const char8_t* p = u8"界";
|
||||
EXPECT_EQ(PrintPointer(p) + " pointing to u8\"\\xE7\\x95\\x8C\"", Print(p));
|
||||
}
|
||||
|
||||
// char8_t*.
|
||||
TEST(PrintU8StringTest, NonConst) {
|
||||
char8_t p[] = u8"世";
|
||||
EXPECT_EQ(PrintPointer(p) + " pointing to u8\"\\xE4\\xB8\\x96\"",
|
||||
Print(static_cast<char8_t*>(p)));
|
||||
}
|
||||
|
||||
// NULL u8 string.
|
||||
TEST(PrintU8StringTest, Null) {
|
||||
const char8_t* p = nullptr;
|
||||
EXPECT_EQ("NULL", Print(p));
|
||||
}
|
||||
|
||||
// Tests that u8 strings are escaped properly.
|
||||
TEST(PrintU8StringTest, EscapesProperly) {
|
||||
const char8_t* p = u8"'\"?\\\a\b\f\n\r\t\v\x7F\xFF hello 世界";
|
||||
EXPECT_EQ(PrintPointer(p) +
|
||||
" pointing to u8\"'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\x7F\\xFF "
|
||||
"hello \\xE4\\xB8\\x96\\xE7\\x95\\x8C\"",
|
||||
Print(p));
|
||||
}
|
||||
#endif
|
||||
|
||||
// const char16_t*.
|
||||
TEST(PrintU16StringTest, Const) {
|
||||
const char16_t* p = u"界";
|
||||
EXPECT_EQ(PrintPointer(p) + " pointing to u\"\\x754C\"", Print(p));
|
||||
}
|
||||
|
||||
// char16_t*.
|
||||
TEST(PrintU16StringTest, NonConst) {
|
||||
char16_t p[] = u"世";
|
||||
EXPECT_EQ(PrintPointer(p) + " pointing to u\"\\x4E16\"",
|
||||
Print(static_cast<char16_t*>(p)));
|
||||
}
|
||||
|
||||
// NULL u16 string.
|
||||
TEST(PrintU16StringTest, Null) {
|
||||
const char16_t* p = nullptr;
|
||||
EXPECT_EQ("NULL", Print(p));
|
||||
}
|
||||
|
||||
// Tests that u16 strings are escaped properly.
|
||||
TEST(PrintU16StringTest, EscapesProperly) {
|
||||
const char16_t* p = u"'\"?\\\a\b\f\n\r\t\v\x7F\xFF hello 世界";
|
||||
EXPECT_EQ(PrintPointer(p) +
|
||||
" pointing to u\"'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\x7F\\xFF "
|
||||
"hello \\x4E16\\x754C\"",
|
||||
Print(p));
|
||||
}
|
||||
|
||||
// const char32_t*.
|
||||
TEST(PrintU32StringTest, Const) {
|
||||
const char32_t* p = U"🗺️";
|
||||
EXPECT_EQ(PrintPointer(p) + " pointing to U\"\\x1F5FA\\xFE0F\"", Print(p));
|
||||
}
|
||||
|
||||
// char32_t*.
|
||||
TEST(PrintU32StringTest, NonConst) {
|
||||
char32_t p[] = U"🌌";
|
||||
EXPECT_EQ(PrintPointer(p) + " pointing to U\"\\x1F30C\"",
|
||||
Print(static_cast<char32_t*>(p)));
|
||||
}
|
||||
|
||||
// NULL u32 string.
|
||||
TEST(PrintU32StringTest, Null) {
|
||||
const char32_t* p = nullptr;
|
||||
EXPECT_EQ("NULL", Print(p));
|
||||
}
|
||||
|
||||
// Tests that u32 strings are escaped properly.
|
||||
TEST(PrintU32StringTest, EscapesProperly) {
|
||||
const char32_t* p = U"'\"?\\\a\b\f\n\r\t\v\x7F\xFF hello 🗺️";
|
||||
EXPECT_EQ(PrintPointer(p) +
|
||||
" pointing to U\"'\\\"?\\\\\\a\\b\\f\\n\\r\\t\\v\\x7F\\xFF "
|
||||
"hello \\x1F5FA\\xFE0F\"",
|
||||
Print(p));
|
||||
}
|
||||
|
||||
// MSVC compiler can be configured to define whar_t as a typedef
|
||||
// of unsigned short. Defining an overload for const wchar_t* in that case
|
||||
// would cause pointers to unsigned shorts be printed as wide strings,
|
||||
@@ -622,21 +789,66 @@ TEST(PrintArrayTest, CharArrayWithNoTerminatingNul) {
|
||||
EXPECT_EQ("\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// const char array with terminating NUL.
|
||||
TEST(PrintArrayTest, ConstCharArrayWithTerminatingNul) {
|
||||
// char array with terminating NUL.
|
||||
TEST(PrintArrayTest, CharArrayWithTerminatingNul) {
|
||||
const char a[] = "\0Hi";
|
||||
EXPECT_EQ("\"\\0Hi\"", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// const wchar_t array without terminating NUL.
|
||||
#ifdef __cpp_char8_t
|
||||
// char_t array without terminating NUL.
|
||||
TEST(PrintArrayTest, Char8ArrayWithNoTerminatingNul) {
|
||||
// Array a contains '\0' in the middle and doesn't end with '\0'.
|
||||
const char8_t a[] = {u8'H', u8'\0', u8'i'};
|
||||
EXPECT_EQ("u8\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// char8_t array with terminating NUL.
|
||||
TEST(PrintArrayTest, Char8ArrayWithTerminatingNul) {
|
||||
const char8_t a[] = u8"\0世界";
|
||||
EXPECT_EQ(
|
||||
"u8\"\\0\\xE4\\xB8\\x96\\xE7\\x95\\x8C\"",
|
||||
PrintArrayHelper(a));
|
||||
}
|
||||
#endif
|
||||
|
||||
// const char16_t array without terminating NUL.
|
||||
TEST(PrintArrayTest, Char16ArrayWithNoTerminatingNul) {
|
||||
// Array a contains '\0' in the middle and doesn't end with '\0'.
|
||||
const char16_t a[] = {u'こ', u'\0', u'ん', u'に', u'ち', u'は'};
|
||||
EXPECT_EQ("u\"\\x3053\\0\\x3093\\x306B\\x3061\\x306F\" (no terminating NUL)",
|
||||
PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// char16_t array with terminating NUL.
|
||||
TEST(PrintArrayTest, Char16ArrayWithTerminatingNul) {
|
||||
const char16_t a[] = u"\0こんにちは";
|
||||
EXPECT_EQ("u\"\\0\\x3053\\x3093\\x306B\\x3061\\x306F\"", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// char32_t array without terminating NUL.
|
||||
TEST(PrintArrayTest, Char32ArrayWithNoTerminatingNul) {
|
||||
// Array a contains '\0' in the middle and doesn't end with '\0'.
|
||||
const char32_t a[] = {U'👋', U'\0', U'🌌'};
|
||||
EXPECT_EQ("U\"\\x1F44B\\0\\x1F30C\" (no terminating NUL)",
|
||||
PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// char32_t array with terminating NUL.
|
||||
TEST(PrintArrayTest, Char32ArrayWithTerminatingNul) {
|
||||
const char32_t a[] = U"\0👋🌌";
|
||||
EXPECT_EQ("U\"\\0\\x1F44B\\x1F30C\"", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// wchar_t array without terminating NUL.
|
||||
TEST(PrintArrayTest, WCharArrayWithNoTerminatingNul) {
|
||||
// Array a contains '\0' in the middle and doesn't end with '\0'.
|
||||
const wchar_t a[] = { L'H', L'\0', L'i' };
|
||||
const wchar_t a[] = {L'H', L'\0', L'i'};
|
||||
EXPECT_EQ("L\"H\\0i\" (no terminating NUL)", PrintArrayHelper(a));
|
||||
}
|
||||
|
||||
// wchar_t array with terminating NUL.
|
||||
TEST(PrintArrayTest, WConstCharArrayWithTerminatingNul) {
|
||||
TEST(PrintArrayTest, WCharArrayWithTerminatingNul) {
|
||||
const wchar_t a[] = L"\0Hi";
|
||||
EXPECT_EQ("L\"\\0Hi\"", PrintArrayHelper(a));
|
||||
}
|
||||
@@ -700,6 +912,26 @@ TEST(PrintWideStringTest, StringAmbiguousHex) {
|
||||
}
|
||||
#endif // GTEST_HAS_STD_WSTRING
|
||||
|
||||
#ifdef __cpp_char8_t
|
||||
TEST(PrintStringTest, U8String) {
|
||||
std::u8string str = u8"Hello, 世界";
|
||||
EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type.
|
||||
EXPECT_EQ("u8\"Hello, \\xE4\\xB8\\x96\\xE7\\x95\\x8C\"", Print(str));
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(PrintStringTest, U16String) {
|
||||
std::u16string str = u"Hello, 世界";
|
||||
EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type.
|
||||
EXPECT_EQ("u\"Hello, \\x4E16\\x754C\"", Print(str));
|
||||
}
|
||||
|
||||
TEST(PrintStringTest, U32String) {
|
||||
std::u32string str = U"Hello, 🗺️";
|
||||
EXPECT_EQ(str, str); // Verify EXPECT_EQ compiles with this type
|
||||
EXPECT_EQ("U\"Hello, \\x1F5FA\\xFE0F\"", Print(str));
|
||||
}
|
||||
|
||||
// Tests printing types that support generic streaming (i.e. streaming
|
||||
// to std::basic_ostream<Char, CharTraits> for any valid Char and
|
||||
// CharTraits types).
|
||||
@@ -758,22 +990,22 @@ TEST(PrintTypeWithGenericStreamingTest, TypeImplicitlyConvertible) {
|
||||
EXPECT_EQ("AllowsGenericStreamingAndImplicitConversionTemplate", Print(a));
|
||||
}
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
#if GTEST_INTERNAL_HAS_STRING_VIEW
|
||||
|
||||
// Tests printing ::absl::string_view.
|
||||
// Tests printing internal::StringView.
|
||||
|
||||
TEST(PrintStringViewTest, SimpleStringView) {
|
||||
const ::absl::string_view sp = "Hello";
|
||||
const internal::StringView sp = "Hello";
|
||||
EXPECT_EQ("\"Hello\"", Print(sp));
|
||||
}
|
||||
|
||||
TEST(PrintStringViewTest, UnprintableCharacters) {
|
||||
const char str[] = "NUL (\0) and \r\t";
|
||||
const ::absl::string_view sp(str, sizeof(str) - 1);
|
||||
const internal::StringView sp(str, sizeof(str) - 1);
|
||||
EXPECT_EQ("\"NUL (\\0) and \\r\\t\"", Print(sp));
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_ABSL
|
||||
#endif // GTEST_INTERNAL_HAS_STRING_VIEW
|
||||
|
||||
// Tests printing STL containers.
|
||||
|
||||
@@ -978,9 +1210,8 @@ TEST(PrintStdTupleTest, VariousSizes) {
|
||||
EXPECT_EQ("(false, 2, 3, 4)", Print(t4));
|
||||
|
||||
const char* const str = "8";
|
||||
::std::tuple<bool, char, short, testing::internal::Int32, // NOLINT
|
||||
testing::internal::Int64, float, double, const char*, void*,
|
||||
std::string>
|
||||
::std::tuple<bool, char, short, int32_t, int64_t, float, double, // NOLINT
|
||||
const char*, void*, std::string>
|
||||
t10(false, 'a', static_cast<short>(3), 4, 5, 1.5F, -2.5, str, // NOLINT
|
||||
nullptr, "10");
|
||||
EXPECT_EQ("(false, 'a' (97, 0x61), 3, 4, 5, 1.5, -2.5, " + PrintPointer(str) +
|
||||
@@ -1064,6 +1295,20 @@ TEST(PrintStreamableTypeTest, TemplateTypeInUserNamespace) {
|
||||
Print(::foo::StreamableTemplateInFoo<int>()));
|
||||
}
|
||||
|
||||
TEST(PrintStreamableTypeTest, TypeInUserNamespaceWithTemplatedStreamOperator) {
|
||||
EXPECT_EQ("TemplatedStreamableInFoo",
|
||||
Print(::foo::TemplatedStreamableInFoo()));
|
||||
}
|
||||
|
||||
TEST(PrintStreamableTypeTest, SubclassUsesSuperclassStreamOperator) {
|
||||
ParentClass parent;
|
||||
ChildClassWithStreamOperator child_stream;
|
||||
ChildClassWithoutStreamOperator child_no_stream;
|
||||
EXPECT_EQ("ParentClass", Print(parent));
|
||||
EXPECT_EQ("ChildClassWithStreamOperator", Print(child_stream));
|
||||
EXPECT_EQ("ParentClass", Print(child_no_stream));
|
||||
}
|
||||
|
||||
// Tests printing a user-defined recursive container type that has a <<
|
||||
// operator.
|
||||
TEST(PrintStreamableTypeTest, PathLikeInUserNamespace) {
|
||||
@@ -1472,6 +1717,13 @@ TEST(UniversalPrintTest, WorksForReference) {
|
||||
EXPECT_EQ("123", ss.str());
|
||||
}
|
||||
|
||||
TEST(UniversalPrintTest, WorksForPairWithConst) {
|
||||
std::pair<const Wrapper<std::string>, int> p(Wrapper<std::string>("abc"), 1);
|
||||
::std::stringstream ss;
|
||||
UniversalPrint(p, &ss);
|
||||
EXPECT_EQ("(Wrapper(\"abc\"), 1)", ss.str());
|
||||
}
|
||||
|
||||
TEST(UniversalPrintTest, WorksForCString) {
|
||||
const char* s1 = "abc";
|
||||
::std::stringstream ss1;
|
||||
@@ -1501,6 +1753,63 @@ TEST(UniversalPrintTest, WorksForCharArray) {
|
||||
EXPECT_EQ("\"\\\"Line\\0 1\\\"\\nLine 2\"", ss2.str());
|
||||
}
|
||||
|
||||
TEST(UniversalPrintTest, IncompleteType) {
|
||||
struct Incomplete;
|
||||
char some_object = 0;
|
||||
EXPECT_EQ("(incomplete type)",
|
||||
PrintToString(reinterpret_cast<Incomplete&>(some_object)));
|
||||
}
|
||||
|
||||
TEST(UniversalPrintTest, SmartPointers) {
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<int>()));
|
||||
std::unique_ptr<int> p(new int(17));
|
||||
EXPECT_EQ("(ptr = " + PrintPointer(p.get()) + ", value = 17)",
|
||||
PrintToString(p));
|
||||
std::unique_ptr<int[]> p2(new int[2]);
|
||||
EXPECT_EQ("(" + PrintPointer(p2.get()) + ")", PrintToString(p2));
|
||||
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int>()));
|
||||
std::shared_ptr<int> p3(new int(1979));
|
||||
EXPECT_EQ("(ptr = " + PrintPointer(p3.get()) + ", value = 1979)",
|
||||
PrintToString(p3));
|
||||
#if __cpp_lib_shared_ptr_arrays >= 201611L
|
||||
std::shared_ptr<int[]> p4(new int[2]);
|
||||
EXPECT_EQ("(" + PrintPointer(p4.get()) + ")", PrintToString(p4));
|
||||
#endif
|
||||
|
||||
// modifiers
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<int>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<const int>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<volatile int>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<volatile const int>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<int[]>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<const int[]>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<volatile int[]>()));
|
||||
EXPECT_EQ("(nullptr)",
|
||||
PrintToString(std::unique_ptr<volatile const int[]>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<const int>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile int>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile const int>()));
|
||||
#if __cpp_lib_shared_ptr_arrays >= 201611L
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<int[]>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<const int[]>()));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<volatile int[]>()));
|
||||
EXPECT_EQ("(nullptr)",
|
||||
PrintToString(std::shared_ptr<volatile const int[]>()));
|
||||
#endif
|
||||
|
||||
// void
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::unique_ptr<void, void (*)(void*)>(
|
||||
nullptr, nullptr)));
|
||||
EXPECT_EQ("(" + PrintPointer(p.get()) + ")",
|
||||
PrintToString(
|
||||
std::unique_ptr<void, void (*)(void*)>(p.get(), [](void*) {})));
|
||||
EXPECT_EQ("(nullptr)", PrintToString(std::shared_ptr<void>()));
|
||||
EXPECT_EQ("(" + PrintPointer(p.get()) + ")",
|
||||
PrintToString(std::shared_ptr<void>(p.get(), [](void*) {})));
|
||||
}
|
||||
|
||||
TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsEmptyTuple) {
|
||||
Strings result = UniversalTersePrintTupleFieldsToStrings(::std::make_tuple());
|
||||
EXPECT_EQ(0u, result.size());
|
||||
@@ -1530,32 +1839,65 @@ TEST(UniversalTersePrintTupleFieldsToStringsTestWithStd, PrintsTersely) {
|
||||
EXPECT_EQ("\"a\"", result[1]);
|
||||
}
|
||||
|
||||
#if GTEST_HAS_ABSL
|
||||
#if GTEST_INTERNAL_HAS_ANY
|
||||
class PrintAnyTest : public ::testing::Test {
|
||||
protected:
|
||||
template <typename T>
|
||||
static std::string ExpectedTypeName() {
|
||||
#if GTEST_HAS_RTTI
|
||||
return internal::GetTypeName<T>();
|
||||
#else
|
||||
return "<unknown_type>";
|
||||
#endif // GTEST_HAS_RTTI
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PrintAnyTest, Empty) {
|
||||
internal::Any any;
|
||||
EXPECT_EQ("no value", PrintToString(any));
|
||||
}
|
||||
|
||||
TEST_F(PrintAnyTest, NonEmpty) {
|
||||
internal::Any any;
|
||||
constexpr int val1 = 10;
|
||||
const std::string val2 = "content";
|
||||
|
||||
any = val1;
|
||||
EXPECT_EQ("value of type " + ExpectedTypeName<int>(), PrintToString(any));
|
||||
|
||||
any = val2;
|
||||
EXPECT_EQ("value of type " + ExpectedTypeName<std::string>(),
|
||||
PrintToString(any));
|
||||
}
|
||||
#endif // GTEST_INTERNAL_HAS_ANY
|
||||
|
||||
#if GTEST_INTERNAL_HAS_OPTIONAL
|
||||
TEST(PrintOptionalTest, Basic) {
|
||||
absl::optional<int> value;
|
||||
internal::Optional<int> value;
|
||||
EXPECT_EQ("(nullopt)", PrintToString(value));
|
||||
value = {7};
|
||||
EXPECT_EQ("(7)", PrintToString(value));
|
||||
EXPECT_EQ("(1.1)", PrintToString(absl::optional<double>{1.1}));
|
||||
EXPECT_EQ("(\"A\")", PrintToString(absl::optional<std::string>{"A"}));
|
||||
EXPECT_EQ("(1.1)", PrintToString(internal::Optional<double>{1.1}));
|
||||
EXPECT_EQ("(\"A\")", PrintToString(internal::Optional<std::string>{"A"}));
|
||||
}
|
||||
#endif // GTEST_INTERNAL_HAS_OPTIONAL
|
||||
|
||||
#if GTEST_INTERNAL_HAS_VARIANT
|
||||
struct NonPrintable {
|
||||
unsigned char contents = 17;
|
||||
};
|
||||
|
||||
TEST(PrintOneofTest, Basic) {
|
||||
using Type = absl::variant<int, StreamableInGlobal, NonPrintable>;
|
||||
EXPECT_EQ("('int' with value 7)", PrintToString(Type(7)));
|
||||
EXPECT_EQ("('StreamableInGlobal' with value StreamableInGlobal)",
|
||||
using Type = internal::Variant<int, StreamableInGlobal, NonPrintable>;
|
||||
EXPECT_EQ("('int(index = 0)' with value 7)", PrintToString(Type(7)));
|
||||
EXPECT_EQ("('StreamableInGlobal(index = 1)' with value StreamableInGlobal)",
|
||||
PrintToString(Type(StreamableInGlobal{})));
|
||||
EXPECT_EQ(
|
||||
"('testing::gtest_printers_test::NonPrintable' with value 1-byte object "
|
||||
"<11>)",
|
||||
"('testing::gtest_printers_test::NonPrintable(index = 2)' with value "
|
||||
"1-byte object <11>)",
|
||||
PrintToString(Type(NonPrintable{})));
|
||||
}
|
||||
#endif // GTEST_HAS_ABSL
|
||||
#endif // GTEST_INTERNAL_HAS_VARIANT
|
||||
namespace {
|
||||
class string_ref;
|
||||
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2019, Google Inc.
|
||||
# All rights reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
"""Verifies that SetUpTestSuite and TearDownTestSuite errors are noticed."""
|
||||
|
||||
import gtest_test_utils
|
||||
|
||||
COMMAND = gtest_test_utils.GetTestExecutablePath(
|
||||
'googletest-setuptestsuite-test_')
|
||||
|
||||
|
||||
class GTestSetUpTestSuiteTest(gtest_test_utils.TestCase):
|
||||
|
||||
def testSetupErrorAndTearDownError(self):
|
||||
p = gtest_test_utils.Subprocess(COMMAND)
|
||||
self.assertNotEqual(p.exit_code, 0, msg=p.output)
|
||||
|
||||
self.assertIn(
|
||||
'[ FAILED ] SetupFailTest: SetUpTestSuite or TearDownTestSuite\n'
|
||||
'[ FAILED ] TearDownFailTest: SetUpTestSuite or TearDownTestSuite\n'
|
||||
'\n'
|
||||
' 2 FAILED TEST SUITES\n',
|
||||
p.output)
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
+14
-26
@@ -27,35 +27,23 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
//
|
||||
// Tests for Google Test itself. This verifies that the basic constructs of
|
||||
// Google Test work.
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "googletest-param-test-test.h"
|
||||
|
||||
using ::testing::Values;
|
||||
using ::testing::internal::ParamGenerator;
|
||||
class SetupFailTest : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() {
|
||||
ASSERT_EQ("", "SET_UP_FAIL");
|
||||
}
|
||||
};
|
||||
|
||||
// Tests that generators defined in a different translation unit
|
||||
// are functional. The test using extern_gen_2 is defined
|
||||
// in googletest-param-test-test.cc.
|
||||
ParamGenerator<int> extern_gen_2 = Values(33);
|
||||
TEST_F(SetupFailTest, NoopPassingTest) {}
|
||||
|
||||
// Tests that a parameterized test case can be defined in one translation unit
|
||||
// and instantiated in another. The test is defined in
|
||||
// googletest-param-test-test.cc and ExternalInstantiationTest fixture class is
|
||||
// defined in gtest-param-test_test.h.
|
||||
INSTANTIATE_TEST_SUITE_P(MultiplesOf33,
|
||||
ExternalInstantiationTest,
|
||||
Values(33, 66));
|
||||
|
||||
// Tests that a parameterized test case can be instantiated
|
||||
// in multiple translation units. Another instantiation is defined
|
||||
// in googletest-param-test-test.cc and
|
||||
// InstantiationInMultipleTranslationUnitsTest fixture is defined in
|
||||
// gtest-param-test_test.h
|
||||
INSTANTIATE_TEST_SUITE_P(Sequence2,
|
||||
InstantiationInMultipleTranslationUnitsTest,
|
||||
Values(42*3, 42*4, 42*5));
|
||||
class TearDownFailTest : public ::testing::Test {
|
||||
protected:
|
||||
static void TearDownTestSuite() {
|
||||
ASSERT_EQ("", "TEAR_DOWN_FAIL");
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(TearDownFailTest, NoopPassingTest) {}
|
||||
Vendored
Regular → Executable
@@ -82,7 +82,7 @@ class TestNamePrinter : public EmptyTestEventListener {
|
||||
}
|
||||
|
||||
void OnTestStart(const TestInfo& test_info) override {
|
||||
printf("%s.%s\n", test_info.test_case_name(), test_info.name());
|
||||
printf("%s.%s\n", test_info.test_suite_name(), test_info.name());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Vendored
Regular → Executable
+1
-1
@@ -86,7 +86,7 @@ class ThrowOnFailureTest(gtest_test_utils.TestCase):
|
||||
variable; None if the variable should be unset.
|
||||
flag_value: value of the --gtest_break_on_failure flag;
|
||||
None if the flag should not be present.
|
||||
should_fail: True iff the program is expected to fail.
|
||||
should_fail: True if and only if the program is expected to fail.
|
||||
"""
|
||||
|
||||
SetEnvVar(THROW_ON_FAILURE, env_var_value)
|
||||
|
||||
Vendored
Regular → Executable
@@ -33,12 +33,8 @@
|
||||
#include "test/gtest-typed-test_test.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
// Tests that the same type-parameterized test case can be
|
||||
// instantiated in different translation units linked together.
|
||||
// (ContainerTest is also instantiated in gtest-typed-test_test.cc.)
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Vector, ContainerTest,
|
||||
testing::Types<std::vector<int> >);
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include "test/gtest-typed-test_test.h"
|
||||
|
||||
#include <set>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
@@ -87,9 +88,6 @@ class CommonTest : public Test {
|
||||
template <typename T>
|
||||
T* CommonTest<T>::shared_ = nullptr;
|
||||
|
||||
// This #ifdef block tests typed tests.
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
|
||||
using testing::Types;
|
||||
|
||||
// Tests that SetUpTestSuite()/TearDownTestSuite(), fixture ctor/dtor,
|
||||
@@ -177,10 +175,10 @@ class TypedTestNames {
|
||||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int i) {
|
||||
if (testing::internal::IsSame<T, char>::value) {
|
||||
if (std::is_same<T, char>::value) {
|
||||
return std::string("char") + ::testing::PrintToString(i);
|
||||
}
|
||||
if (testing::internal::IsSame<T, int>::value) {
|
||||
if (std::is_same<T, int>::value) {
|
||||
return std::string("int") + ::testing::PrintToString(i);
|
||||
}
|
||||
}
|
||||
@@ -189,25 +187,20 @@ class TypedTestNames {
|
||||
TYPED_TEST_SUITE(TypedTestWithNames, TwoTypes, TypedTestNames);
|
||||
|
||||
TYPED_TEST(TypedTestWithNames, TestSuiteName) {
|
||||
if (testing::internal::IsSame<TypeParam, char>::value) {
|
||||
if (std::is_same<TypeParam, char>::value) {
|
||||
EXPECT_STREQ(::testing::UnitTest::GetInstance()
|
||||
->current_test_info()
|
||||
->test_case_name(),
|
||||
->test_suite_name(),
|
||||
"TypedTestWithNames/char0");
|
||||
}
|
||||
if (testing::internal::IsSame<TypeParam, int>::value) {
|
||||
if (std::is_same<TypeParam, int>::value) {
|
||||
EXPECT_STREQ(::testing::UnitTest::GetInstance()
|
||||
->current_test_info()
|
||||
->test_case_name(),
|
||||
->test_suite_name(),
|
||||
"TypedTestWithNames/int1");
|
||||
}
|
||||
}
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
// This #ifdef block tests type-parameterized tests.
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
using testing::Types;
|
||||
using testing::internal::TypedTestSuitePState;
|
||||
|
||||
@@ -227,7 +220,7 @@ class TypedTestSuitePStateTest : public Test {
|
||||
TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) {
|
||||
const char* tests = "A, B, C";
|
||||
EXPECT_EQ(tests,
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, tests));
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, tests));
|
||||
}
|
||||
|
||||
// Makes sure that the order of the tests and spaces around the names
|
||||
@@ -235,33 +228,33 @@ TEST_F(TypedTestSuitePStateTest, SucceedsForMatchingList) {
|
||||
TEST_F(TypedTestSuitePStateTest, IgnoresOrderAndSpaces) {
|
||||
const char* tests = "A,C, B";
|
||||
EXPECT_EQ(tests,
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, tests));
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, tests));
|
||||
}
|
||||
|
||||
using TypedTestSuitePStateDeathTest = TypedTestSuitePStateTest;
|
||||
|
||||
TEST_F(TypedTestSuitePStateDeathTest, DetectsDuplicates) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, A, C"),
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, A, C"),
|
||||
"foo\\.cc.1.?: Test A is listed more than once\\.");
|
||||
}
|
||||
|
||||
TEST_F(TypedTestSuitePStateDeathTest, DetectsExtraTest) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C, D"),
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, C, D"),
|
||||
"foo\\.cc.1.?: No test named D can be found in this test suite\\.");
|
||||
}
|
||||
|
||||
TEST_F(TypedTestSuitePStateDeathTest, DetectsMissedTest) {
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, C"),
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, C"),
|
||||
"foo\\.cc.1.?: You forgot to list test B\\.");
|
||||
}
|
||||
|
||||
// Tests that defining a test for a parameterized test case generates
|
||||
// a run-time error if the test case has been registered.
|
||||
TEST_F(TypedTestSuitePStateDeathTest, DetectsTestAfterRegistration) {
|
||||
state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C");
|
||||
state_.VerifyRegisteredTestNames("Suite", "foo.cc", 1, "A, B, C");
|
||||
EXPECT_DEATH_IF_SUPPORTED(
|
||||
state_.AddTestName("foo.cc", 2, "FooTest", "D"),
|
||||
"foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_SUITE_P"
|
||||
@@ -311,16 +304,16 @@ class TypeParametrizedTestWithNames : public Test {};
|
||||
TYPED_TEST_SUITE_P(TypeParametrizedTestWithNames);
|
||||
|
||||
TYPED_TEST_P(TypeParametrizedTestWithNames, TestSuiteName) {
|
||||
if (testing::internal::IsSame<TypeParam, char>::value) {
|
||||
if (std::is_same<TypeParam, char>::value) {
|
||||
EXPECT_STREQ(::testing::UnitTest::GetInstance()
|
||||
->current_test_info()
|
||||
->test_case_name(),
|
||||
->test_suite_name(),
|
||||
"CustomName/TypeParametrizedTestWithNames/parChar0");
|
||||
}
|
||||
if (testing::internal::IsSame<TypeParam, int>::value) {
|
||||
if (std::is_same<TypeParam, int>::value) {
|
||||
EXPECT_STREQ(::testing::UnitTest::GetInstance()
|
||||
->current_test_info()
|
||||
->test_case_name(),
|
||||
->test_suite_name(),
|
||||
"CustomName/TypeParametrizedTestWithNames/parInt1");
|
||||
}
|
||||
}
|
||||
@@ -331,10 +324,10 @@ class TypeParametrizedTestNames {
|
||||
public:
|
||||
template <typename T>
|
||||
static std::string GetName(int i) {
|
||||
if (testing::internal::IsSame<T, char>::value) {
|
||||
if (std::is_same<T, char>::value) {
|
||||
return std::string("parChar") + ::testing::PrintToString(i);
|
||||
}
|
||||
if (testing::internal::IsSame<T, int>::value) {
|
||||
if (std::is_same<T, int>::value) {
|
||||
return std::string("parInt") + ::testing::PrintToString(i);
|
||||
}
|
||||
}
|
||||
@@ -442,20 +435,3 @@ INSTANTIATE_TYPED_TEST_SUITE_P(My, TrimmedTest, TrimTypes);
|
||||
|
||||
} // namespace library2
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
#if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P)
|
||||
|
||||
// Google Test may not support type-parameterized tests with some
|
||||
// compilers. If we use conditional compilation to compile out all
|
||||
// code referring to the gtest_main library, MSVC linker will not link
|
||||
// that library at all and consequently complain about missing entry
|
||||
// point defined in that library (fatal error LNK1561: entry point
|
||||
// must be defined). This dummy test keeps gtest_main linked in.
|
||||
TEST(DummyTest, TypedTestsAreNotSupportedOnThisPlatform) {}
|
||||
|
||||
#if _MSC_VER
|
||||
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4127
|
||||
#endif // _MSC_VER
|
||||
|
||||
#endif // #if !defined(GTEST_HAS_TYPED_TEST) && !defined(GTEST_HAS_TYPED_TEST_P)
|
||||
|
||||
@@ -27,14 +27,11 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
|
||||
#ifndef GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
#define GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
#ifndef GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
#define GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
using testing::Test;
|
||||
|
||||
// For testing that the same type-parameterized test case can be
|
||||
@@ -60,6 +57,4 @@ TYPED_TEST_P(ContainerTest, InitialSizeIsZero) {
|
||||
REGISTER_TYPED_TEST_SUITE_P(ContainerTest,
|
||||
CanBeDefaultConstructed, InitialSizeIsZero);
|
||||
|
||||
#endif // GTEST_HAS_TYPED_TEST_P
|
||||
|
||||
#endif // GTEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
#endif // GOOGLETEST_TEST_GTEST_TYPED_TEST_TEST_H_
|
||||
|
||||
@@ -55,8 +55,8 @@ class UnitTestHelper {
|
||||
// name. The caller is responsible for deleting the array.
|
||||
static TestSuite const** GetSortedTestSuites() {
|
||||
UnitTest& unit_test = *UnitTest::GetInstance();
|
||||
auto const** const test_suites =
|
||||
new const TestSuite*[unit_test.total_test_suite_count()];
|
||||
auto const** const test_suites = new const TestSuite*[static_cast<size_t>(
|
||||
unit_test.total_test_suite_count())];
|
||||
|
||||
for (int i = 0; i < unit_test.total_test_suite_count(); ++i)
|
||||
test_suites[i] = unit_test.GetTestSuite(i);
|
||||
@@ -83,8 +83,8 @@ class UnitTestHelper {
|
||||
// sorted by the test name. The caller is responsible for deleting the
|
||||
// array.
|
||||
static TestInfo const** GetSortedTests(const TestSuite* test_suite) {
|
||||
TestInfo const** const tests =
|
||||
new const TestInfo*[test_suite->total_test_count()];
|
||||
TestInfo const** const tests = new const TestInfo*[static_cast<size_t>(
|
||||
test_suite->total_test_count())];
|
||||
|
||||
for (int i = 0; i < test_suite->total_test_count(); ++i)
|
||||
tests[i] = test_suite->GetTestInfo(i);
|
||||
@@ -95,17 +95,12 @@ class UnitTestHelper {
|
||||
}
|
||||
};
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
template <typename T> class TestSuiteWithCommentTest : public Test {};
|
||||
TYPED_TEST_SUITE(TestSuiteWithCommentTest, Types<int>);
|
||||
TYPED_TEST(TestSuiteWithCommentTest, Dummy) {}
|
||||
|
||||
const int kTypedTestSuites = 1;
|
||||
const int kTypedTests = 1;
|
||||
#else
|
||||
const int kTypedTestSuites = 0;
|
||||
const int kTypedTests = 0;
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
// We can only test the accessors that do not change value while tests run.
|
||||
// Since tests can be run in any order, the values the accessors that track
|
||||
@@ -123,9 +118,7 @@ TEST(ApiTest, UnitTestImmutableAccessorsWork) {
|
||||
|
||||
EXPECT_STREQ("ApiTest", test_suites[0]->name());
|
||||
EXPECT_STREQ("DISABLED_Test", test_suites[1]->name());
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suites[2]->name());
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
delete[] test_suites;
|
||||
|
||||
@@ -183,12 +176,11 @@ TEST(ApiTest, TestSuiteImmutableAccessorsWork) {
|
||||
delete[] tests;
|
||||
tests = nullptr;
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
test_suite = UnitTestHelper::FindTestSuite("TestSuiteWithCommentTest/0");
|
||||
ASSERT_TRUE(test_suite != nullptr);
|
||||
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suite->name());
|
||||
EXPECT_STREQ(GetTypeName<int>().c_str(), test_suite->type_param());
|
||||
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), test_suite->type_param());
|
||||
EXPECT_TRUE(test_suite->should_run());
|
||||
EXPECT_EQ(0, test_suite->disabled_test_count());
|
||||
EXPECT_EQ(1, test_suite->test_to_run_count());
|
||||
@@ -199,11 +191,10 @@ TEST(ApiTest, TestSuiteImmutableAccessorsWork) {
|
||||
EXPECT_STREQ("Dummy", tests[0]->name());
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
|
||||
EXPECT_TRUE(IsNull(tests[0]->value_param()));
|
||||
EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param());
|
||||
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), tests[0]->type_param());
|
||||
EXPECT_TRUE(tests[0]->should_run());
|
||||
|
||||
delete[] tests;
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
}
|
||||
|
||||
TEST(ApiTest, TestSuiteDisabledAccessorsWork) {
|
||||
@@ -263,9 +254,9 @@ class FinalSuccessChecker : public Environment {
|
||||
EXPECT_EQ(0, test_suites[1]->successful_test_count());
|
||||
EXPECT_EQ(0, test_suites[1]->failed_test_count());
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", test_suites[2]->name());
|
||||
EXPECT_STREQ(GetTypeName<int>().c_str(), test_suites[2]->type_param());
|
||||
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(),
|
||||
test_suites[2]->type_param());
|
||||
EXPECT_TRUE(test_suites[2]->should_run());
|
||||
EXPECT_EQ(0, test_suites[2]->disabled_test_count());
|
||||
ASSERT_EQ(1, test_suites[2]->total_test_count());
|
||||
@@ -273,7 +264,6 @@ class FinalSuccessChecker : public Environment {
|
||||
EXPECT_EQ(0, test_suites[2]->failed_test_count());
|
||||
EXPECT_TRUE(test_suites[2]->Passed());
|
||||
EXPECT_FALSE(test_suites[2]->Failed());
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
|
||||
const TestSuite* test_suite = UnitTestHelper::FindTestSuite("ApiTest");
|
||||
const TestInfo** tests = UnitTestHelper::GetSortedTests(test_suite);
|
||||
@@ -310,20 +300,18 @@ class FinalSuccessChecker : public Environment {
|
||||
|
||||
delete[] tests;
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
test_suite = UnitTestHelper::FindTestSuite("TestSuiteWithCommentTest/0");
|
||||
tests = UnitTestHelper::GetSortedTests(test_suite);
|
||||
|
||||
EXPECT_STREQ("Dummy", tests[0]->name());
|
||||
EXPECT_STREQ("TestSuiteWithCommentTest/0", tests[0]->test_suite_name());
|
||||
EXPECT_TRUE(IsNull(tests[0]->value_param()));
|
||||
EXPECT_STREQ(GetTypeName<int>().c_str(), tests[0]->type_param());
|
||||
EXPECT_STREQ(GetTypeName<Types<int>>().c_str(), tests[0]->type_param());
|
||||
EXPECT_TRUE(tests[0]->should_run());
|
||||
EXPECT_TRUE(tests[0]->result()->Passed());
|
||||
EXPECT_EQ(0, tests[0]->result()->test_property_count());
|
||||
|
||||
delete[] tests;
|
||||
#endif // GTEST_HAS_TYPED_TEST
|
||||
delete[] test_suites;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -116,7 +116,7 @@ void Check(bool condition, const char* msg) {
|
||||
}
|
||||
}
|
||||
|
||||
// Runs the tests. Return true iff successful.
|
||||
// Runs the tests. Return true if and only if successful.
|
||||
//
|
||||
// The 'failure' parameter specifies the type of failure that should
|
||||
// be generated by the global set-up.
|
||||
|
||||
+3
-1
@@ -43,6 +43,7 @@ import gtest_test_utils
|
||||
|
||||
|
||||
IS_LINUX = os.name == 'posix' and os.uname()[0] == 'Linux'
|
||||
IS_GNUKFREEBSD = os.name == 'posix' and os.uname()[0] == 'GNU/kFreeBSD'
|
||||
IS_WINDOWS = os.name == 'nt'
|
||||
|
||||
PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath('gtest_help_test_')
|
||||
@@ -68,6 +69,7 @@ HELP_REGEX = re.compile(
|
||||
FLAG_PREFIX + r'shuffle.*' +
|
||||
FLAG_PREFIX + r'random_seed=.*' +
|
||||
FLAG_PREFIX + r'color=.*' +
|
||||
FLAG_PREFIX + r'brief.*' +
|
||||
FLAG_PREFIX + r'print_time.*' +
|
||||
FLAG_PREFIX + r'output=.*' +
|
||||
FLAG_PREFIX + r'break_on_failure.*' +
|
||||
@@ -110,7 +112,7 @@ class GTestHelpTest(gtest_test_utils.TestCase):
|
||||
self.assertEquals(0, exit_code)
|
||||
self.assert_(HELP_REGEX.search(output), output)
|
||||
|
||||
if IS_LINUX:
|
||||
if IS_LINUX or IS_GNUKFREEBSD:
|
||||
self.assert_(STREAM_RESULT_TO_FLAG in output, output)
|
||||
else:
|
||||
self.assert_(STREAM_RESULT_TO_FLAG not in output, output)
|
||||
|
||||
+150
-5
@@ -46,16 +46,42 @@ GTEST_LIST_TESTS_FLAG = '--gtest_list_tests'
|
||||
GTEST_OUTPUT_FLAG = '--gtest_output'
|
||||
|
||||
EXPECTED_XML = """<\?xml version="1.0" encoding="UTF-8"\?>
|
||||
<testsuites tests="2" name="AllTests">
|
||||
<testsuites tests="16" name="AllTests">
|
||||
<testsuite name="FooTest" tests="2">
|
||||
<testcase name="Test1" file=".*gtest_list_output_unittest_.cc" line="43" />
|
||||
<testcase name="Test2" file=".*gtest_list_output_unittest_.cc" line="45" />
|
||||
</testsuite>
|
||||
<testsuite name="FooTestFixture" tests="2">
|
||||
<testcase name="Test3" file=".*gtest_list_output_unittest_.cc" line="48" />
|
||||
<testcase name="Test4" file=".*gtest_list_output_unittest_.cc" line="49" />
|
||||
</testsuite>
|
||||
<testsuite name="TypedTest/0" tests="2">
|
||||
<testcase name="Test7" type_param="int" file=".*gtest_list_output_unittest_.cc" line="60" />
|
||||
<testcase name="Test8" type_param="int" file=".*gtest_list_output_unittest_.cc" line="61" />
|
||||
</testsuite>
|
||||
<testsuite name="TypedTest/1" tests="2">
|
||||
<testcase name="Test7" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="60" />
|
||||
<testcase name="Test8" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="61" />
|
||||
</testsuite>
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/0" tests="2">
|
||||
<testcase name="Test9" type_param="int" file=".*gtest_list_output_unittest_.cc" line="66" />
|
||||
<testcase name="Test10" type_param="int" file=".*gtest_list_output_unittest_.cc" line="67" />
|
||||
</testsuite>
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/1" tests="2">
|
||||
<testcase name="Test9" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="66" />
|
||||
<testcase name="Test10" type_param="bool" file=".*gtest_list_output_unittest_.cc" line="67" />
|
||||
</testsuite>
|
||||
<testsuite name="ValueParam/ValueParamTest" tests="4">
|
||||
<testcase name="Test5/0" value_param="33" file=".*gtest_list_output_unittest_.cc" line="52" />
|
||||
<testcase name="Test5/1" value_param="42" file=".*gtest_list_output_unittest_.cc" line="52" />
|
||||
<testcase name="Test6/0" value_param="33" file=".*gtest_list_output_unittest_.cc" line="53" />
|
||||
<testcase name="Test6/1" value_param="42" file=".*gtest_list_output_unittest_.cc" line="53" />
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
"""
|
||||
|
||||
EXPECTED_JSON = """{
|
||||
"tests": 2,
|
||||
"tests": 16,
|
||||
"name": "AllTests",
|
||||
"testsuites": \[
|
||||
{
|
||||
@@ -73,6 +99,124 @@ EXPECTED_JSON = """{
|
||||
"line": 45
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "FooTestFixture",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test3",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 48
|
||||
},
|
||||
{
|
||||
"name": "Test4",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 49
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "TypedTest\\\\/0",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test7",
|
||||
"type_param": "int",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 60
|
||||
},
|
||||
{
|
||||
"name": "Test8",
|
||||
"type_param": "int",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 61
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "TypedTest\\\\/1",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test7",
|
||||
"type_param": "bool",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 60
|
||||
},
|
||||
{
|
||||
"name": "Test8",
|
||||
"type_param": "bool",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 61
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "Single\\\\/TypeParameterizedTestSuite\\\\/0",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test9",
|
||||
"type_param": "int",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 66
|
||||
},
|
||||
{
|
||||
"name": "Test10",
|
||||
"type_param": "int",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 67
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "Single\\\\/TypeParameterizedTestSuite\\\\/1",
|
||||
"tests": 2,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test9",
|
||||
"type_param": "bool",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 66
|
||||
},
|
||||
{
|
||||
"name": "Test10",
|
||||
"type_param": "bool",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 67
|
||||
}
|
||||
\]
|
||||
},
|
||||
{
|
||||
"name": "ValueParam\\\\/ValueParamTest",
|
||||
"tests": 4,
|
||||
"testsuite": \[
|
||||
{
|
||||
"name": "Test5\\\\/0",
|
||||
"value_param": "33",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 52
|
||||
},
|
||||
{
|
||||
"name": "Test5\\\\/1",
|
||||
"value_param": "42",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 52
|
||||
},
|
||||
{
|
||||
"name": "Test6\\\\/0",
|
||||
"value_param": "33",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 53
|
||||
},
|
||||
{
|
||||
"name": "Test6\\\\/1",
|
||||
"value_param": "42",
|
||||
"file": ".*gtest_list_output_unittest_.cc",
|
||||
"line": 53
|
||||
}
|
||||
\]
|
||||
}
|
||||
\]
|
||||
}
|
||||
@@ -114,8 +258,9 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
||||
p = gtest_test_utils.Subprocess(
|
||||
command, env=environ_copy, working_dir=gtest_test_utils.GetTempDir())
|
||||
|
||||
self.assert_(p.exited)
|
||||
self.assertEquals(0, p.exit_code)
|
||||
self.assertTrue(p.exited)
|
||||
self.assertEqual(0, p.exit_code)
|
||||
self.assertTrue(os.path.isfile(file_path))
|
||||
with open(file_path) as f:
|
||||
result = f.read()
|
||||
return result
|
||||
@@ -128,7 +273,7 @@ class GTestListTestsOutputUnitTest(gtest_test_utils.TestCase):
|
||||
for actual_line in actual_lines:
|
||||
expected_line = expected_lines[line_count]
|
||||
expected_line_re = re.compile(expected_line.strip())
|
||||
self.assert_(
|
||||
self.assertTrue(
|
||||
expected_line_re.match(actual_line.strip()),
|
||||
('actual output of "%s",\n'
|
||||
'which does not match expected regex of "%s"\n'
|
||||
|
||||
@@ -44,6 +44,32 @@ TEST(FooTest, Test1) {}
|
||||
|
||||
TEST(FooTest, Test2) {}
|
||||
|
||||
class FooTestFixture : public ::testing::Test {};
|
||||
TEST_F(FooTestFixture, Test3) {}
|
||||
TEST_F(FooTestFixture, Test4) {}
|
||||
|
||||
class ValueParamTest : public ::testing::TestWithParam<int> {};
|
||||
TEST_P(ValueParamTest, Test5) {}
|
||||
TEST_P(ValueParamTest, Test6) {}
|
||||
INSTANTIATE_TEST_SUITE_P(ValueParam, ValueParamTest, ::testing::Values(33, 42));
|
||||
|
||||
template <typename T>
|
||||
class TypedTest : public ::testing::Test {};
|
||||
typedef testing::Types<int, bool> TypedTestTypes;
|
||||
TYPED_TEST_SUITE(TypedTest, TypedTestTypes);
|
||||
TYPED_TEST(TypedTest, Test7) {}
|
||||
TYPED_TEST(TypedTest, Test8) {}
|
||||
|
||||
template <typename T>
|
||||
class TypeParameterizedTestSuite : public ::testing::Test {};
|
||||
TYPED_TEST_SUITE_P(TypeParameterizedTestSuite);
|
||||
TYPED_TEST_P(TypeParameterizedTestSuite, Test9) {}
|
||||
TYPED_TEST_P(TypeParameterizedTestSuite, Test10) {}
|
||||
REGISTER_TYPED_TEST_SUITE_P(TypeParameterizedTestSuite, Test9, Test10);
|
||||
typedef testing::Types<int, bool> TypeParameterizedTestSuiteTypes; // NOLINT
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Single, TypeParameterizedTestSuite,
|
||||
TypeParameterizedTestSuiteTypes);
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
|
||||
|
||||
+21
-26
@@ -27,7 +27,7 @@
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
// This file is AUTOMATICALLY GENERATED on 01/02/2019 by command
|
||||
// This file is AUTOMATICALLY GENERATED on 11/05/2019 by command
|
||||
// 'gen_gtest_pred_impl.py 5'. DO NOT EDIT BY HAND!
|
||||
|
||||
// Regression test for gtest_pred_impl.h
|
||||
@@ -78,9 +78,8 @@ bool PredFunction1(T1 v1) {
|
||||
return v1 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
bool PredFunction1Int(int v1) {
|
||||
return v1 > 0;
|
||||
}
|
||||
@@ -144,10 +143,10 @@ class Predicate1Test : public testing::Test {
|
||||
}
|
||||
}
|
||||
|
||||
// true iff the test function is expected to run to finish.
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true iff the test function did run to finish.
|
||||
// true if and only if the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
@@ -465,9 +464,8 @@ bool PredFunction2(T1 v1, T2 v2) {
|
||||
return v1 + v2 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
bool PredFunction2Int(int v1, int v2) {
|
||||
return v1 + v2 > 0;
|
||||
}
|
||||
@@ -539,10 +537,10 @@ class Predicate2Test : public testing::Test {
|
||||
}
|
||||
}
|
||||
|
||||
// true iff the test function is expected to run to finish.
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true iff the test function did run to finish.
|
||||
// true if and only if the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
@@ -894,9 +892,8 @@ bool PredFunction3(T1 v1, T2 v2, T3 v3) {
|
||||
return v1 + v2 + v3 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
bool PredFunction3Int(int v1, int v2, int v3) {
|
||||
return v1 + v2 + v3 > 0;
|
||||
}
|
||||
@@ -976,10 +973,10 @@ class Predicate3Test : public testing::Test {
|
||||
}
|
||||
}
|
||||
|
||||
// true iff the test function is expected to run to finish.
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true iff the test function did run to finish.
|
||||
// true if and only if the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
@@ -1365,9 +1362,8 @@ bool PredFunction4(T1 v1, T2 v2, T3 v3, T4 v4) {
|
||||
return v1 + v2 + v3 + v4 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
bool PredFunction4Int(int v1, int v2, int v3, int v4) {
|
||||
return v1 + v2 + v3 + v4 > 0;
|
||||
}
|
||||
@@ -1455,10 +1451,10 @@ class Predicate4Test : public testing::Test {
|
||||
}
|
||||
}
|
||||
|
||||
// true iff the test function is expected to run to finish.
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true iff the test function did run to finish.
|
||||
// true if and only if the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
@@ -1878,9 +1874,8 @@ bool PredFunction5(T1 v1, T2 v2, T3 v3, T4 v4, T5 v5) {
|
||||
return v1 + v2 + v3 + v4 + v5 > 0;
|
||||
}
|
||||
|
||||
// The following two functions are needed to circumvent a bug in
|
||||
// gcc 2.95.3, which sometimes has problem with the above template
|
||||
// function.
|
||||
// The following two functions are needed because a compiler doesn't have
|
||||
// a context yet to know which template function must be instantiated.
|
||||
bool PredFunction5Int(int v1, int v2, int v3, int v4, int v5) {
|
||||
return v1 + v2 + v3 + v4 + v5 > 0;
|
||||
}
|
||||
@@ -1976,10 +1971,10 @@ class Predicate5Test : public testing::Test {
|
||||
}
|
||||
}
|
||||
|
||||
// true iff the test function is expected to run to finish.
|
||||
// true if and only if the test function is expected to run to finish.
|
||||
static bool expected_to_finish_;
|
||||
|
||||
// true iff the test function did run to finish.
|
||||
// true if and only if the test function did run to finish.
|
||||
static bool finished_;
|
||||
|
||||
static int n1_;
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace {
|
||||
|
||||
class PrematureExitTest : public Test {
|
||||
public:
|
||||
// Returns true iff the given file exists.
|
||||
// Returns true if and only if the given file exists.
|
||||
static bool FileExists(const char* filepath) {
|
||||
StatStruct stat;
|
||||
return Stat(filepath, &stat) == 0;
|
||||
@@ -61,7 +61,7 @@ class PrematureExitTest : public Test {
|
||||
}
|
||||
}
|
||||
|
||||
// Returns true iff the premature-exit file exists.
|
||||
// Returns true if and only if the premature-exit file exists.
|
||||
bool PrematureExitFileExists() const {
|
||||
return FileExists(premature_exit_file_path_);
|
||||
}
|
||||
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright 2019 Google LLC. All Rights Reserved.
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
# modification, are permitted provided that the following conditions are
|
||||
# met:
|
||||
#
|
||||
# * Redistributions of source code must retain the above copyright
|
||||
# notice, this list of conditions and the following disclaimer.
|
||||
# * Redistributions in binary form must reproduce the above
|
||||
# copyright notice, this list of conditions and the following disclaimer
|
||||
# in the documentation and/or other materials provided with the
|
||||
# distribution.
|
||||
# * Neither the name of Google Inc. nor the names of its
|
||||
# contributors may be used to endorse or promote products derived from
|
||||
# this software without specific prior written permission.
|
||||
#
|
||||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
"""Tests Google Test's gtest skip in environment setup behavior.
|
||||
|
||||
This script invokes gtest_skip_in_environment_setup_test_ and verifies its
|
||||
output.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
import gtest_test_utils
|
||||
|
||||
# Path to the gtest_skip_in_environment_setup_test binary
|
||||
EXE_PATH = gtest_test_utils.GetTestExecutablePath('gtest_skip_test')
|
||||
|
||||
OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output
|
||||
|
||||
|
||||
# Test.
|
||||
class SkipEntireEnvironmentTest(gtest_test_utils.TestCase):
|
||||
|
||||
def testSkipEntireEnvironmentTest(self):
|
||||
self.assertIn('Skipped\nskipping single test\n', OUTPUT)
|
||||
skip_fixture = 'Skipped\nskipping all tests for this fixture\n'
|
||||
self.assertIsNotNone(
|
||||
re.search(skip_fixture + '.*' + skip_fixture, OUTPUT, flags=re.DOTALL),
|
||||
repr(OUTPUT))
|
||||
self.assertNotIn('FAILED', OUTPUT)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
gtest_test_utils.Main()
|
||||
Vendored
Regular → Executable
@@ -35,7 +35,7 @@
|
||||
using ::testing::Test;
|
||||
|
||||
TEST(SkipTest, DoesSkip) {
|
||||
GTEST_SKIP();
|
||||
GTEST_SKIP() << "skipping single test";
|
||||
EXPECT_EQ(0, 1);
|
||||
}
|
||||
|
||||
|
||||
+5
-6
@@ -215,10 +215,10 @@ class Subprocess:
|
||||
Returns:
|
||||
An object that represents outcome of the executed process. It has the
|
||||
following attributes:
|
||||
terminated_by_signal True iff the child process has been terminated
|
||||
by a signal.
|
||||
signal Sygnal that terminated the child process.
|
||||
exited True iff the child process exited normally.
|
||||
terminated_by_signal True if and only if the child process has been
|
||||
terminated by a signal.
|
||||
exited True if and only if the child process exited
|
||||
normally.
|
||||
exit_code The code with which the child process exited.
|
||||
output Child process's stdout and stderr output
|
||||
combined in a string.
|
||||
@@ -288,10 +288,9 @@ class Subprocess:
|
||||
else: # os.WIFEXITED(ret_code) should return True here.
|
||||
self._return_code = os.WEXITSTATUS(ret_code)
|
||||
|
||||
if self._return_code < 0:
|
||||
if bool(self._return_code & 0x80000000):
|
||||
self.terminated_by_signal = True
|
||||
self.exited = False
|
||||
self.signal = -self._return_code
|
||||
else:
|
||||
self.terminated_by_signal = False
|
||||
self.exited = True
|
||||
|
||||
Vendored
Regular → Executable
+465
-249
File diff suppressed because it is too large
Load Diff
Vendored
Regular → Executable
+4
-4
@@ -42,8 +42,8 @@ GTEST_OUTPUT_2_TEST = "gtest_xml_outfile2_test_"
|
||||
|
||||
EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
|
||||
<testsuite name="PropertyOne" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="TestSomeProperties" status="run" result="completed" time="*" classname="PropertyOne">
|
||||
<testsuite name="PropertyOne" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="TestSomeProperties" status="run" result="completed" time="*" timestamp="*" classname="PropertyOne">
|
||||
<properties>
|
||||
<property name="SetUpProp" value="1"/>
|
||||
<property name="TestSomeProperty" value="1"/>
|
||||
@@ -56,8 +56,8 @@ EXPECTED_XML_1 = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
|
||||
EXPECTED_XML_2 = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests">
|
||||
<testsuite name="PropertyTwo" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="TestSomeProperties" status="run" result="completed" time="*" classname="PropertyTwo">
|
||||
<testsuite name="PropertyTwo" tests="1" failures="0" skipped="0" disabled="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="TestSomeProperties" status="run" result="completed" time="*" timestamp="*" classname="PropertyTwo">
|
||||
<properties>
|
||||
<property name="SetUpProp" value="2"/>
|
||||
<property name="TestSomeProperty" value="2"/>
|
||||
|
||||
Vendored
Regular → Executable
+81
-55
@@ -65,21 +65,21 @@ else:
|
||||
sys.argv.remove(NO_STACKTRACE_SUPPORT_FLAG)
|
||||
|
||||
EXPECTED_NON_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="24" failures="4" disabled="2" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" classname="SuccessfulTest"/>
|
||||
<testsuites tests="26" failures="5" disabled="2" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/>
|
||||
</testsuite>
|
||||
<testsuite name="FailedTest" tests="1" failures="1" disabled="0" errors="0" time="*">
|
||||
<testcase name="Fails" status="run" result="completed" time="*" classname="FailedTest">
|
||||
<testsuite name="FailedTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Fails" status="run" result="completed" time="*" timestamp="*" classname="FailedTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Expected equality of these values:
|
||||
1
|
||||
2%(stack)s]]></failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" errors="0" time="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" classname="MixedResultTest"/>
|
||||
<testcase name="Fails" status="run" result="completed" time="*" classname="MixedResultTest">
|
||||
<testsuite name="MixedResultTest" tests="3" failures="1" disabled="1" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest"/>
|
||||
<testcase name="Fails" status="run" result="completed" time="*" timestamp="*" classname="MixedResultTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Expected equality of these values:
|
||||
1
|
||||
@@ -89,86 +89,102 @@ Expected equality of these values:
|
||||
2
|
||||
3%(stack)s]]></failure>
|
||||
</testcase>
|
||||
<testcase name="DISABLED_test" status="notrun" result="suppressed" time="*" classname="MixedResultTest"/>
|
||||
<testcase name="DISABLED_test" status="notrun" result="suppressed" time="*" timestamp="*" classname="MixedResultTest"/>
|
||||
</testsuite>
|
||||
<testsuite name="XmlQuotingTest" tests="1" failures="1" disabled="0" errors="0" time="*">
|
||||
<testcase name="OutputsCData" status="run" result="completed" time="*" classname="XmlQuotingTest">
|
||||
<testsuite name="XmlQuotingTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="OutputsCData" status="run" result="completed" time="*" timestamp="*" classname="XmlQuotingTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Failed
XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]></top>" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Failed
|
||||
XML output: <?xml encoding="utf-8"><top><![CDATA[cdata text]]>]]><![CDATA[</top>%(stack)s]]></failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="InvalidCharactersTest" tests="1" failures="1" disabled="0" errors="0" time="*">
|
||||
<testcase name="InvalidCharactersInMessage" status="run" result="completed" time="*" classname="InvalidCharactersTest">
|
||||
<testsuite name="InvalidCharactersTest" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="InvalidCharactersInMessage" status="run" result="completed" time="*" timestamp="*" classname="InvalidCharactersTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Failed
Invalid characters in brackets []" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Failed
|
||||
Invalid characters in brackets []%(stack)s]]></failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="DisabledTest" tests="1" failures="0" disabled="1" errors="0" time="*">
|
||||
<testcase name="DISABLED_test_not_run" status="notrun" result="suppressed" time="*" classname="DisabledTest"/>
|
||||
<testsuite name="DisabledTest" tests="1" failures="0" disabled="1" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="DISABLED_test_not_run" status="notrun" result="suppressed" time="*" timestamp="*" classname="DisabledTest"/>
|
||||
</testsuite>
|
||||
<testsuite name="SkippedTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="Skipped" status="run" result="skipped" time="*" classname="SkippedTest"/>
|
||||
<testsuite name="SkippedTest" tests="3" failures="1" disabled="0" skipped="2" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Skipped" status="run" result="skipped" time="*" timestamp="*" classname="SkippedTest">
|
||||
<skipped message="gtest_xml_output_unittest_.cc:*
"><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
%(stack)s]]></skipped>
|
||||
</testcase>
|
||||
<testcase name="SkippedWithMessage" status="run" result="skipped" time="*" timestamp="*" classname="SkippedTest">
|
||||
<skipped message="gtest_xml_output_unittest_.cc:*
It is good practice to tell why you skip a test."><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
It is good practice to tell why you skip a test.%(stack)s]]></skipped>
|
||||
</testcase>
|
||||
<testcase name="SkippedAfterFailure" status="run" result="completed" time="*" timestamp="*" classname="SkippedTest">
|
||||
<failure message="gtest_xml_output_unittest_.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
Expected equality of these values:
|
||||
1
|
||||
2%(stack)s]]></failure>
|
||||
<skipped message="gtest_xml_output_unittest_.cc:*
It is good practice to tell why you skip a test."><![CDATA[gtest_xml_output_unittest_.cc:*
|
||||
It is good practice to tell why you skip a test.%(stack)s]]></skipped>
|
||||
</testcase>
|
||||
|
||||
</testsuite>
|
||||
<testsuite name="PropertyRecordingTest" tests="4" failures="0" disabled="0" errors="0" time="*" SetUpTestSuite="yes" TearDownTestSuite="aye">
|
||||
<testcase name="OneProperty" status="run" result="completed" time="*" classname="PropertyRecordingTest">
|
||||
<testsuite name="PropertyRecordingTest" tests="4" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*" SetUpTestSuite="yes" TearDownTestSuite="aye">
|
||||
<testcase name="OneProperty" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_1" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="IntValuedProperty" status="run" result="completed" time="*" classname="PropertyRecordingTest">
|
||||
<testcase name="IntValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_int" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="ThreeProperties" status="run" result="completed" time="*" classname="PropertyRecordingTest">
|
||||
<testcase name="ThreeProperties" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_1" value="1"/>
|
||||
<property name="key_2" value="2"/>
|
||||
<property name="key_3" value="3"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="TwoValuesForOneKeyUsesLastValue" status="run" result="completed" time="*" classname="PropertyRecordingTest">
|
||||
<testcase name="TwoValuesForOneKeyUsesLastValue" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_1" value="2"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="NoFixtureTest" tests="3" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="RecordProperty" status="run" result="completed" time="*" classname="NoFixtureTest">
|
||||
<testsuite name="NoFixtureTest" tests="3" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="RecordProperty" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest">
|
||||
<properties>
|
||||
<property name="key" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" result="completed" time="*" classname="NoFixtureTest">
|
||||
<testcase name="ExternalUtilityThatCallsRecordIntValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest">
|
||||
<properties>
|
||||
<property name="key_for_utility_int" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
<testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" result="completed" time="*" classname="NoFixtureTest">
|
||||
<testcase name="ExternalUtilityThatCallsRecordStringValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="NoFixtureTest">
|
||||
<properties>
|
||||
<property name="key_for_utility_string" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="Single/ValueParamTest" tests="4" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="HasValueParamAttribute/1" value_param="42" status="run" result="completed" time="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" result="completed" time="*" classname="Single/ValueParamTest" />
|
||||
<testsuite name="Single/ValueParamTest" tests="4" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="HasValueParamAttribute/1" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/1" value_param="42" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
</testsuite>
|
||||
<testsuite name="TypedTest/0" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" classname="TypedTest/0" />
|
||||
<testsuite name="TypedTest/0" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/0" />
|
||||
</testsuite>
|
||||
<testsuite name="TypedTest/1" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" classname="TypedTest/1" />
|
||||
<testsuite name="TypedTest/1" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="TypedTest/1" />
|
||||
</testsuite>
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/0" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" classname="Single/TypeParameterizedTestSuite/0" />
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/0" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/0" />
|
||||
</testsuite>
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/1" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" classname="Single/TypeParameterizedTestSuite/1" />
|
||||
<testsuite name="Single/TypeParameterizedTestSuite/1" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasTypeParamAttribute" type_param="*" status="run" result="completed" time="*" timestamp="*" classname="Single/TypeParameterizedTestSuite/1" />
|
||||
</testsuite>
|
||||
</testsuites>""" % {
|
||||
'stack': STACK_TRACE_TEMPLATE
|
||||
@@ -177,33 +193,43 @@ Invalid characters in brackets []%(stack)s]]></failure>
|
||||
EXPECTED_FILTERED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="1" failures="0" disabled="0" errors="0" time="*"
|
||||
timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0"
|
||||
errors="0" time="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" classname="SuccessfulTest"/>
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0"
|
||||
errors="0" time="*" timestamp="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/>
|
||||
</testsuite>
|
||||
</testsuites>"""
|
||||
|
||||
EXPECTED_SHARDED_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="3" failures="0" disabled="0" errors="0" time="*" timestamp="*" name="AllTests" ad_hoc_property="42">
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" classname="SuccessfulTest"/>
|
||||
<testsuite name="SuccessfulTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="Succeeds" status="run" result="completed" time="*" timestamp="*" classname="SuccessfulTest"/>
|
||||
</testsuite>
|
||||
<testsuite name="PropertyRecordingTest" tests="1" failures="0" disabled="0" errors="0" time="*" SetUpTestSuite="yes" TearDownTestSuite="aye">
|
||||
<testcase name="TwoValuesForOneKeyUsesLastValue" status="run" result="completed" time="*" classname="PropertyRecordingTest">
|
||||
<testsuite name="PropertyRecordingTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*" SetUpTestSuite="yes" TearDownTestSuite="aye">
|
||||
<testcase name="IntValuedProperty" status="run" result="completed" time="*" timestamp="*" classname="PropertyRecordingTest">
|
||||
<properties>
|
||||
<property name="key_1" value="2"/>
|
||||
<property name="key_int" value="1"/>
|
||||
</properties>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
<testsuite name="Single/ValueParamTest" tests="1" failures="0" disabled="0" errors="0" time="*">
|
||||
<testcase name="AnotherTestThatHasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" classname="Single/ValueParamTest" />
|
||||
<testsuite name="Single/ValueParamTest" tests="1" failures="0" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="HasValueParamAttribute/0" value_param="33" status="run" result="completed" time="*" timestamp="*" classname="Single/ValueParamTest" />
|
||||
</testsuite>
|
||||
</testsuites>"""
|
||||
|
||||
EXPECTED_EMPTY_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
EXPECTED_NO_TEST_XML = """<?xml version="1.0" encoding="UTF-8"?>
|
||||
<testsuites tests="0" failures="0" disabled="0" errors="0" time="*"
|
||||
timestamp="*" name="AllTests">
|
||||
</testsuites>"""
|
||||
<testsuite name="NonTestSuiteFailure" tests="1" failures="1" disabled="0" skipped="0" errors="0" time="*" timestamp="*">
|
||||
<testcase name="" status="run" result="completed" time="*" timestamp="*" classname="">
|
||||
<failure message="gtest_no_test_unittest.cc:*
Expected equality of these values:
 1
 2" type=""><![CDATA[gtest_no_test_unittest.cc:*
|
||||
Expected equality of these values:
|
||||
1
|
||||
2%(stack)s]]></failure>
|
||||
</testcase>
|
||||
</testsuite>
|
||||
</testsuites>""" % {
|
||||
'stack': STACK_TRACE_TEMPLATE
|
||||
}
|
||||
|
||||
GTEST_PROGRAM_PATH = gtest_test_utils.GetTestExecutablePath(GTEST_PROGRAM_NAME)
|
||||
|
||||
@@ -226,14 +252,14 @@ class GTestXMLOutputUnitTest(gtest_xml_test_utils.GTestXMLTestCase):
|
||||
"""
|
||||
self._TestXmlOutput(GTEST_PROGRAM_NAME, EXPECTED_NON_EMPTY_XML, 1)
|
||||
|
||||
def testEmptyXmlOutput(self):
|
||||
def testNoTestXmlOutput(self):
|
||||
"""Verifies XML output for a Google Test binary without actual tests.
|
||||
|
||||
Runs a test program that generates an empty XML output, and
|
||||
tests that the XML output is expected.
|
||||
Runs a test program that generates an XML output for a binary without tests,
|
||||
and tests that the XML output is expected.
|
||||
"""
|
||||
|
||||
self._TestXmlOutput('gtest_no_test_unittest', EXPECTED_EMPTY_XML, 0)
|
||||
self._TestXmlOutput('gtest_no_test_unittest', EXPECTED_NO_TEST_XML, 0)
|
||||
|
||||
def testTimestampValue(self):
|
||||
"""Checks whether the timestamp attribute in the XML output is valid.
|
||||
|
||||
+9
-4
@@ -74,6 +74,15 @@ TEST_F(SkippedTest, Skipped) {
|
||||
GTEST_SKIP();
|
||||
}
|
||||
|
||||
TEST_F(SkippedTest, SkippedWithMessage) {
|
||||
GTEST_SKIP() << "It is good practice to tell why you skip a test.";
|
||||
}
|
||||
|
||||
TEST_F(SkippedTest, SkippedAfterFailure) {
|
||||
EXPECT_EQ(1, 2);
|
||||
GTEST_SKIP() << "It is good practice to tell why you skip a test.";
|
||||
}
|
||||
|
||||
TEST(MixedResultTest, Succeeds) {
|
||||
EXPECT_EQ(1, 1);
|
||||
ASSERT_EQ(1, 1);
|
||||
@@ -154,16 +163,13 @@ TEST_P(ValueParamTest, HasValueParamAttribute) {}
|
||||
TEST_P(ValueParamTest, AnotherTestThatHasValueParamAttribute) {}
|
||||
INSTANTIATE_TEST_SUITE_P(Single, ValueParamTest, Values(33, 42));
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST
|
||||
// Verifies that the type parameter name is output in the 'type_param'
|
||||
// XML attribute for typed tests.
|
||||
template <typename T> class TypedTest : public Test {};
|
||||
typedef testing::Types<int, long> TypedTestTypes;
|
||||
TYPED_TEST_SUITE(TypedTest, TypedTestTypes);
|
||||
TYPED_TEST(TypedTest, HasTypeParamAttribute) {}
|
||||
#endif
|
||||
|
||||
#if GTEST_HAS_TYPED_TEST_P
|
||||
// Verifies that the type parameter name is output in the 'type_param'
|
||||
// XML attribute for type-parameterized tests.
|
||||
template <typename T>
|
||||
@@ -174,7 +180,6 @@ REGISTER_TYPED_TEST_SUITE_P(TypeParameterizedTestSuite, HasTypeParamAttribute);
|
||||
typedef testing::Types<int, long> TypeParameterizedTestSuiteTypes; // NOLINT
|
||||
INSTANTIATE_TYPED_TEST_SUITE_P(Single, TypeParameterizedTestSuite,
|
||||
TypeParameterizedTestSuiteTypes);
|
||||
#endif
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
InitGoogleTest(&argc, argv);
|
||||
|
||||
+6
-5
@@ -70,7 +70,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
||||
self.assertEquals(expected_node.tagName, actual_node.tagName)
|
||||
|
||||
expected_attributes = expected_node.attributes
|
||||
actual_attributes = actual_node .attributes
|
||||
actual_attributes = actual_node.attributes
|
||||
self.assertEquals(
|
||||
expected_attributes.length, actual_attributes.length,
|
||||
'attribute numbers differ in element %s:\nExpected: %r\nActual: %r' % (
|
||||
@@ -78,7 +78,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
||||
actual_attributes.keys()))
|
||||
for i in range(expected_attributes.length):
|
||||
expected_attr = expected_attributes.item(i)
|
||||
actual_attr = actual_attributes.get(expected_attr.name)
|
||||
actual_attr = actual_attributes.get(expected_attr.name)
|
||||
self.assert_(
|
||||
actual_attr is not None,
|
||||
'expected attribute %s not found in element %s' %
|
||||
@@ -105,6 +105,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
||||
'testsuite': 'name',
|
||||
'testcase': 'name',
|
||||
'failure': 'message',
|
||||
'skipped': 'message',
|
||||
'property': 'name',
|
||||
}
|
||||
|
||||
@@ -169,9 +170,9 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
||||
* The stack traces are removed.
|
||||
"""
|
||||
|
||||
if element.tagName == 'testsuites':
|
||||
if element.tagName in ('testsuites', 'testsuite', 'testcase'):
|
||||
timestamp = element.getAttributeNode('timestamp')
|
||||
timestamp.value = re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d$',
|
||||
timestamp.value = re.sub(r'^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d\.\d\d\d$',
|
||||
'*', timestamp.value)
|
||||
if element.tagName in ('testsuites', 'testsuite', 'testcase'):
|
||||
time = element.getAttributeNode('time')
|
||||
@@ -179,7 +180,7 @@ class GTestXMLTestCase(gtest_test_utils.TestCase):
|
||||
type_param = element.getAttributeNode('type_param')
|
||||
if type_param and type_param.value:
|
||||
type_param.value = '*'
|
||||
elif element.tagName == 'failure':
|
||||
elif element.tagName == 'failure' or element.tagName == 'skipped':
|
||||
source_line_pat = r'^.*[/\\](.*:)\d+\n'
|
||||
# Replaces the source line information with a normalized form.
|
||||
message = element.getAttributeNode('message')
|
||||
|
||||
@@ -30,8 +30,8 @@
|
||||
//
|
||||
// This is part of the unit test for gtest_prod.h.
|
||||
|
||||
#ifndef GTEST_TEST_PRODUCTION_H_
|
||||
#define GTEST_TEST_PRODUCTION_H_
|
||||
#ifndef GOOGLETEST_TEST_PRODUCTION_H_
|
||||
#define GOOGLETEST_TEST_PRODUCTION_H_
|
||||
|
||||
#include "gtest/gtest_prod.h"
|
||||
|
||||
@@ -51,4 +51,4 @@ class PrivateCode {
|
||||
int x_;
|
||||
};
|
||||
|
||||
#endif // GTEST_TEST_PRODUCTION_H_
|
||||
#endif // GOOGLETEST_TEST_PRODUCTION_H_
|
||||
|
||||
Reference in New Issue
Block a user