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
ce60784f
Commit
ce60784f
authored
May 06, 2009
by
nnorwitz
Browse files
Allow any number of ClassNames to be specified on the command line.
0 ClassNames means emit all classes found in the file.
parent
60df3efe
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
7 deletions
+18
-7
scripts/generator/README
scripts/generator/README
+3
-1
scripts/generator/cpp/gmock_class.py
scripts/generator/cpp/gmock_class.py
+15
-6
No files found.
scripts/generator/README
View file @
ce60784f
...
...
@@ -14,7 +14,9 @@ to generate a Google Mock class.
Make sure to install the scripts somewhere in your path. Then you can
run the program.
gmock_gen.py header-file.h ClassName
gmock_gen.py header-file.h [ClassName1] [ClassName2] ...
If no ClassNames are specified, all classes in the file are emitted.
To change the indentation from the default of 2, set INDENT in
the environment. For example to use an indent of 4 spaces:
...
...
scripts/generator/cpp/gmock_class.py
View file @
ce60784f
...
...
@@ -20,7 +20,7 @@ This program will read in a C++ source file and output the Google Mock class
for the specified class.
Usage:
gmock_class.py header-file.h ClassName
gmock_class.py header-file.h
[
ClassName
1] [ClassName2] ...
Output is sent to stdout.
"""
...
...
@@ -79,10 +79,12 @@ def _GenerateMethods(output_lines, source, class_node):
output_lines
.
append
(
line
)
def
_GenerateMock
(
filename
,
source
,
ast_list
,
class_name
):
def
_GenerateMock
(
filename
,
source
,
ast_list
,
desired_
class_name
s
):
lines
=
[]
for
node
in
ast_list
:
if
isinstance
(
node
,
ast
.
Class
)
and
node
.
body
and
node
.
name
==
class_name
:
if
(
isinstance
(
node
,
ast
.
Class
)
and
node
.
body
and
(
desired_class_names
is
None
or
node
.
name
in
desired_class_names
)):
class_name
=
node
.
name
class_node
=
node
# Add namespace before the class.
if
class_node
.
namespace
:
...
...
@@ -115,11 +117,15 @@ def _GenerateMock(filename, source, ast_list, class_name):
if
lines
:
sys
.
stdout
.
write
(
'
\n
'
.
join
(
lines
))
else
:
sys
.
stderr
.
write
(
'Class %s not found
\n
'
%
class_name
)
if
desired_class_names
is
None
:
sys
.
stderr
.
write
(
'No classes not found
\n
'
)
else
:
class_names
=
', '
.
join
(
sorted
(
desired_class_names
))
sys
.
stderr
.
write
(
'Class(es) not found: %s
\n
'
%
class_names
)
def
main
(
argv
=
sys
.
argv
):
if
len
(
argv
)
!=
3
:
if
len
(
argv
)
<
2
:
sys
.
stdout
.
write
(
__doc__
)
return
1
...
...
@@ -131,7 +137,10 @@ def main(argv=sys.argv):
except
:
sys
.
stderr
.
write
(
'Unable to use indent of %s
\n
'
%
os
.
environ
.
get
(
'INDENT'
))
filename
,
class_name
=
argv
[
1
:]
filename
=
argv
[
1
]
class_name
=
None
if
len
(
argv
)
>=
3
:
class_name
=
set
(
argv
[
2
:])
source
=
utils
.
ReadFile
(
filename
)
if
source
is
None
:
return
1
...
...
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