Skip to content

Commit 20fdab1

Browse files
Add command line option to hide warnings
1 parent 604a7b2 commit 20fdab1

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

tests/scripts/check-test-cases.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,28 @@
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:
29-
def __init__(self):
30+
def __init__(self, options):
3031
self.errors = 0
3132
self.warnings = 0
33+
self.ignore_warnings = options.quiet
3234

3335
def error(self, file_name, line_number, fmt, *args):
3436
sys.stderr.write(('{}:{}:ERROR:' + fmt + '\n').
3537
format(file_name, line_number, *args))
3638
self.errors += 1
3739

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

4346
def collect_test_directories():
4447
if os.path.isdir('tests'):
@@ -105,16 +108,24 @@ def check_ssl_opt_sh(results, file_name):
105108
file_name, line_number, description)
106109

107110
def main():
111+
parser = argparse.ArgumentParser(description=__doc__)
112+
parser.add_argument('--quiet', '-q',
113+
action='store_true',
114+
help='Hide warnings')
115+
parser.add_argument('--verbose', '-v',
116+
action='store_false', dest='quiet',
117+
help='Show warnings (default: on; undoes --quiet)')
118+
options = parser.parse_args()
108119
test_directories = collect_test_directories()
109-
results = Results()
120+
results = Results(options)
110121
for directory in test_directories:
111122
for data_file_name in glob.glob(os.path.join(directory, 'suites',
112123
'*.data')):
113124
check_test_suite(results, data_file_name)
114125
ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
115126
if os.path.exists(ssl_opt_sh):
116127
check_ssl_opt_sh(results, ssl_opt_sh)
117-
if results.warnings or results.errors:
128+
if (results.warnings or results.errors) and not options.quiet:
118129
sys.stderr.write('{}: {} errors, {} warnings\n'
119130
.format(sys.argv[0], results.errors, results.warnings))
120131
sys.exit(1 if results.errors else 0)

0 commit comments

Comments
 (0)