aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authornnorwitz <nnorwitz@8415998a-534a-0410-bf83-d39667b30386>2009-05-06 05:57:09 +0000
committernnorwitz <nnorwitz@8415998a-534a-0410-bf83-d39667b30386>2009-05-06 05:57:09 +0000
commitce60784fb51a5a0e28c14edd53bacbf0d2abb36b (patch)
tree3497dc072243b1871819bf68d702d52ade6fba5c /scripts
parent60df3efe3971fb54d3a10c557fbc30ff32512bb5 (diff)
downloadgoogletest-ce60784fb51a5a0e28c14edd53bacbf0d2abb36b.tar.gz
googletest-ce60784fb51a5a0e28c14edd53bacbf0d2abb36b.tar.bz2
googletest-ce60784fb51a5a0e28c14edd53bacbf0d2abb36b.zip
Allow any number of ClassNames to be specified on the command line.
0 ClassNames means emit all classes found in the file.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/generator/README4
-rwxr-xr-xscripts/generator/cpp/gmock_class.py21
2 files changed, 18 insertions, 7 deletions
diff --git a/scripts/generator/README b/scripts/generator/README
index a3ba784b..2fc695a6 100644
--- a/scripts/generator/README
+++ b/scripts/generator/README
@@ -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:
diff --git a/scripts/generator/cpp/gmock_class.py b/scripts/generator/cpp/gmock_class.py
index a4435de4..ab2da32d 100755
--- a/scripts/generator/cpp/gmock_class.py
+++ b/scripts/generator/cpp/gmock_class.py
@@ -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 [ClassName1] [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_names):
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