mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2025-02-24 03:46:49 +00:00
check_test_cases: parametrize iteration functions by the action
Parametrize the code that iterates over test case descriptions by the function to apply on each description. No behavior change. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
fb4f933f8e
commit
d34e9e450f
|
@ -76,10 +76,13 @@ def check_description(results, seen, file_name, line_number, description):
|
|||
len(description))
|
||||
seen[description] = line_number
|
||||
|
||||
def check_test_suite(results, data_file_name):
|
||||
"""Check the test cases in the given unit test data file."""
|
||||
def walk_test_suite(function, results, descriptions, data_file_name):
|
||||
"""Iterate over the test cases in the given unit test data file.
|
||||
|
||||
Call function(results, descriptions, data_file_name, line_number, description)
|
||||
on each description.
|
||||
"""
|
||||
in_paragraph = False
|
||||
descriptions = {}
|
||||
with open(data_file_name, 'rb') as data_file:
|
||||
for line_number, line in enumerate(data_file, 1):
|
||||
line = line.rstrip(b'\r\n')
|
||||
|
@ -90,13 +93,16 @@ def check_test_suite(results, data_file_name):
|
|||
continue
|
||||
if not in_paragraph:
|
||||
# This is a test case description line.
|
||||
check_description(results, descriptions,
|
||||
function(results, descriptions,
|
||||
data_file_name, line_number, line)
|
||||
in_paragraph = True
|
||||
|
||||
def check_ssl_opt_sh(results, file_name):
|
||||
"""Check the test cases in ssl-opt.sh or a file with a similar format."""
|
||||
descriptions = {}
|
||||
def walk_ssl_opt_sh(function, results, descriptions, file_name):
|
||||
"""Iterate over the test cases in ssl-opt.sh or a file with a similar format.
|
||||
|
||||
Call function(results, descriptions, file_name, line_number, description)
|
||||
on each description.
|
||||
"""
|
||||
with open(file_name, 'rb') as file_contents:
|
||||
for line_number, line in enumerate(file_contents, 1):
|
||||
# Assume that all run_test calls have the same simple form
|
||||
|
@ -106,9 +112,24 @@ def check_ssl_opt_sh(results, file_name):
|
|||
if not m:
|
||||
continue
|
||||
description = m.group(1)
|
||||
check_description(results, descriptions,
|
||||
function(results, descriptions,
|
||||
file_name, line_number, description)
|
||||
|
||||
def walk_all(function, results):
|
||||
"""Iterate over all named test cases.
|
||||
|
||||
Call function(results, {}, file_name, line_number, description)
|
||||
on each description.
|
||||
"""
|
||||
test_directories = collect_test_directories()
|
||||
for directory in test_directories:
|
||||
for data_file_name in glob.glob(os.path.join(directory, 'suites',
|
||||
'*.data')):
|
||||
walk_test_suite(function, results, {}, data_file_name)
|
||||
ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
|
||||
if os.path.exists(ssl_opt_sh):
|
||||
walk_ssl_opt_sh(function, results, {}, ssl_opt_sh)
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument('--quiet', '-q',
|
||||
|
@ -118,15 +139,8 @@ def main():
|
|||
action='store_false', dest='quiet',
|
||||
help='Show warnings (default: on; undoes --quiet)')
|
||||
options = parser.parse_args()
|
||||
test_directories = collect_test_directories()
|
||||
results = Results(options)
|
||||
for directory in test_directories:
|
||||
for data_file_name in glob.glob(os.path.join(directory, 'suites',
|
||||
'*.data')):
|
||||
check_test_suite(results, data_file_name)
|
||||
ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
|
||||
if os.path.exists(ssl_opt_sh):
|
||||
check_ssl_opt_sh(results, ssl_opt_sh)
|
||||
walk_all(check_description, results)
|
||||
if (results.warnings or results.errors) and not options.quiet:
|
||||
sys.stderr.write('{}: {} errors, {} warnings\n'
|
||||
.format(sys.argv[0], results.errors, results.warnings))
|
||||
|
|
Loading…
Reference in a new issue