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
e330b754
Commit
e330b754
authored
Nov 17, 2014
by
kosak
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Strip trailing whitespace when stringifying type lists.
parent
074ed8c8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
8 deletions
+42
-8
gtest-internal.h
include/gtest/internal/gtest-internal.h
+1
-1
gtest-port.h
include/gtest/internal/gtest-port.h
+7
-0
gtest-typed-test.cc
src/gtest-typed-test.cc
+15
-7
gtest-typed-test_test.cc
test/gtest-typed-test_test.cc
+19
-0
No files found.
include/gtest/internal/gtest-internal.h
View file @
e330b754
...
...
@@ -612,7 +612,7 @@ class TypeParameterizedTest {
MakeAndRegisterTestInfo
(
(
std
::
string
(
prefix
)
+
(
prefix
[
0
]
==
'\0'
?
""
:
"/"
)
+
case_name
+
"/"
+
StreamableToString
(
index
)).
c_str
(),
GetPrefixUntilComma
(
test_names
).
c_str
(),
StripTrailingSpaces
(
GetPrefixUntilComma
(
test_names
)
).
c_str
(),
GetTypeName
<
Type
>
().
c_str
(),
NULL
,
// No value parameter.
GetTypeId
<
FixtureClass
>
(),
...
...
include/gtest/internal/gtest-port.h
View file @
e330b754
...
...
@@ -2215,6 +2215,13 @@ inline char ToUpper(char ch) {
return
static_cast
<
char
>
(
toupper
(
static_cast
<
unsigned
char
>
(
ch
)));
}
inline
std
::
string
StripTrailingSpaces
(
std
::
string
str
)
{
std
::
string
::
iterator
it
=
str
.
end
();
while
(
it
!=
str
.
begin
()
&&
IsSpace
(
*--
it
))
it
=
str
.
erase
(
it
);
return
str
;
}
// The testing::internal::posix namespace holds wrappers for common
// POSIX functions. These wrappers hide the differences between
// Windows/MSVC and POSIX systems. Since some compilers define these
...
...
src/gtest-typed-test.cc
View file @
e330b754
...
...
@@ -45,6 +45,15 @@ static const char* SkipSpaces(const char* str) {
return
str
;
}
static
std
::
vector
<
std
::
string
>
SplitIntoTestNames
(
const
char
*
src
)
{
std
::
vector
<
std
::
string
>
name_vec
;
src
=
SkipSpaces
(
src
);
for
(;
src
!=
NULL
;
src
=
SkipComma
(
src
))
{
name_vec
.
push_back
(
StripTrailingSpaces
(
GetPrefixUntilComma
(
src
)));
}
return
name_vec
;
}
// Verifies that registered_tests match the test names in
// defined_test_names_; returns registered_tests if successful, or
// aborts the program otherwise.
...
...
@@ -53,15 +62,14 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames(
typedef
::
std
::
set
<
const
char
*>::
const_iterator
DefinedTestIter
;
registered_
=
true
;
// Skip initial whitespace in registered_tests since some
// preprocessors prefix stringizied literals with whitespace.
registered_tests
=
SkipSpaces
(
registered_tests
);
std
::
vector
<
std
::
string
>
name_vec
=
SplitIntoTestNames
(
registered_tests
);
Message
errors
;
::
std
::
set
<
std
::
string
>
tests
;
for
(
const
char
*
names
=
registered_tests
;
names
!=
NULL
;
names
=
SkipComma
(
names
))
{
const
std
::
string
name
=
GetPrefixUntilComma
(
names
);
std
::
set
<
std
::
string
>
tests
;
for
(
std
::
vector
<
std
::
string
>::
const_iterator
name_it
=
name_vec
.
begin
();
name_it
!=
name_vec
.
end
();
++
name_it
)
{
const
std
::
string
&
name
=
*
name_it
;
if
(
tests
.
count
(
name
)
!=
0
)
{
errors
<<
"Test "
<<
name
<<
" is listed more than once.
\n
"
;
continue
;
...
...
test/gtest-typed-test_test.cc
View file @
e330b754
...
...
@@ -344,6 +344,25 @@ REGISTER_TYPED_TEST_CASE_P(NumericTest,
typedef
Types
<
int
,
double
>
NumericTypes
;
INSTANTIATE_TYPED_TEST_CASE_P
(
My
,
NumericTest
,
NumericTypes
);
static
const
char
*
GetTestName
()
{
return
testing
::
UnitTest
::
GetInstance
()
->
current_test_info
()
->
name
();
}
// Test the stripping of space from test names
template
<
typename
T
>
class
TrimmedTest
:
public
Test
{
};
TYPED_TEST_CASE_P
(
TrimmedTest
);
TYPED_TEST_P
(
TrimmedTest
,
Test1
)
{
EXPECT_STREQ
(
"Test1"
,
GetTestName
());
}
TYPED_TEST_P
(
TrimmedTest
,
Test2
)
{
EXPECT_STREQ
(
"Test2"
,
GetTestName
());
}
TYPED_TEST_P
(
TrimmedTest
,
Test3
)
{
EXPECT_STREQ
(
"Test3"
,
GetTestName
());
}
TYPED_TEST_P
(
TrimmedTest
,
Test4
)
{
EXPECT_STREQ
(
"Test4"
,
GetTestName
());
}
TYPED_TEST_P
(
TrimmedTest
,
Test5
)
{
EXPECT_STREQ
(
"Test5"
,
GetTestName
());
}
REGISTER_TYPED_TEST_CASE_P
(
TrimmedTest
,
Test1
,
Test2
,
Test3
,
Test4
,
Test5
);
// NOLINT
template
<
typename
T1
,
typename
T2
>
struct
MyPair
{};
// Be sure to try a type with a comma in its name just in case it matters.
typedef
Types
<
int
,
double
,
MyPair
<
int
,
int
>
>
TrimTypes
;
INSTANTIATE_TYPED_TEST_CASE_P
(
My
,
TrimmedTest
,
TrimTypes
);
}
// namespace library2
#endif // GTEST_HAS_TYPED_TEST_P
...
...
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