aboutsummaryrefslogtreecommitdiff
path: root/minishell_test/hooks.py
diff options
context:
space:
mode:
Diffstat (limited to 'minishell_test/hooks.py')
-rw-r--r--minishell_test/hooks.py35
1 files changed, 14 insertions, 21 deletions
diff --git a/minishell_test/hooks.py b/minishell_test/hooks.py
index 9881354..6356080 100644
--- a/minishell_test/hooks.py
+++ b/minishell_test/hooks.py
@@ -6,15 +6,13 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/11 16:10:20 by charles #+# #+# #
-# Updated: 2021/02/05 15:13:30 by charles ### ########.fr #
+# Updated: 2021/02/27 15:40: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):
@@ -23,18 +21,17 @@ def sort_lines(output):
def error_line0(output):
- """Replace "/bin/bash: -c: line 0:" by "minishell:" and delete the second line"""
- error_message = os.environ.get("MINISHELL_TEST_DONT_CHECK_ERROR_MESSAGE")
- if error_message is not None and error_message == "yes":
+ """Replace "/bin/bash: -c: line n:" by "minishell:" and delete the second line"""
+ if not config.CHECK_ERROR_MESSAGES:
return "DISCARDED BY TEST"
lines = output.split('\n')
if len(lines) != 3:
return output
- prefix = "{}: -c: line 0: ".format(config.REFERENCE_PATH)
- if lines[0].find(prefix) != 0:
+ prefix = config.SHELL_REFERENCE_PREFIX + "-c: "
+ if not lines[0].startswith(prefix):
return output
- return lines[0].replace(prefix, "minishell: ") + "\n"
+ return lines[0].replace(prefix, config.MINISHELL_PREFIX, 1) + "\n"
def discard(output):
@@ -44,7 +41,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 +60,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 +81,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 +102,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