diff options
Diffstat (limited to 'minishell_test')
| -rw-r--r-- | minishell_test/args.py | 2 | ||||
| -rw-r--r-- | minishell_test/hooks.py | 59 | ||||
| -rw-r--r-- | minishell_test/suites/builtin.py | 6 | ||||
| -rw-r--r-- | minishell_test/suites/flow.py | 14 |
4 files changed, 37 insertions, 44 deletions
diff --git a/minishell_test/args.py b/minishell_test/args.py index 3f56b8c..8aca64b 100644 --- a/minishell_test/args.py +++ b/minishell_test/args.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:32 by charles #+# #+# # -# Updated: 2021/02/27 12:08:55 by cacharle ### ########.fr # +# Updated: 2021/02/27 20:16:56 by cacharle ### ########.fr # # # # ############################################################################ # diff --git a/minishell_test/hooks.py b/minishell_test/hooks.py index 6356080..a1447cd 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 15:40:25 by cacharle ### ########.fr # +# Updated: 2021/02/27 20:54:14 by cacharle ### ########.fr # # # # ############################################################################ # @@ -44,18 +44,15 @@ def export_singleton(output): 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]) + if re.match("^{}[a-zA-Z_][a-zA-Z0-9_]*$".format(prefix), line) is None]) ) -def replace_double_slash(output): - """Replace occurence of double slash by one""" - return output.replace("//", "/") - - -def replace_double_semi_colon(output): - """Replace occurence of double semi-colon by one""" - return output.replace(";;", ";") +def replace_double(s): + """Replace double occurence of a string by one""" + def hook(output): + return output.replace(s + s, s) + return hook def platform_status(darwin_status, linux_status, windows_status=None): @@ -68,30 +65,33 @@ def platform_status(darwin_status, linux_status, windows_status=None): return hook -def is_directory(output): - if config.PLATFORM == "linux": - return output.replace("Is a directory", "is a directory") - else: - return output +def linux_only(func): + """ Decorator for hooks that only need to be executed on linux """ + def hook(output): + if not config.PLATFORM == "linux": + return output + return func(output) + return hook -# def no_cd_too_many_arguments(output): -# for i, line in output.split("\n"): -# if line.find("too many arguments") +@linux_only +def is_directory(output): + return output.replace("Is a directory", "is a directory") +@linux_only def shlvl_0_to_1(output): - if config.PLATFORM == "linux": - return output.replace("SHLVL=0", "SHLVL=1") - else: - return output + return output.replace("SHLVL=0", "SHLVL=1") +@linux_only def delete_escape(output): - if config.PLATFORM == "linux": - return output.replace("\\", "") - else: - return output + return output.replace("\\", "") + + +@linux_only +def linux_discard(output): + return "DISCARDED BY MINISHELL TEST" def error_eof_to_expected_token(output): @@ -101,13 +101,6 @@ def error_eof_to_expected_token(output): ) -def linux_discard(output): - if config.PLATFORM == "linux": - return "DISCARDED BY MINISHELL TEST" - else: - return output - - def should_not_be(not_expected): def hook(output): if output == not_expected: diff --git a/minishell_test/suites/builtin.py b/minishell_test/suites/builtin.py index c373ce6..2591bc3 100644 --- a/minishell_test/suites/builtin.py +++ b/minishell_test/suites/builtin.py @@ -6,7 +6,7 @@ # By: juligonz <juligonz@student.42.fr> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:43 by charles #+# #+# # -# Updated: 2021/02/27 12:07:46 by cacharle ### ########.fr # +# Updated: 2021/02/27 20:36:27 by cacharle ### ########.fr # # Updated: 2020/09/11 18:01:27 by juligonz ### ########.fr # # # # **************************************************************************** # @@ -168,7 +168,7 @@ def suite_cd(test): test("echo $PWD; echo $OLDPWD; cd /.; pwd; echo $PWD; echo $OLDPWD") test("echo $PWD; echo $OLDPWD; cd /./; pwd; echo $PWD; echo $OLDPWD") test("echo $PWD; echo $OLDPWD; cd /././././; pwd; echo $PWD; echo $OLDPWD") - test("echo $PWD; echo $OLDPWD; cd //; pwd; echo $PWD; echo $OLDPWD", hook=hooks.replace_double_slash) + test("echo $PWD; echo $OLDPWD; cd //; pwd; echo $PWD; echo $OLDPWD", hook=hooks.replace_double("/")) test("echo $PWD; echo $OLDPWD; cd ///; pwd; echo $PWD; echo $OLDPWD") test("echo $PWD; echo $OLDPWD; cd ////; pwd; echo $PWD; echo $OLDPWD") test("echo $PWD; echo $OLDPWD; cd //////////////////////////////////////////////////////; pwd; echo $PWD; echo $OLDPWD") @@ -179,7 +179,7 @@ def suite_cd(test): test("echo $PWD; echo $OLDPWD; cd ' /'; pwd; echo $PWD; echo $OLDPWD") test("echo $PWD; echo $OLDPWD; cd ' / '; pwd; echo $PWD; echo $OLDPWD") test("echo $PWD; echo $OLDPWD; cd ' // '; pwd; echo $PWD; echo $OLDPWD") - test("echo $PWD; echo $OLDPWD; cd //home; pwd; echo $PWD; echo $OLDPWD", hook=hooks.replace_double_slash) + test("echo $PWD; echo $OLDPWD; cd //home; pwd; echo $PWD; echo $OLDPWD", hook=hooks.replace_double("/")) test("echo $PWD; echo $OLDPWD; cd ' //home'; pwd; echo $PWD; echo $OLDPWD") test("echo $PWD; echo $OLDPWD; cd ' //home '; pwd; echo $PWD; echo $OLDPWD") test("echo $PWD; echo $OLDPWD; cd d; echo $OLDPWD", setup="mkdir -m 000 d") diff --git a/minishell_test/suites/flow.py b/minishell_test/suites/flow.py index 2adbb4b..aa6d395 100644 --- a/minishell_test/suites/flow.py +++ b/minishell_test/suites/flow.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:52 by charles #+# #+# # -# Updated: 2021/02/27 12:06:58 by cacharle ### ########.fr # +# Updated: 2021/02/27 20:35:46 by cacharle ### ########.fr # # # # ############################################################################ # @@ -16,7 +16,7 @@ from minishell_test.hooks import ( error_line0, platform_status, discard, - replace_double_semi_colon, + replace_double, error_eof_to_expected_token ) @@ -49,11 +49,11 @@ def suite_end(test): test("; ;", hook=error_line0, hook_status=platform_status(2, 1)) test("; ; ;", hook=error_line0, hook_status=platform_status(2, 1)) test("echo a ; ; echo b", hook=error_line0, hook_status=platform_status(2, 1)) - test(";;", hook=[error_line0, replace_double_semi_colon], hook_status=platform_status(2, 1)) - test(";;;", hook=[error_line0, replace_double_semi_colon], hook_status=platform_status(2, 1)) - test(";;;;;", hook=[error_line0, replace_double_semi_colon], hook_status=platform_status(2, 1)) - test("echo a ;; echo b", hook=[error_line0, replace_double_semi_colon], hook_status=platform_status(2, 1)) - test("echo a ;;;;; echo b", hook=[error_line0, replace_double_semi_colon], hook_status=platform_status(2, 1)) + test(";;", hook=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) + test(";;;", hook=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) + test(";;;;;", hook=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) + test("echo a ;; echo b", hook=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) + test("echo a ;;;;; echo b", hook=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) test("ls " + 40 * " ; ls", setup="touch a b c") test("ls " + 80 * " ; ls", setup="touch a b c") test("ls " + 40 * " ; ls" + ";", setup="touch a b c") |
