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
098f8ac3
Commit
098f8ac3
authored
May 05, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Evaluate EXPECT_STD* output argument once.
parent
758283f7
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
11 deletions
+16
-11
test/gtest-extra-test.cc
test/gtest-extra-test.cc
+7
-0
test/gtest-extra.h
test/gtest-extra.h
+9
-11
No files found.
test/gtest-extra-test.cc
View file @
098f8ac3
...
@@ -109,6 +109,13 @@ TEST_F(SingleEvaluationTest, FailedEXPECT_THROW_MSG) {
...
@@ -109,6 +109,13 @@ TEST_F(SingleEvaluationTest, FailedEXPECT_THROW_MSG) {
EXPECT_EQ
(
s_
+
1
,
p_
);
EXPECT_EQ
(
s_
+
1
,
p_
);
}
}
// Tests that when EXPECT_STDOUT fails, it evaluates its message argument
// exactly once.
TEST_F
(
SingleEvaluationTest
,
FailedEXPECT_STDOUT
)
{
EXPECT_NONFATAL_FAILURE
(
EXPECT_STDOUT
(
std
::
printf
(
"test"
),
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 @
098f8ac3
...
@@ -44,16 +44,16 @@
...
@@ -44,16 +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; \
std::string
gtest_expected_message
= 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_str
!= e.what()) { \
if (
gtest_expected_message
!= 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_str
<< "\n" \
<< "Expected: " <<
gtest_expected_message
<< "\n" \
<< " Actual: " << e.what(); \
<< " Actual: " << e.what(); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
} \
} \
...
@@ -340,16 +340,14 @@ class OutputRedirect {
...
@@ -340,16 +340,14 @@ class OutputRedirect {
#define FMT_TEST_PRINT_(statement, expected_output, file, fail) \
#define FMT_TEST_PRINT_(statement, expected_output, file, 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 gtest_output; \
std::string gtest_expected_output = expected_output; \
{ \
OutputRedirect gtest_redir(file); \
OutputRedirect gtest_redir(file); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
gtest_output = gtest_redir.RestoreAndRead(); \
std::string gtest_output = gtest_redir.RestoreAndRead(); \
} \
if (gtest_output != gtest_expected_output) { \
if (gtest_output != expected_output) { \
gtest_ar \
gtest_ar \
<< #statement " produces different output.\n" \
<< #statement " produces different output.\n" \
<< "Expected: " << expected_output << "\n" \
<< "Expected: " <<
gtest_
expected_output << "\n" \
<< " Actual: " << gtest_output; \
<< " Actual: " << gtest_output; \
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