From 7081b93b8ed4f98c628400e05d22d0523f41a842 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 27 Feb 2021 12:24:37 +0100 Subject: Fixing #16 - Adding support for custom config file in user directory --- minishell_test/hooks.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) (limited to 'minishell_test/hooks.py') diff --git a/minishell_test/hooks.py b/minishell_test/hooks.py index 9881354..dbbd975 100644 --- a/minishell_test/hooks.py +++ b/minishell_test/hooks.py @@ -6,15 +6,14 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 16:10:20 by charles #+# #+# # -# Updated: 2021/02/05 15:13:30 by charles ### ########.fr # +# Updated: 2021/02/27 12:09:25 by cacharle ### ########.fr # # # # ############################################################################ # import re -import sys import os -import minishell_test.config as config +from minishell_test import config def sort_lines(output): @@ -31,7 +30,7 @@ def error_line0(output): lines = output.split('\n') if len(lines) != 3: return output - prefix = "{}: -c: line 0: ".format(config.REFERENCE_PATH) + prefix = "{}: -c: line 0: ".format(config.SHELL_REFERENCE_PATH) if lines[0].find(prefix) != 0: return output return lines[0].replace(prefix, "minishell: ") + "\n" @@ -44,7 +43,7 @@ def discard(output): def export_singleton(output): """Remove variable that are not set to anything in a call to export without arguments""" - prefix = "export " if ("--posix" in config.REFERENCE_ARGS) else "declare -x " + prefix = "export " if ("--posix" in config.SHELL_REFERENCE_ARGS) else "declare -x " return sort_lines( '\n'.join([line for line in output.split('\n') if re.match("^{}[a-zA-Z]+$".format(prefix), line) is None]) @@ -63,20 +62,16 @@ def replace_double_semi_colon(output): def platform_status(darwin_status, linux_status, windows_status=None): def hook(status): - if config.PLATFORM == "Darwin": + if config.PLATFORM == "darwin": return status - elif config.PLATFORM == "Linux": + elif config.PLATFORM == "linux": return (darwin_status if status == linux_status else status) - else: - raise RuntimeError("This platform exit codes are not supported yet," - "feel free to contact me to add it.") - sys.exit(2) return status return hook def is_directory(output): - if config.PLATFORM == "Linux": + if config.PLATFORM == "linux": return output.replace("Is a directory", "is a directory") else: return output @@ -88,14 +83,14 @@ def is_directory(output): def shlvl_0_to_1(output): - if config.PLATFORM == "Linux": + if config.PLATFORM == "linux": return output.replace("SHLVL=0", "SHLVL=1") else: return output def delete_escape(output): - if config.PLATFORM == "Linux": + if config.PLATFORM == "linux": return output.replace("\\", "") else: return output @@ -109,7 +104,7 @@ def error_eof_to_expected_token(output): def linux_discard(output): - if config.PLATFORM == "Linux": + if config.PLATFORM == "linux": return "DISCARDED BY MINISHELL TEST" else: return output -- cgit