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
34648f40
Commit
34648f40
authored
May 14, 2014
by
Victor Zverovich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test EXPECT_SYSTEM_ERROR.
parent
5415b2a4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
97 additions
and
2 deletions
+97
-2
test/gtest-extra-test.cc
test/gtest-extra-test.cc
+97
-2
No files found.
test/gtest-extra-test.cc
View file @
34648f40
...
...
@@ -106,6 +106,10 @@ void ThrowException() {
throw
std
::
runtime_error
(
"test"
);
}
void
ThrowSystemError
()
{
fmt
::
ThrowSystemError
(
EDOM
,
"test"
);
}
// Tests that when EXPECT_THROW_MSG fails, it evaluates its message argument
// exactly once.
TEST_F
(
SingleEvaluationTest
,
FailedEXPECT_THROW_MSG
)
{
...
...
@@ -114,6 +118,14 @@ TEST_F(SingleEvaluationTest, FailedEXPECT_THROW_MSG) {
EXPECT_EQ
(
s_
+
1
,
p_
);
}
// Tests that when EXPECT_SYSTEM_ERROR fails, it evaluates its message argument
// exactly once.
TEST_F
(
SingleEvaluationTest
,
FailedEXPECT_SYSTEM_ERROR
)
{
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
(
ThrowSystemError
(),
EDOM
,
p_
++
),
"01234"
);
EXPECT_EQ
(
s_
+
1
,
p_
);
}
// Tests that when EXPECT_WRITE fails, it evaluates its message argument
// exactly once.
TEST_F
(
SingleEvaluationTest
,
FailedEXPECT_WRITE
)
{
...
...
@@ -156,6 +168,39 @@ TEST_F(SingleEvaluationTest, ExceptionTests) {
EXPECT_EQ
(
4
,
b_
);
}
TEST_F
(
SingleEvaluationTest
,
SystemErrorTests
)
{
// successful EXPECT_SYSTEM_ERROR
EXPECT_SYSTEM_ERROR
({
// NOLINT
a_
++
;
ThrowSystemError
();
},
EDOM
,
(
b_
++
,
"test"
));
EXPECT_EQ
(
1
,
a_
);
EXPECT_EQ
(
1
,
b_
);
// failed EXPECT_SYSTEM_ERROR, throws different type
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
({
// NOLINT
a_
++
;
ThrowException
();
},
EDOM
,
(
b_
++
,
"test"
)),
"throws a different type"
);
EXPECT_EQ
(
2
,
a_
);
EXPECT_EQ
(
2
,
b_
);
// failed EXPECT_SYSTEM_ERROR, throws an exception with different message
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
({
// NOLINT
a_
++
;
ThrowSystemError
();
},
EDOM
,
(
b_
++
,
"other"
)),
"throws an exception with a different message"
);
EXPECT_EQ
(
3
,
a_
);
EXPECT_EQ
(
3
,
b_
);
// failed EXPECT_SYSTEM_ERROR, throws nothing
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
(
a_
++
,
EDOM
,
(
b_
++
,
"test"
)),
"throws nothing"
);
EXPECT_EQ
(
4
,
a_
);
EXPECT_EQ
(
4
,
b_
);
}
// Tests that assertion arguments are evaluated exactly once.
TEST_F
(
SingleEvaluationTest
,
WriteTests
)
{
// successful EXPECT_WRITE
...
...
@@ -187,6 +232,18 @@ TEST(ExpectThrowTest, DoesNotGenerateUnreachableCodeWarning) {
throw
runtime_error
(
"a"
),
runtime_error
,
"b"
),
""
);
}
// Tests that the compiler will not complain about unreachable code in the
// EXPECT_SYSTEM_ERROR macro.
TEST
(
ExpectSystemErrorTest
,
DoesNotGenerateUnreachableCodeWarning
)
{
int
n
=
0
;
EXPECT_SYSTEM_ERROR
(
throw
fmt
::
SystemError
(
FormatSystemErrorMessage
(
EDOM
,
"test"
),
EDOM
),
EDOM
,
"test"
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
(
n
++
,
EDOM
,
""
),
""
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
(
throw
1
,
EDOM
,
""
),
""
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
(
throw
fmt
::
SystemError
(
"aaa"
,
EDOM
),
EDOM
,
"bbb"
),
""
);
}
TEST
(
AssertionSyntaxTest
,
ExceptionAssertionBehavesLikeSingleStatement
)
{
if
(
::
testing
::
internal
::
AlwaysFalse
())
EXPECT_THROW_MSG
(
DoNothing
(),
std
::
exception
,
""
);
...
...
@@ -197,6 +254,16 @@ TEST(AssertionSyntaxTest, ExceptionAssertionBehavesLikeSingleStatement) {
DoNothing
();
}
TEST
(
AssertionSyntaxTest
,
SystemErrorAssertionBehavesLikeSingleStatement
)
{
if
(
::
testing
::
internal
::
AlwaysFalse
())
EXPECT_SYSTEM_ERROR
(
DoNothing
(),
EDOM
,
""
);
if
(
::
testing
::
internal
::
AlwaysTrue
())
EXPECT_SYSTEM_ERROR
(
ThrowSystemError
(),
EDOM
,
"test"
);
else
DoNothing
();
}
TEST
(
AssertionSyntaxTest
,
WriteAssertionBehavesLikeSingleStatement
)
{
if
(
::
testing
::
internal
::
AlwaysFalse
())
EXPECT_WRITE
(
stdout
,
std
::
printf
(
"x"
),
"x"
);
...
...
@@ -225,6 +292,27 @@ TEST(ExpectTest, EXPECT_THROW_MSG) {
" Actual: test"
);
}
// Tests EXPECT_SYSTEM_ERROR.
TEST
(
ExpectTest
,
EXPECT_SYSTEM_ERROR
)
{
EXPECT_SYSTEM_ERROR
(
ThrowSystemError
(),
EDOM
,
"test"
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
(
ThrowException
(),
EDOM
,
"test"
),
"Expected: ThrowException() throws an exception of "
"type fmt::SystemError.
\n
Actual: it throws a different type."
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
(
DoNothing
(),
EDOM
,
"test"
),
"Expected: DoNothing() throws an exception of type fmt::SystemError.
\n
"
" Actual: it throws nothing."
);
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
(
ThrowSystemError
(),
EDOM
,
"other"
),
str
(
fmt
::
Format
(
"ThrowSystemError() throws an exception with a different message.
\n
"
"Expected: {}
\n
"
" Actual: {}"
)
<<
FormatSystemErrorMessage
(
EDOM
,
"other"
)
<<
FormatSystemErrorMessage
(
EDOM
,
"test"
)));
}
// Tests EXPECT_WRITE.
TEST
(
ExpectTest
,
EXPECT_WRITE
)
{
EXPECT_WRITE
(
stdout
,
DoNothing
(),
""
);
...
...
@@ -244,6 +332,14 @@ TEST(StreamingAssertionsTest, EXPECT_THROW_MSG) {
<<
"expected failure"
,
"expected failure"
);
}
TEST
(
StreamingAssertionsTest
,
EXPECT_SYSTEM_ERROR
)
{
EXPECT_SYSTEM_ERROR
(
ThrowSystemError
(),
EDOM
,
"test"
)
<<
"unexpected failure"
;
EXPECT_NONFATAL_FAILURE
(
EXPECT_SYSTEM_ERROR
(
ThrowSystemError
(),
EDOM
,
"other"
)
<<
"expected failure"
,
"expected failure"
);
}
TEST
(
StreamingAssertionsTest
,
EXPECT_WRITE
)
{
EXPECT_WRITE
(
stdout
,
std
::
printf
(
"test"
),
"test"
)
<<
"unexpected failure"
;
...
...
@@ -704,8 +800,7 @@ TEST(OutputRedirectTest, ErrorInDtor) {
write_copy
.
dup2
(
write_fd
);
// "undo" close or dtor of BufferedFile will fail
}
// TODO: test EXPECT_SYSTEM_ERROR
// TODO: test retry on EINTR
// TODO: test retry on EINTR, test FormatSystemErrorMessage
#endif // FMT_USE_FILE_DESCRIPTORS
...
...
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