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
62394e0e
Commit
62394e0e
authored
May 02, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More assertion tests.
parent
61d5ebc0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
3 deletions
+52
-3
test/assert-test.cc
test/assert-test.cc
+49
-1
test/format-test.h
test/format-test.h
+3
-2
No files found.
test/assert-test.cc
View file @
62394e0e
...
...
@@ -44,6 +44,8 @@ class SingleEvaluationTest : public ::testing::Test {
int
SingleEvaluationTest
::
a_
;
void
ThrowNothing
()
{}
void
ThrowException
()
{
throw
std
::
runtime_error
(
"test"
);
}
...
...
@@ -77,6 +79,52 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
EXPECT_EQ
(
4
,
a_
);
}
// TODO: more tests
// Tests that the compiler will not complain about unreachable code in the
// EXPECT_THROW_MSG macro.
TEST
(
ExpectThrowTest
,
DoesNotGenerateUnreachableCodeWarning
)
{
int
n
=
0
;
using
std
::
runtime_error
;
EXPECT_THROW_MSG
(
throw
runtime_error
(
""
),
runtime_error
,
""
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
n
++
,
runtime_error
,
""
),
""
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
throw
1
,
runtime_error
,
""
),
""
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
throw
runtime_error
(
"a"
),
runtime_error
,
"b"
),
""
);
}
TEST
(
AssertionSyntaxTest
,
ExceptionAssertionsBehavesLikeSingleStatement
)
{
if
(
::
testing
::
internal
::
AlwaysFalse
())
EXPECT_THROW_MSG
(
ThrowNothing
(),
std
::
exception
,
""
);
if
(
::
testing
::
internal
::
AlwaysTrue
())
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"test"
);
else
;
// NOLINT
}
// Tests EXPECT_THROW_MSG.
TEST
(
ExpectTest
,
EXPECT_THROW_MSG
)
{
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"test"
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
logic_error
,
"test"
),
"Expected: ThrowException() throws an exception of "
"type std::logic_error.
\n
Actual: it throws a different type."
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
ThrowNothing
(),
std
::
exception
,
"test"
),
"Expected: ThrowNothing() throws an exception of type std::exception.
\n
"
" Actual: it throws nothing."
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"other"
),
"ThrowException() throws an exception with a different message.
\n
"
"Expected: other
\n
"
" Actual: test"
);
}
TEST
(
StreamingAssertionsTest
,
ThrowMsg
)
{
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"test"
)
<<
"unexpected failure"
;
EXPECT_NONFATAL_FAILURE
(
EXPECT_THROW_MSG
(
ThrowException
(),
std
::
exception
,
"other"
)
<<
"expected failure"
,
"expected failure"
);
}
}
// namespace
test/format-test.h
View file @
62394e0e
...
...
@@ -36,9 +36,10 @@
} \
catch (expected_exception const& e) { \
if (expected_message != std::string(e.what())) { \
gtest_ar << "Statement throws an exception with a different message\n" \
gtest_ar \
<< #statement " throws an exception with a different message.\n" \
<< "Expected: " << expected_message << "\n" \
<< " Actual: " << e.what()
<< "\n"
; \
<< " Actual: " << e.what(); \
goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \
} \
gtest_caught_expected = true; \
...
...
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