diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-02-28 12:11:50 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-02-28 12:11:50 +0100 |
| commit | b1e0674c4f91c39c426a145686c1c37f57528b46 (patch) | |
| tree | 82c6624c78478949ed08e1a2f6f8d287b35a7be7 /minishell_test | |
| parent | b6eb06aeee0fda77395d7b3172c44b999b70cdee (diff) | |
| download | minishell_test-b1e0674c4f91c39c426a145686c1c37f57528b46.tar.gz minishell_test-b1e0674c4f91c39c426a145686c1c37f57528b46.tar.bz2 minishell_test-b1e0674c4f91c39c426a145686c1c37f57528b46.zip | |
Added all hooks tests
Diffstat (limited to 'minishell_test')
| -rw-r--r-- | minishell_test/config.py | 6 | ||||
| -rw-r--r-- | minishell_test/hooks.py | 67 |
2 files changed, 33 insertions, 40 deletions
diff --git a/minishell_test/config.py b/minishell_test/config.py index db98ce5..00d147c 100644 --- a/minishell_test/config.py +++ b/minishell_test/config.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/02/26 09:40:36 by cacharle #+# #+# # -# Updated: 2021/02/28 10:53:38 by cacharle ### ########.fr # +# Updated: 2021/02/28 11:19:13 by cacharle ### ########.fr # # # # ############################################################################ # @@ -78,7 +78,7 @@ class Config(): @classmethod def init(cls, args): if isinstance(args, list): - args = parse_args(sys.argv[1:]) + args = parse_args(args) cls.minishell_dir = Path(args.path).resolve() @@ -160,7 +160,7 @@ class Config(): cfg = ConfigParser() cfg.read(DATA_DIR / 'default.cfg') user_cfg = ConfigParser() - user_cfg.read(cls.minishell_dir / CONFIG_FILENAME) + user_cfg.read(cls.minishell_dir / CONFIG_FILENAME) # if file doesn't exists, returns [] for section in user_cfg: if section not in cfg: diff --git a/minishell_test/hooks.py b/minishell_test/hooks.py index 67c3f84..54963c9 100644 --- a/minishell_test/hooks.py +++ b/minishell_test/hooks.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 16:10:20 by charles #+# #+# # -# Updated: 2021/02/27 20:54:14 by cacharle ### ########.fr # +# Updated: 2021/02/28 12:06:14 by cacharle ### ########.fr # # # # ############################################################################ # @@ -15,6 +15,9 @@ import re from minishell_test.config import Config +DISCARDED_TEXT = "DISCARDED BY TEST" + + def sort_lines(output): """Sort lines of output""" return '\n'.join(sorted(output.split('\n'))) @@ -23,7 +26,7 @@ def sort_lines(output): def error_line0(output): """Replace "/bin/bash: -c: line n:" by "minishell:" and delete the second line""" if not Config.check_error_messages: - return "DISCARDED BY TEST" + return DISCARDED_TEXT lines = output.split('\n') if len(lines) != 3: @@ -36,7 +39,7 @@ def error_line0(output): def discard(output): """Discard the output""" - return "DISCARDED BY TEST" + return DISCARDED_TEXT def export_singleton(output): @@ -55,7 +58,22 @@ def replace_double(s): return hook -def platform_status(darwin_status, linux_status, windows_status=None): +def error_eof_to_expected_token(output): + return output.replace( + "-c: line 1: syntax error: unexpected end of file", + "syntax error expected token" + ) + + +def should_not_be(not_expected): + def hook(output): + if output == not_expected: + return "OUTPUT SHOULD NOT BE " + output + return DISCARDED_TEXT + return hook + + +def platform_status(darwin_status, linux_status): def hook(status): if Config.platform == "darwin": return status @@ -65,45 +83,20 @@ def platform_status(darwin_status, linux_status, windows_status=None): return hook -def linux_only(func): - """ Decorator for hooks that only need to be executed on linux """ +def linux_replace(f, t): def hook(output): if not Config.platform == "linux": return output - return func(output) + return output.replace(f, t) return hook -@linux_only -def is_directory(output): - return output.replace("Is a directory", "is a directory") - - -@linux_only -def shlvl_0_to_1(output): - return output.replace("SHLVL=0", "SHLVL=1") +is_directory = linux_replace("Is a directory", "is a directory") +shlvl_0_to_1 = linux_replace("SHLVL=0", "SHLVL=1") +delete_escape = linux_replace("\\", "") -@linux_only -def delete_escape(output): - return output.replace("\\", "") - - -@linux_only def linux_discard(output): - return "DISCARDED BY MINISHELL TEST" - - -def error_eof_to_expected_token(output): - return output.replace( - "-c: line 1: syntax error: unexpected end of file", - "syntax error expected token" - ) - - -def should_not_be(not_expected): - def hook(output): - if output == not_expected: - return "OUTPUT SHOULD NOT BE " + output - return "DISCARDED BY TEST" - return hook + if not Config.platform == "linux": + return output + return DISCARDED_TEXT |
