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
b2788286
Commit
b2788286
authored
Sep 25, 2018
by
misterg
Committed by
Gennadiy Civil
Sep 25, 2018
Browse files
Googletest export
Project import generated by Copybara. PiperOrigin-RevId: 214441835
parent
ba974c97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
43 deletions
+104
-43
googletest/include/gtest/internal/gtest-internal.h
googletest/include/gtest/internal/gtest-internal.h
+64
-39
googletest/test/gtest_unittest.cc
googletest/test/gtest_unittest.cc
+40
-4
No files found.
googletest/include/gtest/internal/gtest-internal.h
View file @
b2788286
...
@@ -1189,6 +1189,18 @@ class NativeArray {
...
@@ -1189,6 +1189,18 @@ class NativeArray {
GTEST_DISALLOW_ASSIGN_
(
NativeArray
);
GTEST_DISALLOW_ASSIGN_
(
NativeArray
);
};
};
class
AdditionalMessage
{
public:
explicit
AdditionalMessage
(
const
char
*
message
)
:
msg_value_
(
message
)
{}
void
set
(
const
std
::
string
&
message
)
{
msg_value_
=
message
;
}
explicit
operator
bool
()
const
{
return
true
;
}
const
std
::
string
&
get
()
const
{
return
msg_value_
;
}
private:
std
::
string
msg_value_
;
};
}
// namespace internal
}
// namespace internal
}
// namespace testing
}
// namespace testing
...
@@ -1214,45 +1226,58 @@ class NativeArray {
...
@@ -1214,45 +1226,58 @@ class NativeArray {
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \
if (::testing::internal::AlwaysTrue()) { statement; }
if (::testing::internal::AlwaysTrue()) { statement; }
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
#define GTEST_TEST_THROW_(statement, expected_exception, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::internal::ConstCharPtr gtest_msg = "") { \
if (::testing::internal::AdditionalMessage message{""}) { \
bool gtest_caught_expected = false; \
bool gtest_caught_expected = false; \
try { \
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
try { \
} \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
catch (expected_exception const&) { \
} catch (expected_exception const&) { \
gtest_caught_expected = true; \
gtest_caught_expected = true; \
} \
throw; \
catch (...) { \
} \
gtest_msg.value = \
} catch (const std::exception& e) { \
"Expected: " #statement " throws an exception of type " \
if (!gtest_caught_expected) { \
#expected_exception ".\n Actual: it throws a different type."; \
message.set("it throws a different type with message: " + \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
std::string(e.what())); \
} \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
if (!gtest_caught_expected) { \
} \
gtest_msg.value = \
} catch (...) { \
"Expected: " #statement " throws an exception of type " \
if (!gtest_caught_expected) { \
#expected_exception ".\n Actual: it throws nothing."; \
message.set("it throws a different type."); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
} \
} \
} else \
} \
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \
if (!gtest_caught_expected) { \
fail(gtest_msg.value)
message.set("it throws nothing."); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
#define GTEST_TEST_NO_THROW_(statement, fail) \
} \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
} else \
if (::testing::internal::AlwaysTrue()) { \
GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__) \
try { \
: fail(("Expected: " #statement \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
" throws an exception of type " #expected_exception \
} \
".\n Actual: " + \
catch (...) { \
message.get()) \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
.c_str())
} \
} else \
#define GTEST_TEST_NO_THROW_(statement, fail) \
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
fail("Expected: " #statement " doesn't throw an exception.\n" \
if (::testing::internal::AdditionalMessage message{"."}) { \
" Actual: it throws.")
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} catch (const std::exception& e) { \
message.set(std::string(": ") + e.what()); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
} catch (...) { \
goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \
} \
} else \
GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__) \
: fail(("Expected: " #statement " doesn't throw an exception.\n" \
" Actual: it throws" + \
message.get()) \
.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 @
b2788286
...
@@ -3328,6 +3328,7 @@ TEST_F(SingleEvaluationTest, OtherCases) {
...
@@ -3328,6 +3328,7 @@ TEST_F(SingleEvaluationTest, OtherCases) {
void
ThrowAnInteger
()
{
void
ThrowAnInteger
()
{
throw
1
;
throw
1
;
}
}
void
ThrowAnException
(
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
)
{
...
@@ -3370,6 +3371,26 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
...
@@ -3370,6 +3371,26 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
// failed EXPECT_ANY_THROW
// failed EXPECT_ANY_THROW
EXPECT_NONFATAL_FAILURE
(
EXPECT_ANY_THROW
(
a_
++
),
"it doesn't"
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_ANY_THROW
(
a_
++
),
"it doesn't"
);
EXPECT_EQ
(
7
,
a_
);
EXPECT_EQ
(
7
,
a_
);
// failed EXPECT_THROW std::exception, throws different
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW
(
{
// NOLINT
a_
++
;
ThrowAnInteger
();
},
std
::
exception
),
"throws a different type"
);
EXPECT_EQ
(
8
,
a_
);
// failed EXPECT_THROW, throws std::exception
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW
(
{
// NOLINT
a_
++
;
ThrowAnException
(
"blablubb"
);
},
bool
),
"throws a different type with message: blablubb"
);
EXPECT_EQ
(
9
,
a_
);
}
}
#endif // GTEST_HAS_EXCEPTIONS
#endif // GTEST_HAS_EXCEPTIONS
...
@@ -3802,6 +3823,11 @@ TEST(AssertionTest, ASSERT_THROW) {
...
@@ -3802,6 +3823,11 @@ TEST(AssertionTest, ASSERT_THROW) {
ASSERT_THROW
(
ThrowNothing
(),
bool
),
ASSERT_THROW
(
ThrowNothing
(),
bool
),
"Expected: ThrowNothing() throws an exception of type bool.
\n
"
"Expected: ThrowNothing() throws an exception of type bool.
\n
"
" Actual: it throws nothing."
);
" Actual: it throws nothing."
);
EXPECT_FATAL_FAILURE
(
ASSERT_THROW
(
ThrowAnException
(
"b"
),
bool
),
"Expected: ThrowAnException(
\"
b
\"
) throws an exception of type bool.
\n
"
" Actual: it throws a different type with message: b"
);
}
}
// Tests ASSERT_NO_THROW.
// Tests ASSERT_NO_THROW.
...
@@ -3810,6 +3836,9 @@ TEST(AssertionTest, ASSERT_NO_THROW) {
...
@@ -3810,6 +3836,9 @@ 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
(
ThrowAnException
(
"blablubb"
)),
"Expected: ThrowAnException(
\"
blablubb
\"
) doesn't throw"
" an exception.
\n
Actual: it throws: blablubb"
);
}
}
// Tests ASSERT_ANY_THROW.
// Tests ASSERT_ANY_THROW.
...
@@ -4536,13 +4565,17 @@ TEST(ExpectTest, EXPECT_GT) {
...
@@ -4536,13 +4565,17 @@ TEST(ExpectTest, EXPECT_GT) {
// Tests EXPECT_THROW.
// Tests EXPECT_THROW.
TEST
(
ExpectTest
,
EXPECT_THROW
)
{
TEST
(
ExpectTest
,
EXPECT_THROW
)
{
EXPECT_THROW
(
ThrowAnInteger
(),
int
);
EXPECT_THROW
(
ThrowAnInteger
(),
int
);
EXPECT_THROW
(
ThrowAnException
(
""
),
std
::
exception
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW
(
ThrowAnInteger
(),
bool
),
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW
(
ThrowAnInteger
(),
bool
),
"Expected: ThrowAnInteger() throws an exception of "
"Expected: ThrowAnInteger() throws an exception of "
"type bool.
\n
Actual: it throws a different type."
);
"type bool.
\n
Actual: it throws a different type."
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW
(
ThrowNothing
(),
bool
),
EXPECT_THROW
(
ThrowNothing
(),
bool
),
"Expected: ThrowNothing() throws an exception of "
"Expected: ThrowNothing() throws an exception of type bool.
\n
"
"type bool.
\n
Actual: it throws nothing."
);
" Actual: it throws nothing."
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW
(
ThrowAnException
(
"buuh"
),
bool
),
"Expected: ThrowAnException(
\"
buuh
\"
) throws an "
"exception of type bool.
\n
Actual: "
"it throws a different type with message: buuh"
);
}
}
// Tests EXPECT_NO_THROW.
// Tests EXPECT_NO_THROW.
...
@@ -4551,6 +4584,9 @@ TEST(ExpectTest, EXPECT_NO_THROW) {
...
@@ -4551,6 +4584,9 @@ 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
(
ThrowAnException
(
"blah"
)),
"Expected: ThrowAnException(
\"
blah
\"
) doesn't "
"throw an exception.
\n
Actual: it throws: blah"
);
}
}
// 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