Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
fmt
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
fmt
Commits
536e6138
Commit
536e6138
authored
May 05, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Evaluate message argument passed to EXPECT_THROW_MSG once.
parent
368505eb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
3 deletions
+18
-3
test/gtest-extra-test.cc
test/gtest-extra-test.cc
+15
-1
test/gtest-extra.h
test/gtest-extra.h
+3
-2
No files found.
test/gtest-extra-test.cc
View file @
536e6138
...
@@ -77,12 +77,18 @@ bool IsClosedInternal(int fd) {
...
@@ -77,12 +77,18 @@ bool IsClosedInternal(int fd) {
class
SingleEvaluationTest
:
public
::
testing
::
Test
{
class
SingleEvaluationTest
:
public
::
testing
::
Test
{
protected:
protected:
SingleEvaluationTest
()
{
SingleEvaluationTest
()
{
p_
=
s_
;
a_
=
0
;
a_
=
0
;
}
}
static
const
char
*
const
s_
;
static
const
char
*
p_
;
static
int
a_
;
static
int
a_
;
};
};
const
char
*
const
SingleEvaluationTest
::
s_
=
"01234"
;
const
char
*
SingleEvaluationTest
::
p_
;
int
SingleEvaluationTest
::
a_
;
int
SingleEvaluationTest
::
a_
;
void
ThrowNothing
()
{}
void
ThrowNothing
()
{}
...
@@ -91,6 +97,14 @@ void ThrowException() {
...
@@ -91,6 +97,14 @@ void ThrowException() {
throw
std
::
runtime_error
(
"test"
);
throw
std
::
runtime_error
(
"test"
);
}
}
// Tests that when EXPECT_THROW_MSG fails, it evaluates its message argument
// exactly once.
TEST_F
(
SingleEvaluationTest
,
FailedASSERT_THROW_MSG
)
{
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
p_
++
),
"01234"
);
EXPECT_EQ
(
s_
+
1
,
p_
);
}
// Tests that assertion arguments are evaluated exactly once.
// Tests that assertion arguments are evaluated exactly once.
TEST_F
(
SingleEvaluationTest
,
ExceptionTests
)
{
TEST_F
(
SingleEvaluationTest
,
ExceptionTests
)
{
// successful EXPECT_THROW_MSG
// successful EXPECT_THROW_MSG
...
...
test/gtest-extra.h
View file @
536e6138
...
@@ -44,15 +44,16 @@
...
@@ -44,15 +44,16 @@
#define FMT_TEST_THROW_(statement, expected_exception, expected_message, fail) \
#define FMT_TEST_THROW_(statement, expected_exception, expected_message, fail) \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
if (::testing::AssertionResult gtest_ar = ::testing::AssertionSuccess()) { \
if (::testing::AssertionResult gtest_ar = ::testing::AssertionSuccess()) { \
std::string expected_message_str = expected_message; \
bool gtest_caught_expected = false; \
bool gtest_caught_expected = false; \
try { \
try { \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
} \
} \
catch (expected_exception const& e) { \
catch (expected_exception const& e) { \
if (expected_message
!= std::string(e.what()
)) { \
if (expected_message
_str != e.what(
)) { \
gtest_ar \
gtest_ar \
<< #statement " throws an exception with a different message.\n" \
<< #statement " throws an exception with a different message.\n" \
<< "Expected: " << expected_message << "\n" \
<< "Expected: " << expected_message
_str
<< "\n" \
<< " Actual: " << e.what(); \
<< " Actual: " << e.what(); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
} \
} \
...
...
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