Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
googletest
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
googletest
Commits
887d569e
Commit
887d569e
authored
May 07, 2017
by
Billy Donahue
Committed by
GitHub
May 07, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #965 from davidben/format-attr
Annotate ColoredPrintf with the format attribute and fix bugs.
parents
0ad83afd
53c478d6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
3 deletions
+21
-3
gtest-port.h
googletest/include/gtest/internal/gtest-port.h
+17
-0
gtest.cc
googletest/src/gtest.cc
+4
-3
No files found.
googletest/include/gtest/internal/gtest-port.h
View file @
887d569e
...
@@ -874,6 +874,23 @@ using ::std::tuple_size;
...
@@ -874,6 +874,23 @@ using ::std::tuple_size;
# define GTEST_ATTRIBUTE_UNUSED_
# define GTEST_ATTRIBUTE_UNUSED_
#endif
#endif
// Use this annotation before a function that takes a printf format string.
#if defined(__GNUC__) && !defined(COMPILER_ICC)
# if defined(__MINGW_PRINTF_FORMAT)
// MinGW has two different printf implementations. Ensure the format macro
// matches the selected implementation. See
// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/.
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
__attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \
first_to_check)))
# else
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \
__attribute__((__format__(__printf__, string_index, first_to_check)))
# endif
#else
# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check)
#endif
// A macro to disallow operator=
// A macro to disallow operator=
// This should be used in the private: declarations for a class.
// This should be used in the private: declarations for a class.
#define GTEST_DISALLOW_ASSIGN_(type)\
#define GTEST_DISALLOW_ASSIGN_(type)\
...
...
googletest/src/gtest.cc
View file @
887d569e
...
@@ -2953,6 +2953,7 @@ bool ShouldUseColor(bool stdout_is_tty) {
...
@@ -2953,6 +2953,7 @@ bool ShouldUseColor(bool stdout_is_tty) {
// cannot simply emit special characters and have the terminal change colors.
// cannot simply emit special characters and have the terminal change colors.
// This routine must actually emit the characters rather than return a string
// This routine must actually emit the characters rather than return a string
// that would be colored when printed, as can be done on Linux.
// that would be colored when printed, as can be done on Linux.
GTEST_ATTRIBUTE_PRINTF_
(
2
,
3
)
void
ColoredPrintf
(
GTestColor
color
,
const
char
*
fmt
,
...)
{
void
ColoredPrintf
(
GTestColor
color
,
const
char
*
fmt
,
...)
{
va_list
args
;
va_list
args
;
va_start
(
args
,
fmt
);
va_start
(
args
,
fmt
);
...
@@ -4729,7 +4730,7 @@ bool ShouldShard(const char* total_shards_env,
...
@@ -4729,7 +4730,7 @@ bool ShouldShard(const char* total_shards_env,
<<
"Invalid environment variables: you have "
<<
"Invalid environment variables: you have "
<<
kTestShardIndex
<<
" = "
<<
shard_index
<<
kTestShardIndex
<<
" = "
<<
shard_index
<<
", but have left "
<<
kTestTotalShards
<<
" unset.
\n
"
;
<<
", but have left "
<<
kTestTotalShards
<<
" unset.
\n
"
;
ColoredPrintf
(
COLOR_RED
,
msg
.
GetString
().
c_str
());
ColoredPrintf
(
COLOR_RED
,
"%s"
,
msg
.
GetString
().
c_str
());
fflush
(
stdout
);
fflush
(
stdout
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
else
if
(
total_shards
!=
-
1
&&
shard_index
==
-
1
)
{
}
else
if
(
total_shards
!=
-
1
&&
shard_index
==
-
1
)
{
...
@@ -4737,7 +4738,7 @@ bool ShouldShard(const char* total_shards_env,
...
@@ -4737,7 +4738,7 @@ bool ShouldShard(const char* total_shards_env,
<<
"Invalid environment variables: you have "
<<
"Invalid environment variables: you have "
<<
kTestTotalShards
<<
" = "
<<
total_shards
<<
kTestTotalShards
<<
" = "
<<
total_shards
<<
", but have left "
<<
kTestShardIndex
<<
" unset.
\n
"
;
<<
", but have left "
<<
kTestShardIndex
<<
" unset.
\n
"
;
ColoredPrintf
(
COLOR_RED
,
msg
.
GetString
().
c_str
());
ColoredPrintf
(
COLOR_RED
,
"%s"
,
msg
.
GetString
().
c_str
());
fflush
(
stdout
);
fflush
(
stdout
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
else
if
(
shard_index
<
0
||
shard_index
>=
total_shards
)
{
}
else
if
(
shard_index
<
0
||
shard_index
>=
total_shards
)
{
...
@@ -4746,7 +4747,7 @@ bool ShouldShard(const char* total_shards_env,
...
@@ -4746,7 +4747,7 @@ bool ShouldShard(const char* total_shards_env,
<<
kTestShardIndex
<<
" < "
<<
kTestTotalShards
<<
kTestShardIndex
<<
" < "
<<
kTestTotalShards
<<
", but you have "
<<
kTestShardIndex
<<
"="
<<
shard_index
<<
", but you have "
<<
kTestShardIndex
<<
"="
<<
shard_index
<<
", "
<<
kTestTotalShards
<<
"="
<<
total_shards
<<
".
\n
"
;
<<
", "
<<
kTestTotalShards
<<
"="
<<
total_shards
<<
".
\n
"
;
ColoredPrintf
(
COLOR_RED
,
msg
.
GetString
().
c_str
());
ColoredPrintf
(
COLOR_RED
,
"%s"
,
msg
.
GetString
().
c_str
());
fflush
(
stdout
);
fflush
(
stdout
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
...
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