diff options
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/ctest-driver.py | 102 | ||||
| -rwxr-xr-x | tools/project-clang-format.py | 66 |
2 files changed, 117 insertions, 51 deletions
diff --git a/tools/ctest-driver.py b/tools/ctest-driver.py index f429a0c..2a75534 100755 --- a/tools/ctest-driver.py +++ b/tools/ctest-driver.py @@ -22,7 +22,6 @@ import re import subprocess import sys - SCRIPT_NAME = os.path.basename(__file__) @@ -41,9 +40,13 @@ def read_file(path): def run(cmd_line): try: - result = subprocess.run(cmd_line, check=True, universal_newlines=True, - stderr=subprocess.STDOUT, - stdout=subprocess.PIPE) + result = subprocess.run( + cmd_line, + check=True, + universal_newlines=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + ) assert result.returncode == 0 return result.stdout except subprocess.CalledProcessError as e: @@ -53,8 +56,9 @@ def run(cmd_line): def run_new_window(cmd_line): try: - result = subprocess.run(cmd_line, check=True, - creationflags=subprocess.CREATE_NEW_CONSOLE) + result = subprocess.run( + cmd_line, check=True, creationflags=subprocess.CREATE_NEW_CONSOLE + ) assert result.returncode == 0 return None except subprocess.CalledProcessError as e: @@ -77,8 +81,10 @@ def match_pass_regexes(output, regexes): if not regexes: return if not match_all(output, regexes): - err("Couldn't match test program's output against all of the"\ - " regular expressions:") + err( + "Couldn't match test program's output against all of the" + " regular expressions:" + ) for regex in regexes: err(f'\t{regex}') sys.exit(1) @@ -88,8 +94,7 @@ def match_fail_regexes(output, regexes): if not regexes: return if match_any(output, regexes): - err("Matched test program's output against some of the regular"\ - " expressions:") + err("Matched test program's output against some of the regular" " expressions:") for regex in regexes: err(f'\t{regex}') sys.exit(1) @@ -120,34 +125,67 @@ def parse_args(argv=None): argv = sys.argv[1:] parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) + description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter + ) subparsers = parser.add_subparsers(dest='command') - parser_run = subparsers.add_parser('run', help='run an executable and check its output') - parser_run.add_argument('-p', '--pass-regex', nargs='*', - dest='pass_regexes', metavar='REGEX', - help='pass if all of these regexes match') - parser_run.add_argument('-f', '--fail-regex', nargs='*', - dest='fail_regexes', metavar='REGEX', - help='fail if any of these regexes matches') - parser_run.add_argument('-n', '--new-window', action='store_true', - help='launch child process in a new console window') - parser_run.add_argument('exe_path', metavar='PATH', - help='path to the test executable') + parser_run = subparsers.add_parser( + 'run', help='run an executable and check its output' + ) + parser_run.add_argument( + '-p', + '--pass-regex', + nargs='*', + dest='pass_regexes', + metavar='REGEX', + help='pass if all of these regexes match', + ) + parser_run.add_argument( + '-f', + '--fail-regex', + nargs='*', + dest='fail_regexes', + metavar='REGEX', + help='fail if any of these regexes matches', + ) + parser_run.add_argument( + '-n', + '--new-window', + action='store_true', + help='launch child process in a new console window', + ) + parser_run.add_argument( + 'exe_path', metavar='PATH', help='path to the test executable' + ) # nargs='*' here would discard additional '--'s. - parser_run.add_argument('exe_args', metavar='ARG', nargs=argparse.REMAINDER, - help='test executable arguments') + parser_run.add_argument( + 'exe_args', + metavar='ARG', + nargs=argparse.REMAINDER, + help='test executable arguments', + ) parser_run.set_defaults(func=run_actual_test_driver) - parser_grep = subparsers.add_parser('grep', help='check file contents for matching patterns') - parser_grep.add_argument('-p', '--pass-regex', nargs='*', - dest='pass_regexes', metavar='REGEX', - help='pass if all of these regexes match') - parser_grep.add_argument('-f', '--fail-regex', nargs='*', - dest='fail_regexes', metavar='REGEX', - help='fail if any of these regexes matches') + parser_grep = subparsers.add_parser( + 'grep', help='check file contents for matching patterns' + ) + parser_grep.add_argument( + '-p', + '--pass-regex', + nargs='*', + dest='pass_regexes', + metavar='REGEX', + help='pass if all of these regexes match', + ) + parser_grep.add_argument( + '-f', + '--fail-regex', + nargs='*', + dest='fail_regexes', + metavar='REGEX', + help='fail if any of these regexes matches', + ) parser_grep.add_argument('path', metavar='PATH', help='text file path') parser_grep.set_defaults(func=grep_file) diff --git a/tools/project-clang-format.py b/tools/project-clang-format.py index 2f36613..113f7ff 100755 --- a/tools/project-clang-format.py +++ b/tools/project-clang-format.py @@ -26,7 +26,8 @@ def setup_logging(): logging.basicConfig( format='%(asctime)s | %(levelname)s | %(message)s', datefmt='%Y-%m-%d %H:%M:%S%z', - level=logging.INFO) + level=logging.INFO, + ) try: yield except Exception as e: @@ -51,8 +52,13 @@ def normalize_path(entry): def run(cmd_line): logging.debug('Running executable: %s', cmd_line) try: - return subprocess.run(cmd_line, check=True, universal_newlines=True, - stderr=subprocess.STDOUT, stdout=subprocess.PIPE) + return subprocess.run( + cmd_line, + check=True, + universal_newlines=True, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + ) except subprocess.CalledProcessError as e: logging.error('Process finished with exit code %d: %s', e.returncode, cmd_line) logging.error('Its output was:\n%s', e.output) @@ -87,8 +93,13 @@ class ClangFormat: original_lbl = f'{path} (original)' formatted_lbl = f'{path} (formatted)' - diff = difflib.unified_diff(original, formatted, fromfile=original_lbl, - tofile=formatted_lbl, lineterm='') + diff = difflib.unified_diff( + original, + formatted, + fromfile=original_lbl, + tofile=formatted_lbl, + lineterm='', + ) clean = True for line in diff: @@ -136,7 +147,9 @@ def filter_files(paths, exclude): return (path for path in paths if not excluded(path, exclude)) -CPP_FILE_EXTENSIONS = set(('.c', '.h', '.cc', '.hh', '.cpp', '.hpp', '.cxx', '.hxx', '.cp', '.c++')) +CPP_FILE_EXTENSIONS = set( + ('.c', '.h', '.cc', '.hh', '.cpp', '.hpp', '.cxx', '.hxx', '.cp', '.c++') +) def list_cpp_files(): @@ -150,8 +163,9 @@ DEFAULT_VERSION = 'clang-format' DEFAULT_STYLE = 'file' -def process_cpp_files(version=DEFAULT_VERSION, style=DEFAULT_STYLE, - in_place=False, exclude=None): +def process_cpp_files( + version=DEFAULT_VERSION, style=DEFAULT_STYLE, in_place=False, exclude=None +): clang_format = ClangFormat(version, style) with cd(git_root_dir()): cpp_files = filter_files(list_cpp_files(), exclude) @@ -167,18 +181,32 @@ def parse_args(argv=None): argv = sys.argv[1:] parser = argparse.ArgumentParser( - description=__doc__, - formatter_class=argparse.RawDescriptionHelpFormatter) + description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter + ) - parser.add_argument('-b', '--clang-format', dest='version', - default=DEFAULT_VERSION, - help='clang-format executable file path') - parser.add_argument('-s', '--style', default=DEFAULT_STYLE, - help='clang-format -style parameter argument') - parser.add_argument('-i', '--in-place', action='store_true', - help='edit the files in-place') - parser.add_argument('-e', '--exclude', nargs='*', type=normalize_path, - help='files or directories to exclude') + parser.add_argument( + '-b', + '--clang-format', + dest='version', + default=DEFAULT_VERSION, + help='clang-format executable file path', + ) + parser.add_argument( + '-s', + '--style', + default=DEFAULT_STYLE, + help='clang-format -style parameter argument', + ) + parser.add_argument( + '-i', '--in-place', action='store_true', help='edit the files in-place' + ) + parser.add_argument( + '-e', + '--exclude', + nargs='*', + type=normalize_path, + help='files or directories to exclude', + ) return parser.parse_args(argv) |
