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
8f04622c
Commit
8f04622c
authored
Aug 14, 2017
by
gpetit
Browse files
Use GTEST_LOG instead of printf
parent
aa148eb2
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
23 deletions
+26
-23
googletest/src/gtest.cc
googletest/src/gtest.cc
+26
-23
No files found.
googletest/src/gtest.cc
View file @
8f04622c
...
@@ -2571,10 +2571,10 @@ void ReportInvalidTestCaseType(const char* test_case_name,
...
@@ -2571,10 +2571,10 @@ void ReportInvalidTestCaseType(const char* test_case_name,
<<
"probably rename one of the classes to put the tests into different
\n
"
<<
"probably rename one of the classes to put the tests into different
\n
"
<<
"test cases."
;
<<
"test cases."
;
fprintf
(
stderr
,
"%s %s"
,
GTEST_LOG_
(
ERROR
)
FormatFileLocation
(
code_location
.
file
.
c_str
(),
<<
FormatFileLocation
(
code_location
.
file
.
c_str
(),
code_location
.
line
)
.
c_str
()
,
code_location
.
line
),
errors
.
GetString
()
.
c_str
())
;
<<
" "
<<
errors
.
GetString
();
}
}
#endif // GTEST_HAS_PARAM_TEST
#endif // GTEST_HAS_PARAM_TEST
...
@@ -3422,8 +3422,10 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
...
@@ -3422,8 +3422,10 @@ class XmlUnitTestResultPrinter : public EmptyTestEventListener {
XmlUnitTestResultPrinter
::
XmlUnitTestResultPrinter
(
const
char
*
output_file
)
XmlUnitTestResultPrinter
::
XmlUnitTestResultPrinter
(
const
char
*
output_file
)
:
output_file_
(
output_file
)
{
:
output_file_
(
output_file
)
{
if
(
output_file_
.
c_str
()
==
NULL
||
output_file_
.
empty
())
{
if
(
output_file_
.
c_str
()
==
NULL
||
output_file_
.
empty
())
{
fprintf
(
stderr
,
"XML output file may not be null
\n
"
);
{
fflush
(
stderr
);
// scoped to make sure the log is flushed before we exit
GTEST_LOG_
(
FATAL
)
<<
"XML output file may not be null"
;
}
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
}
}
...
@@ -3449,10 +3451,10 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
...
@@ -3449,10 +3451,10 @@ void XmlUnitTestResultPrinter::OnTestIterationEnd(const UnitTest& unit_test,
// 3. To interpret the meaning of errno in a thread-safe way,
// 3. To interpret the meaning of errno in a thread-safe way,
// we need the strerror_r() function, which is not available on
// we need the strerror_r() function, which is not available on
// Windows.
// Windows.
fprintf
(
stderr
,
{
// scoped to ensure the log is flushed before we exit
"Unable to open file
\"
%s
\"\n
"
,
GTEST_LOG_
(
FATAL
)
<<
"Unable to open file
\"
"
output_file_
.
c_str
())
;
<<
output_file_
<<
"
\"
"
;
fflush
(
stderr
);
}
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
std
::
stringstream
stream
;
std
::
stringstream
stream
;
...
@@ -4403,9 +4405,9 @@ void UnitTestImpl::ConfigureXmlOutput() {
...
@@ -4403,9 +4405,9 @@ void UnitTestImpl::ConfigureXmlOutput() {
listeners
()
->
SetDefaultXmlGenerator
(
new
XmlUnitTestResultPrinter
(
listeners
()
->
SetDefaultXmlGenerator
(
new
XmlUnitTestResultPrinter
(
UnitTestOptions
::
GetAbsolutePathToOutputFile
().
c_str
()));
UnitTestOptions
::
GetAbsolutePathToOutputFile
().
c_str
()));
}
else
if
(
output_format
!=
""
)
{
}
else
if
(
output_format
!=
""
)
{
printf
(
"WARNING: unrecognized output format
\"
%s
\"
ignored.
\n
"
,
GTEST_LOG_
(
WARNING
)
<<
"WARNING: unrecognized output format
\"
"
output_format
.
c_str
());
<<
output_format
fflush
(
stdout
)
;
<<
"
\"
ignored."
;
}
}
}
}
...
@@ -4420,9 +4422,9 @@ void UnitTestImpl::ConfigureStreamingOutput() {
...
@@ -4420,9 +4422,9 @@ void UnitTestImpl::ConfigureStreamingOutput() {
listeners
()
->
Append
(
new
StreamingListener
(
target
.
substr
(
0
,
pos
),
listeners
()
->
Append
(
new
StreamingListener
(
target
.
substr
(
0
,
pos
),
target
.
substr
(
pos
+
1
)));
target
.
substr
(
pos
+
1
)));
}
else
{
}
else
{
printf
(
"
WARNING
:
unrecognized streaming target
\"
%s
\"
ignored.
\n
"
,
GTEST_LOG_
(
WARNING
)
<<
"
unrecognized streaming target
\"
"
target
.
c_str
());
<<
target
fflush
(
stdout
)
;
<<
"
\"
ignored."
;
}
}
}
}
}
}
...
@@ -4551,9 +4553,9 @@ static void TearDownEnvironment(Environment* env) { env->TearDown(); }
...
@@ -4551,9 +4553,9 @@ static void TearDownEnvironment(Environment* env) { env->TearDown(); }
bool
UnitTestImpl
::
RunAllTests
()
{
bool
UnitTestImpl
::
RunAllTests
()
{
// Makes sure InitGoogleTest() was called.
// Makes sure InitGoogleTest() was called.
if
(
!
GTestIsInitialized
())
{
if
(
!
GTestIsInitialized
())
{
printf
(
"%s"
,
GTEST_LOG_
(
ERROR
)
<<
"
\n
This test program did NOT call ::testing::InitGoogleTest "
"
\n
This test program did NOT call ::testing::InitGoogleTest "
"before calling RUN_ALL_TESTS(). Please fix it.
\n
"
)
;
"before calling RUN_ALL_TESTS(). Please fix it.
"
;
return
false
;
return
false
;
}
}
...
@@ -5253,10 +5255,11 @@ bool ParseGoogleTestFlag(const char* const arg) {
...
@@ -5253,10 +5255,11 @@ bool ParseGoogleTestFlag(const char* const arg) {
void
LoadFlagsFromFile
(
const
std
::
string
&
path
)
{
void
LoadFlagsFromFile
(
const
std
::
string
&
path
)
{
FILE
*
flagfile
=
posix
::
FOpen
(
path
.
c_str
(),
"r"
);
FILE
*
flagfile
=
posix
::
FOpen
(
path
.
c_str
(),
"r"
);
if
(
!
flagfile
)
{
if
(
!
flagfile
)
{
fprintf
(
stderr
,
{
// scoped to ensure the log is flushed before we exit
"Unable to open file
\"
%s
\"\n
"
,
GTEST_LOG_
(
FATAL
)
<<
"Unable to open file
\"
"
GTEST_FLAG
(
flagfile
).
c_str
());
<<
GTEST_FLAG
(
flagfile
)
fflush
(
stderr
);
<<
"
\"
"
;
}
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
std
::
string
contents
(
ReadEntireFile
(
flagfile
));
std
::
string
contents
(
ReadEntireFile
(
flagfile
));
...
...
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