Add a test to protect against syntax errors in main(). Also
test some main()-invariant logic while I'm at it. DELTA=19 (16 added, 0 deleted, 3 changed) Revision created by MOE tool push_codebase. MOE_MIGRATION=1409
This commit is contained in:
parent
d81dcede97
commit
ed381497a3
|
@ -1944,9 +1944,9 @@ def main(argv):
|
|||
' else min(the number of files that would be'
|
||||
' modified, 100)'))
|
||||
|
||||
parse.add_option('--ignore_re', default=None,
|
||||
help=('fix_includes.py will skip editing any file whose'
|
||||
' name matches this regular expression.'))
|
||||
parser.add_option('--ignore_re', default=None,
|
||||
help=('fix_includes.py will skip editing any file whose'
|
||||
' name matches this regular expression.'))
|
||||
|
||||
parser.add_option('--checkout_command', default=None,
|
||||
help=('A command, such as "p4 edit", to run on each'
|
||||
|
|
|
@ -18,6 +18,7 @@ __author__ = 'csilvers@google.com (Craig Silverstein)'
|
|||
|
||||
import cStringIO
|
||||
import re
|
||||
import sys
|
||||
# I use unittest instead of googletest to ease opensourcing. Luckily,
|
||||
# the only googletest function I have to re-implement is assertListEqual.
|
||||
import unittest
|
||||
|
@ -2432,6 +2433,21 @@ namespace util { class Status; }
|
|||
{'structuredsearch/common/internal/query_field_xlate.h': infile})
|
||||
self.ProcessAndTest(iwyu_output)
|
||||
|
||||
def testMain(self):
|
||||
"""Make sure calling main doesn't crash. Inspired by a syntax-error bug."""
|
||||
# Give an empty stdin so we don't actually try to parse anything.
|
||||
old_stdin = sys.stdin
|
||||
try:
|
||||
sys.stdin = cStringIO.StringIO()
|
||||
fix_includes.main(['fix_includes.py']) # argv[0] doesn't really matter
|
||||
finally:
|
||||
sys.stdin = old_stdin
|
||||
|
||||
def testFilenamesForSortingInMain(self):
|
||||
"""Make sure if we use s, we have a filename specified, in main()."""
|
||||
# -s without any files to sort.
|
||||
self.assertRaises(SystemExit, fix_includes.main,
|
||||
['fix_includes.py', '-s'])
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue