From 0cf5f137f886bd4e80868dcf2cf74b3f3b2c28d3 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Sat, 27 Feb 2021 15:43:07 +0100 Subject: Fixing #10 - bash error line with number 0 or 1 --- minishell_test/config.py | 19 ++++++++++++------- minishell_test/hooks.py | 9 ++++----- minishell_test/test/captured.py | 19 +++++++++---------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/minishell_test/config.py b/minishell_test/config.py index ab40afe..5a45e8b 100644 --- a/minishell_test/config.py +++ b/minishell_test/config.py @@ -6,7 +6,7 @@ # By: cacharle +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/02/26 09:40:36 by cacharle #+# #+# # -# Updated: 2021/02/27 14:44:12 by cacharle ### ########.fr # +# Updated: 2021/02/27 15:13:19 by cacharle ### ########.fr # # # # ############################################################################ # @@ -22,11 +22,12 @@ import minishell_test.data from minishell_test.args import parse_args -DATA_DIR = Path(inspect.getfile(minishell_test.data)).parent -CONFIG_FILENAME = Path('minishell_test.cfg') +DATA_DIR = Path(inspect.getfile(minishell_test.data)).parent class ConfigParser(configparser.ConfigParser): + BOOLEAN_STATES = {'true': True, 'false': False} + def __init__(self): super().__init__(self) @@ -41,16 +42,19 @@ class ConfigParser(configparser.ConfigParser): return self.get(section, options).strip().split('\n') +args = parse_args() +MINISHELL_DIR = Path(args.path).resolve() + +CONFIG_FILENAME = Path('minishell_test.cfg') config = ConfigParser() config.read(DATA_DIR / 'default.cfg') # TODO check user_config for unkown stuff user_config = ConfigParser() -user_config.read(Path(".") / CONFIG_FILENAME) +user_config.read(MINISHELL_DIR / CONFIG_FILENAME) config.read_dict({**config, **user_config}) -args = parse_args() BONUS = config.getboolean('minishell_test', 'bonus') EXEC_NAME = config.get('minishell_test', 'exec_name') @@ -70,7 +74,6 @@ SHELL_REFERENCE_ARGS = config.getargs('shell:reference', 'args') TIMEOUT_TEST = config.getfloat('timeout', 'test') TIMEOUT_LEAKS = config.getfloat('timeout', 'leaks') - xdg_cache_home = os.environ.get('XDG_CACHE_HOME') home = os.environ.get('HOME') if xdg_cache_home is not None: @@ -88,9 +91,11 @@ SHELL_PATH_VARIABLE = SHELL_PATH_VARIABLE.format(shell_available_commands_dir=SH with open(DATA_DIR / 'lorem') as f: LOREM = ' '.join(f.read().split('\n')) -MINISHELL_DIR = Path(args.path).resolve() MINISHELL_EXEC_PATH = MINISHELL_DIR / EXEC_NAME +MINISHELL_PREFIX = EXEC_NAME + ": " +SHELL_REFERENCE_PREFIX = str(SHELL_REFERENCE_PATH) + ": " + EXIT_FIRST = args.exit_first RANGE = args.range CHECK_LEAKS = args.check_leaks diff --git a/minishell_test/hooks.py b/minishell_test/hooks.py index 531580a..6356080 100644 --- a/minishell_test/hooks.py +++ b/minishell_test/hooks.py @@ -6,12 +6,11 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 16:10:20 by charles #+# #+# # -# Updated: 2021/02/27 14:44:19 by cacharle ### ########.fr # +# Updated: 2021/02/27 15:40:25 by cacharle ### ########.fr # # # # ############################################################################ # import re -import os from minishell_test import config @@ -29,10 +28,10 @@ def error_line0(output): lines = output.split('\n') if len(lines) != 3: return output - prefix = "{}: -c: line 0: ".format(config.SHELL_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): diff --git a/minishell_test/test/captured.py b/minishell_test/test/captured.py index a6141e8..e1ef29a 100644 --- a/minishell_test/test/captured.py +++ b/minishell_test/test/captured.py @@ -6,13 +6,14 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:16:25 by charles #+# #+# # -# Updated: 2021/02/27 12:20:00 by cacharle ### ########.fr # +# Updated: 2021/02/27 15:25:58 by cacharle ### ########.fr # # # # ############################################################################ # +import re from typing import List, Optional -# from minishell_test import config +from minishell_test import config class Captured: @@ -30,14 +31,12 @@ class Captured: is_timeout: the command has timed out """ - # lines = output.split('\n') - # for i, l in enumerate(lines): - # if l.find(config.REFERENCE_ERROR_BEGIN) == 0: - # lines[i] = l.replace(config.REFERENCE_ERROR_BEGIN, config.MINISHELL_ERROR_BEGIN, 1) - # elif l.find(config.REFERENCE_PATH + ": ") == 0: - # lines[i] = l.replace(config.REFERENCE_PATH + ": ", config.MINISHELL_ERROR_BEGIN, 1) - - self.output = output # '\n'.join(lines) + lines = output.split('\n') + for i, _ in enumerate(lines): + lines[i] = line = re.sub(f"line [01]: ", "", lines[i], 1) + if line.startswith(config.SHELL_REFERENCE_PREFIX): + lines[i] = config.MINISHELL_PREFIX + line[len(config.SHELL_REFERENCE_PREFIX):] + self.output = '\n'.join(lines) self.status = status self.files_content = files_content -- cgit