diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-10-09 11:19:58 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-10-09 11:19:58 +0200 |
| commit | 84b23010e0d0515ad3ed17a605440e50439781e8 (patch) | |
| tree | 2c71f2d4afbb7b0a8e9e128f1d1383f5637de88c /src | |
| parent | 5d1410a9b08eb8df82a43312b8b6d3d9c1c9eb00 (diff) | |
| download | minishell_test-84b23010e0d0515ad3ed17a605440e50439781e8.tar.gz minishell_test-84b23010e0d0515ad3ed17a605440e50439781e8.tar.bz2 minishell_test-84b23010e0d0515ad3ed17a605440e50439781e8.zip | |
Formatting/Refactoring, Added pretty ascii art
Diffstat (limited to 'src')
| -rw-r--r-- | src/args.py | 27 | ||||
| -rw-r--r-- | src/suite/decorator.py | 4 | ||||
| -rw-r--r-- | src/suite/suite.py | 26 | ||||
| -rw-r--r-- | src/suites/builtin.py | 4 | ||||
| -rw-r--r-- | src/suites/flow.py | 6 | ||||
| -rw-r--r-- | src/suites/path.py | 17 | ||||
| -rw-r--r-- | src/test/result.py | 21 | ||||
| -rw-r--r-- | src/test/test.py | 3 |
8 files changed, 66 insertions, 42 deletions
diff --git a/src/args.py b/src/args.py index 7d1f260..5473711 100644 --- a/src/args.py +++ b/src/args.py @@ -6,19 +6,32 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:32 by charles #+# #+# # -# Updated: 2020/10/08 16:29:25 by cacharle ### ########.fr # +# Updated: 2020/10/09 10:58:47 by cacharle ### ########.fr # # # # ############################################################################ # import argparse +import textwrap def parse_args(): """Parse command line arguments""" parser = argparse.ArgumentParser( - description="Minishell test", - epilog="Signal handling is not tested" + description=textwrap.dedent(r"""\ + ___ ____ _ _ _ _ _ _ + | \/ (_) (_) | | | | | | | | | + | . . |_ _ __ _ ___| |__ ___| | | | |_ ___ ___| |_ + | |\/| | | '_ \| / __| '_ \ / _ \ | | | __/ _ \/ __| __| + | | | | | | | | \__ \ | | | __/ | | | || __/\__ \ |_ + \_| |_/_|_| |_|_|___/_| |_|\___|_|_| \__\___||___/\__| + """), + formatter_class=argparse.RawTextHelpFormatter, + epilog=textwrap.dedent("""\ + Signal handling is not tested + There is a commented glob suite in src/suites/preprocess.py. + Good luck handling `*'.*'`. + """) ) parser.add_argument( "-k", "--check-leaks", action="store_true", @@ -62,9 +75,11 @@ def parse_args(): ) parser.add_argument( "suites", nargs='*', metavar="suite", - help="Test suites/group to run. " - "It tries to be smart and autocomplete the suite name " - "(e.g ./run int -> ./run preprocess/interpolation)" + help=textwrap.dedent("""\ + Test suites/group to run. + It tries to be smart and autocomplete the suite name + (e.g ./run int -> ./run preprocess/interpolation) + """) ) tmp = parser.parse_args() if tmp.verbose is None: diff --git a/src/suite/decorator.py b/src/suite/decorator.py index 12f58a6..45599fa 100644 --- a/src/suite/decorator.py +++ b/src/suite/decorator.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:28:00 by charles #+# #+# # -# Updated: 2020/10/08 08:34:10 by cacharle ### ########.fr # +# Updated: 2020/10/09 10:59:09 by cacharle ### ########.fr # # # # ############################################################################ # @@ -28,10 +28,8 @@ def suite(groups: [str] = [], bonus: bool = False): print("You should had a doc string to the {} suite".format(name)) description = "no description" description = description.split("\n")[0].strip() - s = Suite(name, groups + [mod_name], bonus, description) - def test_generator(): def test(*args, **kwargs): s.add(Test(*args, **kwargs)) diff --git a/src/suite/suite.py b/src/suite/suite.py index a46234b..0dfff4e 100644 --- a/src/suite/suite.py +++ b/src/suite/suite.py @@ -6,13 +6,11 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:29 by charles #+# #+# # -# Updated: 2020/10/08 08:55:15 by cacharle ### ########.fr # +# Updated: 2020/10/09 11:00:32 by cacharle ### ########.fr # # # # ############################################################################ # import sys -import tty -import termios import config @@ -44,28 +42,28 @@ class Suite: names.append(name) continue matches = [n for n in suite_names - if n.find("/") != -1 - and n[n.find("/") + 1:].startswith(name) - or n.startswith(name)] + if n.find("/") != -1 + and n[n.find("/") + 1:].startswith(name) + or n.startswith(name)] if len(matches) == 1: names.append(matches[0]) elif len(matches) != 0 and all([n.startswith(name) for n in matches]): names.extend(matches) elif len(matches) > 2: print(("Ambiguous name `{}` match the following suites\n\t{}\n" - "Try to run with -l to see the available suites") - .format(name, ', '.join(matches))) + "Try to run with -l to see the available suites") + .format(name, ', '.join(matches))) sys.exit(1) elif len(matches) == 0: print(("Name `{}` doesn't match any suite/group name\n\t" - "Try to run with -l to see the available suites") - .format(name)) + "Try to run with -l to see the available suites") + .format(name)) sys.exit(1) cls.available = list(set( [s for s in cls.available if s.name in names] + [s for s in cls.available if any([g for g in s.groups if g in names])] - )) + )) cls.available.sort(key=lambda s: s.name) for s in cls.available: s.generator_func() @@ -127,7 +125,7 @@ class Suite: " " + self.name + " ", self.CLOSE_CHARS, width=config.TERM_COLS - )) + )) for i, t in enumerate(self.tests): if config.RANGE is not None: if not (config.RANGE[0] <= i <= config.RANGE[1]): @@ -162,9 +160,9 @@ class Suite: pass_sum += pass_total fail_sum += fail_total print("{:.<{width}} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m" - .format(s.name + " ", pass_total, fail_total, width=config.TERM_COLS - 22)) + .format(s.name + " ", pass_total, fail_total, width=config.TERM_COLS - 22)) print("{:.<{width}} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m" - .format("TOTAL ", pass_sum, fail_sum, width=config.TERM_COLS - 22)) + .format("TOTAL ", pass_sum, fail_sum, width=config.TERM_COLS - 22)) @classmethod def save_log(cls): diff --git a/src/suites/builtin.py b/src/suites/builtin.py index c64a411..64d6ea6 100644 --- a/src/suites/builtin.py +++ b/src/suites/builtin.py @@ -6,7 +6,7 @@ # By: juligonz <juligonz@student.42.fr> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:43 by charles #+# #+# # -# Updated: 2020/10/09 08:34:18 by cacharle ### ########.fr # +# Updated: 2020/10/09 08:48:28 by cacharle ### ########.fr # # Updated: 2020/09/11 18:01:27 by juligonz ### ########.fr # # # # **************************************************************************** # @@ -254,6 +254,8 @@ def suite_pwd(test): test("pwd", setup="cd $HOME") test("pwd | cat -e") test("pwd", exports={"PWD": "/etc"}) + test("unset PWD; pwd; echo $PWD") + test("export PWD=foo; pwd; echo $PWD") # test("cd lnk; rmdir ../d; pwd", setup="mkdir d; ln -s d lnk") diff --git a/src/suites/flow.py b/src/suites/flow.py index a62cd9d..eb9eb30 100644 --- a/src/suites/flow.py +++ b/src/suites/flow.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:52 by charles #+# #+# # -# Updated: 2020/10/08 17:33:32 by cacharle ### ########.fr # +# Updated: 2020/10/09 08:51:57 by cacharle ### ########.fr # # # # ############################################################################ # @@ -203,6 +203,10 @@ def suite_parenthesis(test): test("( echo salut && echo bonjours ) ; echo comment ca va") test("(cd /; echo $PWD; pwd); echo $PWD; pwd") test("(export A=a; echo $A); echo $A") + test("(cat /etc/shells) | (cat -e) | (cat -e) | (cat -e)") + test("(cat /etc/shells) | (cat -e) | (cat -e) | (cat -e) | (cat -e) | (cat -e) | (cat -e) | (cat -e) | (cat -e)") + test("(cat /etc/shells | (cat -e) | (cat -e) | (cat -e)", hook=[error_line0, error_eof_to_expected_token]) + test("(cat /etc/shells) | (cat -e) | (cat -e | (cat -e)", hook=[error_line0, error_eof_to_expected_token]) @suite() diff --git a/src/suites/path.py b/src/suites/path.py index 13866de..5ac25ae 100644 --- a/src/suites/path.py +++ b/src/suites/path.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/09 15:12:58 by charles #+# #+# # -# Updated: 2020/10/08 08:41:38 by cacharle ### ########.fr # +# Updated: 2020/10/09 11:00:46 by cacharle ### ########.fr # # # # ############################################################################ # @@ -19,9 +19,9 @@ from suite import suite def suite_path(test): """ searching a command in the path tests """ whoami_path = distutils.spawn.find_executable("which") - mode_fmt = ("mkdir path && cp " + - whoami_path + - " ./path/a && chmod {} ./path/a") + mode_fmt = ("mkdir path && cp " + + whoami_path + + " ./path/a && chmod {} ./path/a") test("a", setup=mode_fmt.format("000"), exports={"PATH": "path"}) test("a", setup=mode_fmt.format("001"), exports={"PATH": "path"}) test("a", setup=mode_fmt.format("002"), exports={"PATH": "path"}) @@ -66,13 +66,13 @@ def suite_path(test): test("a", setup=mode_fmt.format("6777"), exports={"PATH": "path"}) test("a", setup=mode_fmt.format("7777"), exports={"PATH": "path"}) test("a", setup=mode_fmt.format("0000"), exports={"PATH": "path"}) - test("b", setup="mkdir path && cp " + whoami_path + " ./path/a && ln -s ./path/a ./path/b", - exports={"PATH": "path"}) + # test("b", setup="mkdir path && cp " + whoami_path + " ./path/a && ln -s ./path/a ./path/b", + # exports={"PATH": "path"}) test("b", setup="mkdir path && ln -s " + whoami_path + " ./path/b", exports={"PATH": "path"}) test("a", setup="mkdir path && mkfifo path/a") test("a", setup="mkdir path && mkfifo path/a && chmod 777 path/a") - test("a", setup="mkdir path1 path2 && cp " + whoami_path + " path1/a" - "&& cp " + whoami_path + " path2/a && chmod 000 path1/a", exports={"PATH": "path1:path2"}) + # test("a", setup="mkdir path1 path2 && cp " + whoami_path + " path1/a" + # "&& cp " + whoami_path + " path2/a && chmod 000 path1/a", exports={"PATH": "path1:path2"}) test("a", setup="mkdir path1 path2 && cp " + whoami_path + " path1/a" "&& cp " + whoami_path + " path2/a && chmod 000 path1/a", exports={"PATH": "path2:path1"}) @@ -106,6 +106,7 @@ def suite_path_variable(test): test("whoami", exports={"PATH": " /sbin "}) test("whoami", exports={"PATH": "/sbin:/sbin:/sbin:/sbin"}) test("whoami", exports={"PATH": ""}) # error message explicit enough + test("unset PATH; whoami") # error message explicit enough test("whoami", exports={"PATH": ":"}) test("whoami", exports={"PATH": ":::::::::::::::::::"}) test("whoami", exports={"PATH": "/asdfasdf"}) diff --git a/src/test/result.py b/src/test/result.py index 3d16c7e..55cda54 100644 --- a/src/test/result.py +++ b/src/test/result.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:17:34 by charles #+# #+# # -# Updated: 2020/10/08 08:53:49 by cacharle ### ########.fr # +# Updated: 2020/10/09 11:04:16 by cacharle ### ########.fr # # # # ############################################################################ # @@ -51,18 +51,25 @@ class Result: def leak(cmd: str, leak_output: str = None): return Result(cmd, None, None, None, leak_output) - @property - def lost_bytes(self): - m = re.search( - r"definitely lost: (?P<bytes>[0-9,]+) bytes in [0-9,]+ blocks", + def _search_leak_kind(self, kind: str) -> int: + match = re.search( + r"==\d+==\s+" + kind + r" lost: (?P<bytes>[0-9,]+) bytes in [0-9,]+ blocks", self.leak_output ) - if m is None: + if match is None: raise RuntimeError( "valgrind output parsing failed for `{}`:\n{}" .format(self.cmd, self.leak_output) ) - return int(m.group("bytes")) + return match + + @property + def lost_bytes(self): + definite_match = self._search_leak_kind("definitely") + indirect_match = self._search_leak_kind("indirectly") + definite_bytes = int(definite_match.group("bytes").replace(",", "")) + indirect_bytes = int(indirect_match.group("bytes").replace(",", "")) + return definite_bytes + indirect_bytes @property def passed(self): diff --git a/src/test/test.py b/src/test/test.py index 6668573..b487f10 100644 --- a/src/test/test.py +++ b/src/test/test.py @@ -6,14 +6,13 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/06/16 21:48:50 by charles #+# #+# # -# Updated: 2020/10/08 10:05:39 by cacharle ### ########.fr # +# Updated: 2020/10/09 11:00:57 by cacharle ### ########.fr # # # # ############################################################################ # import os import sys import subprocess -#import time import config from test.captured import Captured |
