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 --- README.md | 37 +++++++++++++++++++++---------------- 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 ++++---- 7 files changed, 52 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 27b3644..7bbc73c 100644 --- a/README.md +++ b/README.md @@ -11,28 +11,33 @@ The default path to your project is `..` but you can change it the the [configur ```sh $ ./run # run all tests -$❯ ./run -h -usage: run [-h] [-k] [-x] [-v] [-b] [-n] [-l] [-m] [-p] [suite [suite ...]] +$ ./run --help +usage: run [-h] [-k] [-x] [-r BEGIN END] [--show-range] [-v] [-b] [-n] [-l] + [-m] [-p] + [suite [suite ...]] Minishell test positional arguments: - suite Test suites/group to run. It tries to be smart and - autocomplete the suite name (e.g ./run int -> ./run - preprocess/interpolation) + suite Test suites/group to run. It tries to be smart and + autocomplete the suite name (e.g ./run int -> ./run + preprocess/interpolation) optional arguments: - -h, --help show this help message and exit - -k, --check-leaks Run valgrind on tests (disable usual comparison with - bash) - -x, --exit-first Exit on first fail - -v, --verbose Increase verbosity level (e.g -vv == 2) - -b, --bonus Enable bonus tests - -n, --no-bonus Disable bonus tests - -l, --list Print available test suites - -m, --make Make minishell and exit - -p, --pager After running the test, display the result in a pager of - your choice ./run --help + -h, --help show this help message and exit + -k, --check-leaks Run valgrind on tests (disable usual comparison with + bash) + -x, --exit-first Exit on first fail + -r BEGIN END, --range BEGIN END + Range of test index to run (imply --show-index) + --show-range Show test index (useful with --range) + -v, --verbose Increase verbosity level (e.g -vv == 2) + -b, --bonus Enable bonus tests + -n, --no-bonus Disable bonus tests + -l, --list Print available test suites + -m, --make Make minishell and exit + -p, --pager After running the test, display the result in a pager + of your choice ``` ## Test compatibility 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