Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
yangql
googletest
Commits
3e062a6e
Commit
3e062a6e
authored
Nov 05, 2019
by
Xiaoyi Zhang
Browse files
Merge pull request #2373 from Youw:master
PiperOrigin-RevId: 278601074
parents
8697709e
f626deda
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
3 deletions
+46
-3
googletest/include/gtest/internal/gtest-internal.h
googletest/include/gtest/internal/gtest-internal.h
+33
-3
googletest/test/gtest_unittest.cc
googletest/test/gtest_unittest.cc
+13
-0
No files found.
googletest/include/gtest/internal/gtest-internal.h
View file @
3e062a6e
...
@@ -825,6 +825,16 @@ struct GTEST_API_ ConstCharPtr {
...
@@ -825,6 +825,16 @@ struct GTEST_API_ ConstCharPtr {
const
char
*
value
;
const
char
*
value
;
};
};
// Helper for declaring std::string within 'if' statement
// in pre C++17 build environment.
struct
GTEST_API_
TrueWithString
{
TrueWithString
()
=
default
;
explicit
TrueWithString
(
const
char
*
str
)
:
value
(
str
)
{}
explicit
TrueWithString
(
const
std
::
string
&
str
)
:
value
(
str
)
{}
explicit
operator
bool
()
const
{
return
true
;
}
std
::
string
value
;
};
// A simple Linear Congruential Generator for generating random
// A simple Linear Congruential Generator for generating random
// numbers with a uniform distribution. Unlike rand() and srand(), it
// numbers with a uniform distribution. Unlike rand() and srand(), it
// doesn't use global state (and therefore can't interfere with user
// doesn't use global state (and therefore can't interfere with user
...
@@ -1284,19 +1294,39 @@ constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; }
...
@@ -1284,19 +1294,39 @@ constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; }
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
fail(gtest_msg.value)
fail(gtest_msg.value)
#if GTEST_HAS_EXCEPTIONS
#define GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \
catch (std::exception const& e) { \
gtest_msg.value = ( \
"it throws std::exception-derived exception with description: \"" \
); \
gtest_msg.value += e.what(); \
gtest_msg.value += "\"."; \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
}
#else // GTEST_HAS_EXCEPTIONS
#define GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_()
#endif // GTEST_HAS_EXCEPTIONS
#define GTEST_TEST_NO_THROW_(statement, fail) \
#define GTEST_TEST_NO_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::
AlwaysTrue()
) { \
if (::testing::internal::
TrueWithString gtest_msg{}
) { \
try { \
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \
} \
GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \
catch (...) { \
catch (...) { \
gtest_msg.value = "it throws."; \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
} \
} \
} else \
} else \
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
fail("Expected: " #statement " doesn't throw an exception.\n" \
fail(
(
"Expected: " #statement " doesn't throw an exception.\n" \
" Actual:
it throws."
)
" Actual:
" + gtest_msg.value).c_str()
)
#define GTEST_TEST_ANY_THROW_(statement, fail) \
#define GTEST_TEST_ANY_THROW_(statement, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
...
...
googletest/test/gtest_unittest.cc
View file @
3e062a6e
...
@@ -3348,6 +3348,9 @@ TEST_F(SingleEvaluationTest, OtherCases) {
...
@@ -3348,6 +3348,9 @@ TEST_F(SingleEvaluationTest, OtherCases) {
void
ThrowAnInteger
()
{
void
ThrowAnInteger
()
{
throw
1
;
throw
1
;
}
}
void
ThrowRuntimeError
(
const
char
*
what
)
{
throw
std
::
runtime_error
(
what
);
}
// Tests that assertion arguments are evaluated exactly once.
// Tests that assertion arguments are evaluated exactly once.
TEST_F
(
SingleEvaluationTest
,
ExceptionTests
)
{
TEST_F
(
SingleEvaluationTest
,
ExceptionTests
)
{
...
@@ -3827,6 +3830,11 @@ TEST(AssertionTest, ASSERT_NO_THROW) {
...
@@ -3827,6 +3830,11 @@ TEST(AssertionTest, ASSERT_NO_THROW) {
EXPECT_FATAL_FAILURE
(
ASSERT_NO_THROW
(
ThrowAnInteger
()),
EXPECT_FATAL_FAILURE
(
ASSERT_NO_THROW
(
ThrowAnInteger
()),
"Expected: ThrowAnInteger() doesn't throw an exception."
"Expected: ThrowAnInteger() doesn't throw an exception."
"
\n
Actual: it throws."
);
"
\n
Actual: it throws."
);
EXPECT_FATAL_FAILURE
(
ASSERT_NO_THROW
(
ThrowRuntimeError
(
"A description"
)),
"Expected: ThrowRuntimeError(
\"
A description
\"
) "
"doesn't throw an exception.
\n
"
"Actual: it throws std::exception-derived exception "
"with description:
\"
A description
\"
."
);
}
}
// Tests ASSERT_ANY_THROW.
// Tests ASSERT_ANY_THROW.
...
@@ -4564,6 +4572,11 @@ TEST(ExpectTest, EXPECT_NO_THROW) {
...
@@ -4564,6 +4572,11 @@ TEST(ExpectTest, EXPECT_NO_THROW) {
EXPECT_NONFATAL_FAILURE
(
EXPECT_NO_THROW
(
ThrowAnInteger
()),
EXPECT_NONFATAL_FAILURE
(
EXPECT_NO_THROW
(
ThrowAnInteger
()),
"Expected: ThrowAnInteger() doesn't throw an "
"Expected: ThrowAnInteger() doesn't throw an "
"exception.
\n
Actual: it throws."
);
"exception.
\n
Actual: it throws."
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_NO_THROW
(
ThrowRuntimeError
(
"A description"
)),
"Expected: ThrowRuntimeError(
\"
A description
\"
) "
"doesn't throw an exception.
\n
"
"Actual: it throws std::exception-derived exception "
"with description:
\"
A description
\"
."
);
}
}
// Tests EXPECT_ANY_THROW.
// Tests EXPECT_ANY_THROW.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment