diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-02-05 12:27:32 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-02-05 12:27:32 +0100 |
| commit | 904a033ae738e1c351f8fef71e2ec2418fc4db3d (patch) | |
| tree | 3de4980582c109c4f0d19111a2b88eafec9b9b36 /minishell_test/__main__.py | |
| parent | a3e983f78dc4cbcf6f75f78fa2b3c57e09cd1b2b (diff) | |
| download | minishell_test-904a033ae738e1c351f8fef71e2ec2418fc4db3d.tar.gz minishell_test-904a033ae738e1c351f8fef71e2ec2418fc4db3d.tar.bz2 minishell_test-904a033ae738e1c351f8fef71e2ec2418fc4db3d.zip | |
Renaming src -> minishell_test for package name, Renaming main.py -> __main__.py for package execution with python -m
Diffstat (limited to 'minishell_test/__main__.py')
| -rwxr-xr-x | minishell_test/__main__.py | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/minishell_test/__main__.py b/minishell_test/__main__.py new file mode 100755 index 0000000..fe48b5e --- /dev/null +++ b/minishell_test/__main__.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python3 + +# ############################################################################ # +# # +# ::: :::::::: # +# main.py :+: :+: :+: # +# +:+ +:+ +:+ # +# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2020/07/15 15:11:52 by charles #+# #+# # +# Updated: 2020/07/15 15:11:52 by charles ### ########.fr # +# # +# ############################################################################ # + +import os +import sys +import shutil +import distutils.spawn +import subprocess + +import config +import sandbox +from args import parse_args +from suite import Suite +from suites import * # noqa: F403,F401 + + +def main(): + args = parse_args() + if args.list: + Suite.list() + sys.exit(0) + + if config.MINISHELL_MAKE or args.make: + try: + print("{:=^{width}}".format("MAKE", width=config.TERM_COLS)) + subprocess.run(["make", "--no-print-directory", "-C", config.MINISHELL_DIR], + check=True, + env={"MINISHELL_TEST_FLAGS": "-DMINISHELL_TEST", **os.environ}) + print("=" * config.TERM_COLS) + except subprocess.CalledProcessError: + sys.exit(1) + if args.make: + sys.exit(0) + if os.path.exists(config.EXECUTABLES_PATH): + shutil.rmtree(config.EXECUTABLES_PATH) + os.mkdir(config.EXECUTABLES_PATH) + for cmd in config.AVAILABLE_COMMANDS: + cmd_path = distutils.spawn.find_executable(cmd) + if cmd_path is None: + raise RuntimeError + shutil.copy(cmd_path, + os.path.join(config.EXECUTABLES_PATH, cmd)) + + reference_args = os.environ.get("MINISHELL_TEST_ARGS") + if reference_args is not None: + config.REFERENCE_ARGS.extend(reference_args.split(',')) + + pager = os.environ.get("MINISHELL_TEST_PAGER") + if pager is not None: + config.PAGER = pager + + config.VERBOSE_LEVEL = args.verbose + if args.bonus or os.environ.get("MINISHELL_TEST_BONUS") == "yes": + config.BONUS = True + if args.no_bonus: + config.BONUS = False + config.EXIT_FIRST = args.exit_first + config.CHECK_LEAKS = args.check_leaks + config.RANGE = args.range + config.SHOW_RANGE = args.show_range + if config.RANGE is not None or config.CHECK_LEAKS: + config.SHOW_RANGE = True + + Suite.setup(args.suites) + try: + Suite.run_all() + except KeyboardInterrupt: + sandbox.remove() + + Suite.summarize() + Suite.save_log() + print("See", config.LOG_PATH, "for more information") + if config.CHECK_LEAKS: + print("HELP: Valgrind is really slow the -x and --range options could be useful" + " (./run -h for more details)") + + if args.pager: + subprocess.run([config.PAGER, config.LOG_PATH]) + + +if __name__ == "__main__": + main() |
