|
20 | 20 | #
|
21 | 21 | # This file is part of Mbed TLS (https://tls.mbed.org)
|
22 | 22 |
|
| 23 | +import argparse |
23 | 24 | import glob
|
24 | 25 | import os
|
25 | 26 | import re
|
26 | 27 | import sys
|
27 | 28 |
|
28 | 29 | class Results:
|
29 |
| - def __init__(self): |
| 30 | + def __init__(self, options): |
30 | 31 | self.errors = 0
|
31 | 32 | self.warnings = 0
|
| 33 | + self.ignore_warnings = options.quiet |
32 | 34 |
|
33 | 35 | def error(self, file_name, line_number, fmt, *args):
|
34 | 36 | sys.stderr.write(('{}:{}:ERROR:' + fmt + '\n').
|
35 | 37 | format(file_name, line_number, *args))
|
36 | 38 | self.errors += 1
|
37 | 39 |
|
38 | 40 | 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 |
42 | 45 |
|
43 | 46 | def collect_test_directories():
|
44 | 47 | if os.path.isdir('tests'):
|
@@ -105,16 +108,24 @@ def check_ssl_opt_sh(results, file_name):
|
105 | 108 | file_name, line_number, description)
|
106 | 109 |
|
107 | 110 | 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() |
108 | 119 | test_directories = collect_test_directories()
|
109 |
| - results = Results() |
| 120 | + results = Results(options) |
110 | 121 | for directory in test_directories:
|
111 | 122 | for data_file_name in glob.glob(os.path.join(directory, 'suites',
|
112 | 123 | '*.data')):
|
113 | 124 | check_test_suite(results, data_file_name)
|
114 | 125 | ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
|
115 | 126 | if os.path.exists(ssl_opt_sh):
|
116 | 127 | 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: |
118 | 129 | sys.stderr.write('{}: {} errors, {} warnings\n'
|
119 | 130 | .format(sys.argv[0], results.errors, results.warnings))
|
120 | 131 | sys.exit(1 if results.errors else 0)
|
|
0 commit comments