From f06e8de42359cff6cb93dad4a89c64078d864790 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 8 Oct 2020 12:03:46 +0200 Subject: Added syntax error discard --- README.md | 9 ++++++++- src/hooks.py | 7 ++++++- src/main.py | 5 ++++- src/test/test.py | 23 ++++++++++++++--------- 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 7bbc73c..a0ea7d8 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,14 @@ Their is 3 different method to enable the bonus tests: ## Memory leaks -`./run -kx` +`./run -k`, checkout the `--show-range`, `--range` and `-x` options to help +to select the tests to run since valgrind is really slow. + +## Custom syntax error message + +If you don't want to copy bash syntax error message, +you can set the environment variable `MINISHELL_TEST_DONT_CHECK_ERROR_MESSAGE` to `yes`. +It will still test your exit status code but will discard any output on error tests. ## Linux diff --git a/src/hooks.py b/src/hooks.py index 2d55bbb..5ec2dde 100644 --- a/src/hooks.py +++ b/src/hooks.py @@ -6,12 +6,13 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 16:10:20 by charles #+# #+# # -# Updated: 2020/10/07 15:18:13 by cacharle ### ########.fr # +# Updated: 2020/10/08 11:43:54 by cacharle ### ########.fr # # # # ############################################################################ # import re import sys +import os import config @@ -23,6 +24,10 @@ 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": + return "DISCARDED BY TEST" + lines = output.split('\n') if len(lines) != 3: return output diff --git a/src/main.py b/src/main.py index 2b70393..05e9158 100755 --- a/src/main.py +++ b/src/main.py @@ -66,7 +66,7 @@ def main(): config.CHECK_LEAKS = args.check_leaks config.RANGE = args.range config.SHOW_RANGE = args.show_range - if config.RANGE is not None: + if config.RANGE is not None or config.CHECK_LEAKS: config.SHOW_RANGE = True Suite.setup(args.suites) @@ -78,6 +78,9 @@ def main(): Suite.summarize() Suite.save_log() print("See", config.LOG_PATH, "for more information") + if config.CHECK_LEAKS: + print("HELP: Valgrind is really slow the -x and --range options could be useful" + " (./run -h for more details)") if args.pager: subprocess.run([config.PAGER, config.LOG_PATH]) diff --git a/src/test/test.py b/src/test/test.py index 542a9d8..6668573 100644 --- a/src/test/test.py +++ b/src/test/test.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/06/16 21:48:50 by charles #+# #+# # -# Updated: 2020/10/08 08:45:34 by cacharle ### ########.fr # +# Updated: 2020/10/08 10:05:39 by cacharle ### ########.fr # # # # ############################################################################ # @@ -62,19 +62,13 @@ class Test: self.hook = [] self.hook_status = [] captured = self._run_sandboxed([*config.VALGRIND_CMD, "-c"]) - self.result = Result.leak(self.cmd, captured.output) + self.result = Result.leak(self.full_cmd, captured.output) self.result.put(index) return expected = self._run_sandboxed([config.REFERENCE_PATH, *config.REFERENCE_ARGS, "-c"]) actual = self._run_sandboxed([config.MINISHELL_PATH, "-c"]) - s = self.cmd - if self.setup != "": - s = "[SETUP {}] {}".format(self.setup, s) - if len(self.exports) != 0: - s = "[EXPORTS {}] {}".format( - ' '.join(["{}='{:.20}'".format(k, v) for k, v in self.exports.items()]), s) - self.result = Result(s, self.files, expected, actual) + self.result = Result(self.full_cmd, self.files, expected, actual) self.result.put(index) def _run_sandboxed(self, shell_cmd: [str]) -> Captured: @@ -146,3 +140,14 @@ class Test: for h in self.hook_status: process.returncode = h(process.returncode) return Captured(output, process.returncode, files_content) + + @property + def full_cmd(self): + """ Return the command prefixed by the setup and exports """ + s = self.cmd + if self.setup != "": + s = "[SETUP {}] {}".format(self.setup, s) + if len(self.exports) != 0: + s = "[EXPORTS {}] {}".format( + ' '.join(["{}='{:.20}'".format(k, v) for k, v in self.exports.items()]), s) + return s -- cgit