|
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 | 30 | """Store file and line information about errors or warnings in test suites."""
|
30 |
| - def __init__(self): |
| 31 | + |
| 32 | + def __init__(self, options): |
31 | 33 | self.errors = 0
|
32 | 34 | self.warnings = 0
|
| 35 | + self.ignore_warnings = options.quiet |
33 | 36 |
|
34 | 37 | def error(self, file_name, line_number, fmt, *args):
|
35 | 38 | sys.stderr.write(('{}:{}:ERROR:' + fmt + '\n').
|
36 | 39 | format(file_name, line_number, *args))
|
37 | 40 | self.errors += 1
|
38 | 41 |
|
39 | 42 | 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 |
43 | 47 |
|
44 | 48 | def collect_test_directories():
|
45 | 49 | """Get the relative path for the TLS and Crypto test directories."""
|
@@ -108,16 +112,24 @@ def check_ssl_opt_sh(results, file_name):
|
108 | 112 | file_name, line_number, description)
|
109 | 113 |
|
110 | 114 | 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() |
111 | 123 | test_directories = collect_test_directories()
|
112 |
| - results = Results() |
| 124 | + results = Results(options) |
113 | 125 | for directory in test_directories:
|
114 | 126 | for data_file_name in glob.glob(os.path.join(directory, 'suites',
|
115 | 127 | '*.data')):
|
116 | 128 | check_test_suite(results, data_file_name)
|
117 | 129 | ssl_opt_sh = os.path.join(directory, 'ssl-opt.sh')
|
118 | 130 | if os.path.exists(ssl_opt_sh):
|
119 | 131 | 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: |
121 | 133 | sys.stderr.write('{}: {} errors, {} warnings\n'
|
122 | 134 | .format(sys.argv[0], results.errors, results.warnings))
|
123 | 135 | sys.exit(1 if results.errors else 0)
|
|
0 commit comments