Skip to content

Commit 7abd984

Browse files
Add command line option to hide warnings
1 parent 5440deb commit 7abd984

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

tests/scripts/check-test-cases.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,30 @@
2020
#
2121
# This file is part of Mbed TLS (https://tls.mbed.org)
2222

23+
import argparse
2324
import glob
2425
import os
2526
import re
2627
import sys
2728

2829
class Results:
2930
"""Store file and line information about errors or warnings in test suites."""
30-
def __init__(self):
31+
32+
def __init__(self, options):
3133
self.errors = 0
3234
self.warnings = 0
35+
self.ignore_warnings = options.quiet
3336

3437
def error(self, file_name, line_number, fmt, *args):
3538
sys.stderr.write(('{}:{}:ERROR:' + fmt + '\n').
3639
format(file_name, line_number, *args))
3740
self.errors += 1
3841

3942
def warning(self, file_name, line_number, fmt, *args):
40-
sys.stderr.write(('{}:{}:Warning:' + fmt + '\n')
41-
.format(file_name, line_number, *args))
42-
self.warnings += 1
43+
if not self.ignore_warnings:
44+
sys.stderr.write(('{}:{}:Warning:' + fmt + '\n')
45+
.format(file_name, line_number, *args))
46+
self.warnings += 1
4347

4448
def collect_test_directories():
4549
"""Get the relative path for the TLS and Crypto test directories."""
@@ -108,16 +112,24 @@ def check_ssl_opt_sh(results, file_name):
108112
file_name, line_number, description)
109113

110114
def main():
115+
parser = argparse.ArgumentParser(description=__doc__)
116+
parser.add_argument('--quiet', '-q',
117+
action='store_true',
118+
help='Hide warnings')
119+
parser.add_argument('--verbose', '-v',
120+
action='store_false', dest='quiet',
121+
help='Show warnings (default: on; undoes --quiet)')
122+
options = parser.parse_args()
111123
test_directories = collect_test_directories()
112-
results = Results()
124+
results = Results(options)
113125
for directory in test_directories:
114126
for data_file_name in glob.glob(os.path.join(directory, 'suites',
115127
'*.data')):
116128
check_test_suite(results, data_file_name)
117129
ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
118130
if os.path.exists(ssl_opt_sh):
119131
check_ssl_opt_sh(results, ssl_opt_sh)
120-
if results.warnings or results.errors:
132+
if (results.warnings or results.errors) and not options.quiet:
121133
sys.stderr.write('{}: {} errors, {} warnings\n'
122134
.format(sys.argv[0], results.errors, results.warnings))
123135
sys.exit(1 if results.errors else 0)

0 commit comments

Comments
 (0)