From c48f9194ac7cd2a15d0f86d8d03b0a8d6001d387 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 8 Oct 2020 09:05:33 +0200 Subject: Added test range selection for long valgrind tests --- src/args.py | 8 ++++---- src/config.py | 6 +++++- src/main.py | 4 ++++ src/suite/suite.py | 13 +++++++++---- src/test/result.py | 7 +++++-- src/test/test.py | 8 ++++---- 6 files changed, 31 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/args.py b/src/args.py index 880bf6a..5536ff5 100644 --- a/src/args.py +++ b/src/args.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:32 by charles #+# #+# # -# Updated: 2020/10/08 08:13:05 by cacharle ### ########.fr # +# Updated: 2020/10/08 09:02:52 by cacharle ### ########.fr # # # # ############################################################################ # @@ -26,11 +26,11 @@ def parse_args(): help="Exit on first fail" ) parser.add_argument( - "-r", "--range", nargs=2, type=int, - help="Range of test index to run (--show-index)" + "-r", "--range", nargs=2, type=int, metavar=("BEGIN", "END"), + help="Range of test index to run (imply --show-index)" ) parser.add_argument( - "--show-index", action="store_true", + "--show-range", action="store_true", help="Show test index (useful with --range)" ) parser.add_argument( diff --git a/src/config.py b/src/config.py index 566ffe8..561cbb9 100644 --- a/src/config.py +++ b/src/config.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:19 by charles #+# #+# # -# Updated: 2020/10/07 18:21:46 by cacharle ### ########.fr # +# Updated: 2020/10/08 08:47:39 by cacharle ### ########.fr # # # # ############################################################################ # @@ -111,3 +111,7 @@ PLATFORM = os.uname().sysname EXIT_FIRST = False CHECK_LEAKS = False + +SHOW_RANGE = False + +RANGE = None diff --git a/src/main.py b/src/main.py index 1bebb89..2b70393 100755 --- a/src/main.py +++ b/src/main.py @@ -64,6 +64,10 @@ def main(): config.BONUS = False config.EXIT_FIRST = args.exit_first config.CHECK_LEAKS = args.check_leaks + config.RANGE = args.range + config.SHOW_RANGE = args.show_range + if config.RANGE is not None: + config.SHOW_RANGE = True Suite.setup(args.suites) try: diff --git a/src/suite/suite.py b/src/suite/suite.py index b5eb96c..a46234b 100644 --- a/src/suite/suite.py +++ b/src/suite/suite.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:29 by charles #+# #+# # -# Updated: 2020/10/08 08:42:50 by cacharle ### ########.fr # +# Updated: 2020/10/08 08:55:15 by cacharle ### ########.fr # # # # ############################################################################ # @@ -29,7 +29,9 @@ class Suite: @classmethod def setup(cls, asked_names: [str]): - """Remove not asked suite from available suites""" + """ Remove not asked suite from available suites + Tries to autocomplete the asked names + """ if not config.BONUS: cls.available = [s for s in cls.available if not s.bonus] if len(asked_names) == 0: @@ -126,8 +128,11 @@ class Suite: self.CLOSE_CHARS, width=config.TERM_COLS )) - for t in self.tests: - t.run() + for i, t in enumerate(self.tests): + if config.RANGE is not None: + if not (config.RANGE[0] <= i <= config.RANGE[1]): + continue + t.run(i) if config.EXIT_FIRST and t.result.failed: return False if config.VERBOSE_LEVEL == 0: diff --git a/src/test/result.py b/src/test/result.py index 30ce31e..3d16c7e 100644 --- a/src/test/result.py +++ b/src/test/result.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:17:34 by charles #+# #+# # -# Updated: 2020/10/07 18:53:27 by cacharle ### ########.fr # +# Updated: 2020/10/08 08:53:49 by cacharle ### ########.fr # # # # ############################################################################ # @@ -82,6 +82,8 @@ class Result: return self.green('.') if self.passed else self.red('!') elif config.VERBOSE_LEVEL == 1: printed = self.escaped_cmd[:] + if config.SHOW_RANGE: + printed = "{:2}: ".format(self.index) + printed if len(printed) > config.TERM_COLS - 7: printed = printed[:config.TERM_COLS - 10] + "..." fmt = self.green("{:{width}} [PASS]") if self.passed else self.red("{:{width}} [FAIL]") @@ -91,10 +93,11 @@ class Result: else: raise RuntimeError - def put(self): + def put(self, index: int): """Print a summary of the result""" if config.VERBOSE_LEVEL == 2 and self.passed: return + self.index = index print(self, end="") if config.VERBOSE_LEVEL == 0: sys.stdout.flush() diff --git a/src/test/test.py b/src/test/test.py index 52b6db3..542a9d8 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/07 18:54:13 by cacharle ### ########.fr # +# Updated: 2020/10/08 08:45:34 by cacharle ### ########.fr # # # # ############################################################################ # @@ -55,7 +55,7 @@ class Test: if type(self.hook_status) is not list: self.hook_status = [self.hook_status] - def run(self): + def run(self, index: int): """ Run the test for minishell and the reference shell and print the result out """ if config.CHECK_LEAKS: @@ -63,7 +63,7 @@ class Test: self.hook_status = [] captured = self._run_sandboxed([*config.VALGRIND_CMD, "-c"]) self.result = Result.leak(self.cmd, captured.output) - self.result.put() + self.result.put(index) return expected = self._run_sandboxed([config.REFERENCE_PATH, *config.REFERENCE_ARGS, "-c"]) @@ -75,7 +75,7 @@ class Test: 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.put() + self.result.put(index) def _run_sandboxed(self, shell_cmd: [str]) -> Captured: """ Run the command in a sandbox environment """ -- cgit