diff options
| -rwxr-xr-x | minishell_test/__main__.py | 38 | ||||
| -rw-r--r-- | minishell_test/args.py | 7 | ||||
| -rw-r--r-- | minishell_test/suite/decorator.py | 52 | ||||
| -rw-r--r-- | minishell_test/suite/suite.py | 236 | ||||
| -rw-r--r-- | minishell_test/suites/builtin.py | 66 | ||||
| -rw-r--r-- | minishell_test/suites/cmd.py | 24 | ||||
| -rw-r--r-- | minishell_test/suites/flow.py | 200 | ||||
| -rw-r--r-- | minishell_test/suites/preprocess.py | 18 | ||||
| -rw-r--r-- | tests/conftest.py | 11 | ||||
| -rw-r--r-- | tests/suite/test_decorator.py | 0 | ||||
| -rw-r--r-- | tests/suite/test_suite.py | 121 | ||||
| -rw-r--r-- | tests/test/test_result.py | 6 | ||||
| -rw-r--r-- | tests/test/test_test.py | 10 | ||||
| -rw-r--r-- | tests/test_config.py | 5 | ||||
| -rw-r--r-- | tests/test_hooks.py | 5 | ||||
| -rw-r--r-- | tests/test_sandbox.py | 4 |
16 files changed, 453 insertions, 350 deletions
diff --git a/minishell_test/__main__.py b/minishell_test/__main__.py index 4ebaec3..727e167 100755 --- a/minishell_test/__main__.py +++ b/minishell_test/__main__.py @@ -22,8 +22,8 @@ from minishell_test.config import Config from minishell_test import sandbox from minishell_test.args import parse_args from minishell_test.suite.suite import Suite, SuiteException -from minishell_test.suites import * # noqa: F403,F401 from minishell_test.test import Test +from minishell_test.suites import * # noqa: F403,F401 def main(argv=None): @@ -31,11 +31,11 @@ def main(argv=None): Config.init(args) if args.list: - Suite.list() + print(Suite.list(), end="") sys.exit(0) # running ``make`` in minishell directory - if Config.make or args.make: + if Config.make: print("{:=^{width}}".format("MAKE", width=Config.term_cols)) try: subprocess.run( @@ -46,8 +46,6 @@ def main(argv=None): except subprocess.CalledProcessError: sys.exit(1) print("=" * Config.term_cols) - if args.make: - sys.exit(0) # setup available commands if not Config.shell_available_commands_dir.exists(): @@ -67,28 +65,26 @@ def main(argv=None): sys.exit(0) try: - Suite.setup(args.suites) - except SuiteException as e: - print(e) - sys.exit(1) - - try: - Suite.run_all() + Suite.run(args.suites) except KeyboardInterrupt: pass finally: sandbox.remove() - 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" - " ({} -h for more details)".format(sys.argv[0])) + Suite.save() + + # 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" + # " ({} -h for more details)".format(sys.argv[0])) - if Config.pager: - # TODO {} replaced by filename in pager config var - subprocess.run([Config.pager_prog, Config.log_path]) + # if Config.pager: + # # TODO {} replaced by filename in pager config var + # subprocess.run([Config.pager_prog, Config.log_path]) if __name__ == "__main__": diff --git a/minishell_test/args.py b/minishell_test/args.py index 6ffb242..76f3a9c 100644 --- a/minishell_test/args.py +++ b/minishell_test/args.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:32 by charles #+# #+# # -# Updated: 2021/02/28 09:06:53 by cacharle ### ########.fr # +# Updated: 2021/03/06 10:47:07 by cacharle ### ########.fr # # # # ############################################################################ # @@ -64,11 +64,6 @@ def parse_args(argv): help="Exit on first fail" ) parser.add_argument( - "-m", "--make", - action="store_true", - help="Make minishell and exit" - ) - parser.add_argument( "-g", "--pager", action="store_true", help="After running the test, display the result in a pager of your choice" diff --git a/minishell_test/suite/decorator.py b/minishell_test/suite/decorator.py index 45f96b6..7cfd29c 100644 --- a/minishell_test/suite/decorator.py +++ b/minishell_test/suite/decorator.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:28:00 by charles #+# #+# # -# Updated: 2021/02/05 17:44:25 by charles ### ########.fr # +# Updated: 2021/03/06 11:31:33 by cacharle ### ########.fr # # # # ############################################################################ # @@ -17,31 +17,49 @@ from minishell_test.suite import Suite from minishell_test.test import Test -def suite(groups: List[str] = [], bonus: bool = False): # type: ignore +class SuiteRegistrationException(Exception): + def __init__(self, function_name: str, message: str): + self._function_name = function_name + self._message = message + + def __str__(self) -> str: + return "Error during the registration of {self._function_name} as a suite: {self._message}" + + +_SUITE_FUNCTION_PREFIX = "suite_" + + +def suite(bonus: bool = False): # type: ignore """Decorator generator for suites arguments""" def suite_wrapper(origin): """Decorator for a suite function (fmt: suite_[name]) """ - mod = inspect.getmodule(origin) - if mod is None: - raise NotImplementedError - mod_name = mod.__name__[len("minishell_test.suites."):] - name = "{}/{}".format(mod_name, origin.__name__[len("suite_"):]) + # get the function name + function_name = origin.__name__ + if not function_name.startswith(_SUITE_FUNCTION_PREFIX): + raise SuiteRegistrationException(function_name, f"Function need to start with {_SUITE_FUNCTION_PREFIX}") + function_name = function_name[len(_SUITE_FUNCTION_PREFIX):] + # get the module name + module = inspect.getmodule(origin) + if module is None: + raise SuiteRegistrationException(function_name, "Could not get function module") + module_name = module.__name__[len("minishell_test.suites."):] + # get the first line of the function docstring as the suite description description = origin.__doc__ if description is None: - print("You should had a doc string to the {} suite".format(name)) + warnings.warn(f"You should had a doc string to the {name} suite") description = "no description" - description = description.split("\n")[0].strip() - s = Suite(name, groups + [mod_name], bonus, description) + description = description.splitlines()[0].strip() - def test_generator(): - def test(*args, **kwargs): - s.add(Test(*args, **kwargs)) - origin(test) + suite = Suite(origin, function_name, module_name, bonus, description) + Suite._available.append(suite) - s.generator_func = test_generator - Suite.available.append(s) - return test_generator + # def test_generator(): + # def test(*args, **kwargs): + # suite.append_test(Test(*args, **kwargs)) + # origin(test) + # suite.generator_func = test_generator + return origin return suite_wrapper diff --git a/minishell_test/suite/suite.py b/minishell_test/suite/suite.py index 2a87fbc..842a876 100644 --- a/minishell_test/suite/suite.py +++ b/minishell_test/suite/suite.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:29 by charles #+# #+# # -# Updated: 2021/03/02 13:17:31 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:57:52 by cacharle ### ########.fr # # # # ############################################################################ # @@ -14,6 +14,7 @@ from typing import List, Tuple, Optional, Callable from minishell_test.config import Config from minishell_test.test import Test +from minishell_test import colors class SuiteException(Exception): @@ -21,173 +22,156 @@ class SuiteException(Exception): pass -class AmbiguousNameException(SuiteException): - def __init__(self, name: str, matches: List[str]): - self.name = name - self.matches = matches +class SuiteExitFirstException(SuiteException): + pass - def __str__(self) -> str: - return (("Ambiguous name `{}` match the following suites\n\t{}\n" - "Try to run with -l to see the available suites") - .format(self.name, ', '.join(self.matches))) + +# class AmbiguousNameException(SuiteException): +# def __init__(self, name: str, matches: List[str]): +# self._name = name +# self._matches = matches +# +# def __str__(self) -> str: +# return (f"Ambiguous name `{self._name}` match the following suites" +# f"\n\t{', '.join(self._matches)}\n" +# "See the --list option to list the _available test suites") class NoMatchException(SuiteException): def __init__(self, name: str): - self.name = name + self._name = name def __str__(self) -> str: - return (("Name `{}` doesn't match any suite/group name\n\t" + return (f"Name `{self._name}` doesn't match any suite/group name\n\t" "Try to run with -l to see the available suites") - .format(self.name)) class Suite: - available: List['Suite'] = [] + _available: List['Suite'] = [] @classmethod - def run_all(cls): - """Run all available suites""" - for s in cls.available: - if not s.run() and Config.exit_first: - break + def run(cls, asked_names: List[str]) -> None: + """Run all _available suites""" - @classmethod - def setup(cls, asked_names: List[str]) -> None: - """ Remove not asked suite from available suites + """ Remove not asked suite from _available suites Tries to autocomplete the asked names """ + + asked_suites = cls._asked_suites(asked_names) + for suite in asked_suites: + suite._register() + for suite in asked_suites: + try: + suite._run() + except SuiteExitFirstException: + break + + @classmethod + def _asked_suites(cls, asked_names: [str]) -> ['Suite']: + suites = cls._available if not Config.bonus: - cls.available = [s for s in cls.available if not s.bonus] + suites = [suite for suite in cls._available if not suite._bonus] if len(asked_names) == 0: - asked_names = [s.name for s in cls.available] + asked_names = [suite._name for suite in suites] - suite_names = [s.name for s in cls.available] names = [] - for i, name in enumerate(asked_names): - if name in suite_names: - 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 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: - raise AmbiguousNameException(name, matches) - elif len(matches) == 0: + for name in asked_names: + matches = [suite._name for suite in suites if suite._name.startswith(name) or suite._group.startswith(name)] + if len(matches) == 0: raise NoMatchException(name) + names.extend(matches) - 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)] + suites = list(set( + [suite for suite in suites if suite._name in names] + + [suite for suite in suites if suite._group in names] )) - cls.available.sort(key=lambda s: s.name) - for s in cls.available: - if s.generator_func is not None: - s.generator_func() + return sorted(suites, key=lambda suite: suite._name) @classmethod - def available_names(cls) -> List[str]: - """List of available suites names""" - return [s.name for s in cls.available] - - @classmethod - def list(cls): - print("Groups:") - print("\n".join({" - " + ', '.join(s.groups) for s in Suite.available})) - print("The available suites are:") - max_name_width = max(len(s.name) for s in Suite.available) + 5 - lines = [ - " - {:.<{max_name_width}} {}".format( - s.name + " ", - s.description, - max_name_width=max_name_width - ) - for s in Suite.available - ] - print("\n".join(lines)) + def list(cls) -> str: + max_name_width = max(len(suite._name + suite._group) for suite in cls._available) + 5 + out = "" + for suite in cls._available: + prefixed_name = f"{suite._group}/{suite._name} " + out += f"{prefixed_name:.<{max_name_width}} {suite._description}\n" + return out def __init__( self, - name: str, - groups: List[str], - bonus: bool = False, - description: str = "no description", + origin, + name: str, + group: str, + bonus: bool = False, + description: str = "no description", ): """Suite class name: suite id groups: list of suite groups bonus: is this suite bonus """ - self.name = name - self.groups = groups - self.description = description - self.bonus = bonus - self.generator_func: Optional[Callable] = None - self.tests: List[Test] = [] - self.results: List[Result] = [] - - def add(self, test): - """Append a test to the suite""" - self.tests.append(test) - - BLUE_CHARS = "\033[34m" - CLOSE_CHARS = "\033[0m" - - def run(self) -> bool: + self._name = name + self._group = group + self._description = description + self._bonus = bonus + self._origin = origin + self._tests: List[Test] = [] + self._results: List[Result] = [] + + def _run(self) -> None: """Run all test in the suite""" - print("{}{:#^{width}}{}".format( - self.BLUE_CHARS, - " " + self.name + " ", - self.CLOSE_CHARS, - width=Config.term_cols - )) + + title = ' ' + self._name + ' ' + print(colors.blue(f"{title:#^{Config.term_cols}}")) if Config.range is not None: - self.tests = self.test[Config.range[0] : Config.range[1] + 1] - for i, test in enumerate(self.tests): + self._tests = self._tests[Config.range[0] : Config.range[1] + 1] + for i, test in enumerate(self._tests): result = test.run() - self.results.append(result) - print(result.to_string(i)) - if Config.exit_first and result is not None and result.failed: - return False - return True - - def total(self) -> Tuple[int, int]: - """Returns the total of passed and failed tests""" - passed_total = 0 - for result in self.results: - if result is None: - return (-1, -1) - if result.passed: - passed_total += 1 - return passed_total, len(self.tests) - passed_total + self._results.append(result) + print(result.summarize(i)) + if Config.exit_first and result.failed: + raise SuiteExitFirstException() + + def _register(self) -> None: + def test(*args, **kwargs): + self._tests.append(Test(*args, **kwargs)) + self._origin(test) @classmethod def summarize(cls): """Print a summary of all runned suites""" - pass_sum = 0 - fail_sum = 0 - print("\nSummary:") - for s in cls.available: - (pass_total, fail_total) = s.total() - if pass_total == -1: - continue - pass_sum += pass_total - fail_sum += fail_total - print("{:.<{width}} \033[32m{:4} [PASS]\033[0m \033[31m{:4} [FAIL]\033[0m" - .format(s.name + " ", pass_total, fail_total, width=Config.term_cols - 24)) - print("{:.<{width}} \033[32m{:4} [PASS]\033[0m \033[31m{:4} [FAIL]\033[0m" - .format("TOTAL ", pass_sum, fail_sum, width=Config.term_cols - 24)) + full_pass_count = sum(suite._pass_count for suite in suites) + full_fail_count = sum(suite._fail_count for suite in suites) + lines = ["Summary:"] + for suite in cls._available: + lines.append(Suite._stat_summary(suite._name, suite._pass_count, suite._fail_count)) + lines.append(Suite._stat_summary("TOTAL", full_pass_count, full_fail_count)) + return "\n".join(lines) + "\n" + + @property + def _pass_count(self) -> int: + count = 0 + for result in self._results: + if result.passed: + count += 1 + return count + + @property + def _fail_count(self) -> int: + return len(self._results) - self._pass_count + + @staticmethod + def _stat_summary(self, name: str, pass_count: int, fail_count: int) -> str: + prefix = f"{name + ' ':.<{Config.term_cols - 24}}" + pass_str = colors.green("{pass_count:4} [PASS]") + fail_str = colors.red("{fail_count:4} [FAIL]") + return f"{prefix} {pass_str} {fail_str}" @classmethod - def save_log(cls): + def save(cls): """Save the result of all suites to a file""" colors.disable() - with open(Config.log_path, "w") as log_file: - for result in self.results: - if result is not None and result.failed: - log_file.write(result.full_diff() + '\n') + with open(Config.log_path, "w") as file: + for suite in suites: + for result in suite._results: + if result.failed: + file.write(result) diff --git a/minishell_test/suites/builtin.py b/minishell_test/suites/builtin.py index 8310ce4..515fbbc 100644 --- a/minishell_test/suites/builtin.py +++ b/minishell_test/suites/builtin.py @@ -324,10 +324,10 @@ def suite_exit(test): test("exit '\t\f\r 3'") test("exit '3 '") test("exit '3\t'") - test("exit '3\r'", hook_status=hooks.platform_status(255, 2)) - test("exit '3\t\f\r '", hook_status=hooks.platform_status(255, 2)) - test("exit '3 a'", hook_status=hooks.platform_status(255, 2)) - test("exit '3\t\t\ta'", hook_status=hooks.platform_status(255, 2)) + test("exit '3\r'", hooks_status=hooks.platform_status(255, 2)) + test("exit '3\t\f\r '", hooks_status=hooks.platform_status(255, 2)) + test("exit '3 a'", hooks_status=hooks.platform_status(255, 2)) + test("exit '3\t\t\ta'", hooks_status=hooks.platform_status(255, 2)) test("exit 0") test("exit -0") test("exit -1") @@ -345,10 +345,10 @@ def suite_exit(test): test("exit 4294967296") test("exit -9223372036854775808") test("exit 9223372036854775807") - test("exit -9223372036854775809", hook_status=hooks.platform_status(255, 2)) - test("exit 9223372036854775808", hook_status=hooks.platform_status(255, 2)) - test("exit 18446744073709551615", hook_status=hooks.platform_status(255, 2)) - test("exit 18446744073709551616", hook_status=hooks.platform_status(255, 2)) + test("exit -9223372036854775809", hooks_status=hooks.platform_status(255, 2)) + test("exit 9223372036854775808", hooks_status=hooks.platform_status(255, 2)) + test("exit 18446744073709551615", hooks_status=hooks.platform_status(255, 2)) + test("exit 18446744073709551616", hooks_status=hooks.platform_status(255, 2)) test("exit +1") test("exit +2") test("exit +3") @@ -357,25 +357,25 @@ def suite_exit(test): test("exit +256") test("exit +2000000") test("exit +2147483647") - test("exit ++1", hook_status=hooks.platform_status(255, 2)) - test("exit ++2", hook_status=hooks.platform_status(255, 2)) - test("exit ++3", hook_status=hooks.platform_status(255, 2)) - test("exit ++0", hook_status=hooks.platform_status(255, 2)) - test("exit ++255", hook_status=hooks.platform_status(255, 2)) - test("exit ++256", hook_status=hooks.platform_status(255, 2)) - test("exit ++2000000", hook_status=hooks.platform_status(255, 2)) - test("exit ++2147483647", hook_status=hooks.platform_status(255, 2)) - test("exit --1", hook_status=hooks.platform_status(255, 2)) - test("exit --2", hook_status=hooks.platform_status(255, 2)) - test("exit --3", hook_status=hooks.platform_status(255, 2)) - test("exit --0", hook_status=hooks.platform_status(255, 2)) - test("exit --255", hook_status=hooks.platform_status(255, 2)) - test("exit --256", hook_status=hooks.platform_status(255, 2)) - test("exit --2000000", hook_status=hooks.platform_status(255, 2)) - test("exit --2147483647", hook_status=hooks.platform_status(255, 2)) - test("exit bonjour", hook_status=hooks.platform_status(255, 2)) - test("exit 0_", hook_status=hooks.platform_status(255, 2)) - test("exit _0", hook_status=hooks.platform_status(255, 2)) + test("exit ++1", hooks_status=hooks.platform_status(255, 2)) + test("exit ++2", hooks_status=hooks.platform_status(255, 2)) + test("exit ++3", hooks_status=hooks.platform_status(255, 2)) + test("exit ++0", hooks_status=hooks.platform_status(255, 2)) + test("exit ++255", hooks_status=hooks.platform_status(255, 2)) + test("exit ++256", hooks_status=hooks.platform_status(255, 2)) + test("exit ++2000000", hooks_status=hooks.platform_status(255, 2)) + test("exit ++2147483647", hooks_status=hooks.platform_status(255, 2)) + test("exit --1", hooks_status=hooks.platform_status(255, 2)) + test("exit --2", hooks_status=hooks.platform_status(255, 2)) + test("exit --3", hooks_status=hooks.platform_status(255, 2)) + test("exit --0", hooks_status=hooks.platform_status(255, 2)) + test("exit --255", hooks_status=hooks.platform_status(255, 2)) + test("exit --256", hooks_status=hooks.platform_status(255, 2)) + test("exit --2000000", hooks_status=hooks.platform_status(255, 2)) + test("exit --2147483647", hooks_status=hooks.platform_status(255, 2)) + test("exit bonjour", hooks_status=hooks.platform_status(255, 2)) + test("exit 0_", hooks_status=hooks.platform_status(255, 2)) + test("exit _0", hooks_status=hooks.platform_status(255, 2)) test("exit 0123456789") test("exit -0123456789") test("exit 00000000000000000000000000000000000000000000001") @@ -386,16 +386,16 @@ def suite_exit(test): test("exit -00000000000000000000000000000000000000000000000" "00000000000000000000000000000000000000000000001") test("exit -99999999999999999999999999999999999999999999" - "99999999999999999999999999999999999999999999", hook_status=hooks.platform_status(255, 2)) + "99999999999999999999999999999999999999999999", hooks_status=hooks.platform_status(255, 2)) test("exit 99999999999999999999999999999999999999999999" - "99999999999999999999999999999999999999999999", hook_status=hooks.platform_status(255, 2)) + "99999999999999999999999999999999999999999999", hooks_status=hooks.platform_status(255, 2)) test("exit 0 bonjour") - test("exit bonjour 0", hook_status=hooks.platform_status(255, 2)) + test("exit bonjour 0", hooks_status=hooks.platform_status(255, 2)) test("exit 0 1") test("exit 0 1 2 3 4 5 6 7 8 9") - test("exit " + Config.lorem, hook_status=hooks.platform_status(255, 2)) - test("exit bonjoru; echo should have exited", hook_status=hooks.platform_status(255, 2)) - test("exit 99999999999999999999999999999999999999999999999999999; echo should have exited", hook_status=hooks.platform_status(255, 2)) + test("exit " + Config.lorem, hooks_status=hooks.platform_status(255, 2)) + test("exit bonjoru; echo should have exited", hooks_status=hooks.platform_status(255, 2)) + test("exit 99999999999999999999999999999999999999999999999999999; echo should have exited", hooks_status=hooks.platform_status(255, 2)) test("exit 9999; echo should have exited") test("Exit; echo a") test("exiT; echo a") diff --git a/minishell_test/suites/cmd.py b/minishell_test/suites/cmd.py index a4c4e88..ede205f 100644 --- a/minishell_test/suites/cmd.py +++ b/minishell_test/suites/cmd.py @@ -68,21 +68,21 @@ def suite_redirection(test): files=["abcdefghijklmnopqrstuvwxyz"]) test("> file", files=["file"]) test("< file", setup="echo bonjour > file") - test(">", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test(">>", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test("<", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test("echo >", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test("echo >>", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test("echo <", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) + test(">", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test(">>", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test("<", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test("echo >", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test("echo >>", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test("echo <", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) test("> test", files=["test"]) test(">> test", files=["test"]) test("< test", setup="touch test") - test("echo foo >>> bar", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test("echo foo >>>> bar", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test("echo foo >>>>> bar", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test("cat << < bar", setup="echo bonjour > bar", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test("cat << << bar", setup="echo bonjour > bar", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) - test("cat <<<<< bar", setup="echo bonjour > bar", hooks=hooks.error_line0, hook_status=hooks.platform_status(1, 2)) + test("echo foo >>> bar", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test("echo foo >>>> bar", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test("echo foo >>>>> bar", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test("cat << < bar", setup="echo bonjour > bar", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test("cat << << bar", setup="echo bonjour > bar", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) + test("cat <<<<< bar", setup="echo bonjour > bar", hooks=hooks.error_line0, hooks_status=hooks.platform_status(1, 2)) test("cat < doesnotexist") test("echo bonjour >> a", setup="echo a > a", files=["a"]) test("echo bonjour >> a >> a", setup="echo a > a", files=["a"]) diff --git a/minishell_test/suites/flow.py b/minishell_test/suites/flow.py index 67cd1b1..089f5d3 100644 --- a/minishell_test/suites/flow.py +++ b/minishell_test/suites/flow.py @@ -31,9 +31,9 @@ def suite_end(test): test("echo; ") test("echo ; ") test("echo ;") - test("; echo", hooks=error_line0, hook_status=platform_status(2, 1)) - test(" ;echo", hooks=error_line0, hook_status=platform_status(2, 1)) - test(" ; echo", hooks=error_line0, hook_status=platform_status(2, 1)) + test("; echo", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(" ;echo", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(" ; echo", hooks=error_line0, hooks_status=platform_status(2, 1)) test("echo a; echo b; echo c; echo d; echo e; echo f; echo g; echo h; echo i;" "echo j; echo k; echo l; echo m; echo c; echo c; echo c; echo c; echo c;" "echo c; echo c; echo c; echo v; echo w; echo x; echo y; echo z") @@ -43,17 +43,17 @@ def suite_end(test): test("ls doesnotexists ; echo bonjour") test("ls doesnotexists; echo bonjour") test("echo bonjour; ls doesnotexists") - test("echo a ; ;", hooks=error_line0, hook_status=platform_status(2, 1)) - test("echo a ; ;", hooks=error_line0, hook_status=platform_status(2, 1)) - test(";", hooks=error_line0, hook_status=platform_status(2, 1)) - test("; ;", hooks=error_line0, hook_status=platform_status(2, 1)) - test("; ; ;", hooks=error_line0, hook_status=platform_status(2, 1)) - test("echo a ; ; echo b", hooks=error_line0, hook_status=platform_status(2, 1)) - test(";;", hooks=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) - test(";;;", hooks=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) - test(";;;;;", hooks=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) - test("echo a ;; echo b", hooks=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) - test("echo a ;;;;; echo b", hooks=[error_line0, replace_double(";")], hook_status=platform_status(2, 1)) + test("echo a ; ;", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("echo a ; ;", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(";", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("; ;", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("; ; ;", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("echo a ; ; echo b", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(";;", hooks=[error_line0, replace_double(";")], hooks_status=platform_status(2, 1)) + test(";;;", hooks=[error_line0, replace_double(";")], hooks_status=platform_status(2, 1)) + test(";;;;;", hooks=[error_line0, replace_double(";")], hooks_status=platform_status(2, 1)) + test("echo a ;; echo b", hooks=[error_line0, replace_double(";")], hooks_status=platform_status(2, 1)) + test("echo a ;;;;; echo b", hooks=[error_line0, replace_double(";")], hooks_status=platform_status(2, 1)) test("ls " + 40 * " ; ls", setup="touch a b c") test("ls " + 80 * " ; ls", setup="touch a b c") test("ls " + 40 * " ; ls" + ";", setup="touch a b c") @@ -78,18 +78,18 @@ def suite_pipe(test): test("ls -l | cat -e | cat | cat | cat", setup="touch a b c d; mkdir m1 m2 m3") test("ls -l | cat -e | cat -e | cat -e | cat -e", setup="touch a b c d; mkdir m1 m2 m3") test("ls -l | cat -e < a", setup="touch a b c d; mkdir m1 m2 m3; echo bonjour > a") - test("echo|", hooks=discard, hook_status=platform_status(2, 1)) - test("echo |", hooks=discard, hook_status=platform_status(2, 1)) - test("echo | ", hooks=discard, hook_status=platform_status(2, 1)) - test("|cat", hooks=error_line0, hook_status=platform_status(2, 1)) - test("| cat", hooks=error_line0, hook_status=platform_status(2, 1)) - test(" | cat", hooks=error_line0, hook_status=platform_status(2, 1)) + test("echo|", hooks=discard, hooks_status=platform_status(2, 1)) + test("echo |", hooks=discard, hooks_status=platform_status(2, 1)) + test("echo | ", hooks=discard, hooks_status=platform_status(2, 1)) + test("|cat", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("| cat", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(" | cat", hooks=error_line0, hooks_status=platform_status(2, 1)) test("echo a | export A=a; echo $A") test("export A=a | cat; echo $A") - test("echo bonjour | | cat -e", hooks=error_line0, hook_status=platform_status(2, 1)) + test("echo bonjour | | cat -e", hooks=error_line0, hooks_status=platform_status(2, 1)) test("echo bonjour | asdf") test("asdf | echo bonjour") - test("echo a ||| echo b", hooks=error_line0, hook_status=platform_status(2, 1)) + test("echo a ||| echo b", hooks=error_line0, hooks_status=platform_status(2, 1)) test("ls " + 40 * " | ls", setup="touch a b c") test("ls " + 80 * " | ls", setup="touch a b c") test("echo bonjour " + 40 * " | cat -e") @@ -110,13 +110,13 @@ def suite_and(test): test("echo bonjour&& echo je") test("echo bonjour &&echo je") test("echo bonjour && echo je") - test("echo bonjour&&", hooks=discard, hook_status=platform_status(2, 1)) - test("echo&& ", hooks=discard, hook_status=platform_status(2, 1)) - test("echo && ", hooks=discard, hook_status=platform_status(2, 1)) - test("echo &&", hooks=discard, hook_status=platform_status(2, 1)) - test("&&echo", hooks=error_line0, hook_status=platform_status(2, 1)) - test("&& echo", hooks=error_line0, hook_status=platform_status(2, 1)) - test(" && echo", hooks=error_line0, hook_status=platform_status(2, 1)) + test("echo bonjour&&", hooks=discard, hooks_status=platform_status(2, 1)) + test("echo&& ", hooks=discard, hooks_status=platform_status(2, 1)) + test("echo && ", hooks=discard, hooks_status=platform_status(2, 1)) + test("echo &&", hooks=discard, hooks_status=platform_status(2, 1)) + test("&&echo", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("&& echo", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(" && echo", hooks=error_line0, hooks_status=platform_status(2, 1)) test("echo a&& echo b&& echo c&& echo d&& echo e&& echo f&& echo g&& echo h&& echo i&&" "echo j&& echo k&& echo l&& echo m&& echo c&& echo c&& echo c&& echo c&& echo c&&" "echo c&& echo c&& echo c&& echo v&& echo w&& echo x&& echo y&& echo z") @@ -136,13 +136,13 @@ def suite_or(test): test("echo bonjour|| echo je") test("echo bonjour ||echo je") test("echo bonjour || echo je") - test("echo bonjour||", hooks=discard, hook_status=platform_status(2, 1)) - test("echo|| ", hooks=discard, hook_status=platform_status(2, 1)) - test("echo || ", hooks=discard, hook_status=platform_status(2, 1)) - test("echo ||", hooks=discard, hook_status=platform_status(2, 1)) - test("||echo", hooks=error_line0, hook_status=platform_status(2, 1)) - test("|| echo", hooks=error_line0, hook_status=platform_status(2, 1)) - test(" || echo", hooks=error_line0, hook_status=platform_status(2, 1)) + test("echo bonjour||", hooks=discard, hooks_status=platform_status(2, 1)) + test("echo|| ", hooks=discard, hooks_status=platform_status(2, 1)) + test("echo || ", hooks=discard, hooks_status=platform_status(2, 1)) + test("echo ||", hooks=discard, hooks_status=platform_status(2, 1)) + test("||echo", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("|| echo", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(" || echo", hooks=error_line0, hooks_status=platform_status(2, 1)) test("echo a|| echo b|| echo c|| echo d|| echo e|| echo f|| echo g|| echo h|| echo i||" "echo j|| echo k|| echo l|| echo m|| echo c|| echo c|| echo c|| echo c|| echo c||" "echo c|| echo c|| echo c|| echo v|| echo w|| echo x|| echo y|| echo z") @@ -216,81 +216,81 @@ def suite_parenthesis(test): 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)", - hooks=[error_line0, error_eof_to_expected_token], hook_status=platform_status(2, 1)) + hooks=[error_line0, error_eof_to_expected_token], hooks_status=platform_status(2, 1)) test("(cat /etc/shells) | (cat -e) | (cat -e | (cat -e)", - hooks=[error_line0, error_eof_to_expected_token], hook_status=platform_status(2, 1)) + hooks=[error_line0, error_eof_to_expected_token], hooks_status=platform_status(2, 1)) @suite() def suite_syntax_error(test): """ separator syntax error test """ - test("< | a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("> | a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(">> | a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("< ; a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("> ; a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(">> ; a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("; | a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("; < a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("; > a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("; >> a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("| ; a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("| < a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("| > a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("| >> a", hooks=error_line0, hook_status=platform_status(2, 1)) + test("< | a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("> | a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(">> | a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("< ; a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("> ; a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(">> ; a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("; | a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("; < a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("; > a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("; >> a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("| ; a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("| < a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("| > a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("| >> a", hooks=error_line0, hooks_status=platform_status(2, 1)) test("> a ; a", hooks=error_line0) test("< a ; a", hooks=error_line0) test(">> a ; a", hooks=error_line0) - test(Config.lorem + " > >" + Config.lorem, hooks=error_line0, hook_status=platform_status(2, 1)) - test(Config.lorem + " < <" + Config.lorem, hooks=error_line0, hook_status=platform_status(2, 1)) - test(Config.lorem + " ; |" + Config.lorem, hooks=error_line0, hook_status=platform_status(2, 1)) - test(Config.lorem + " | ;" + Config.lorem, hooks=error_line0, hook_status=platform_status(2, 1)) + test(Config.lorem + " > >" + Config.lorem, hooks=error_line0, hooks_status=platform_status(2, 1)) + test(Config.lorem + " < <" + Config.lorem, hooks=error_line0, hooks_status=platform_status(2, 1)) + test(Config.lorem + " ; |" + Config.lorem, hooks=error_line0, hooks_status=platform_status(2, 1)) + test(Config.lorem + " | ;" + Config.lorem, hooks=error_line0, hooks_status=platform_status(2, 1)) @suite(bonus=True) def suite_syntax_error_bonus(test): """ separator syntax error bonus test """ - test("< && a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("> && a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(">> && a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("< || a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("> || a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(">> || a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("< ( a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("> ( a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(">> ( a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("< ) a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("> ) a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(">> ) a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("&& < a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("&& > a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("&& >> a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("&& || a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("&& ( a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("&& ) a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("|| < a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("|| > a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("|| >> a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("|| && a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("|| ( a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("|| ) a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("( < a", hooks=[error_line0, error_eof_to_expected_token], hook_status=platform_status(2, 1)) - test("( > a", hooks=[error_line0, error_eof_to_expected_token], hook_status=platform_status(2, 1)) - test("( >> a", hooks=[error_line0, error_eof_to_expected_token], hook_status=platform_status(2, 1)) - test(") < a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(") > a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(") >> a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("( && a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("( || a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("( ) a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(") && a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(") || a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(") ( a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("() a", hooks=error_line0, hook_status=platform_status(2, 1)) - test("( a", hooks=[error_line0, error_eof_to_expected_token], hook_status=platform_status(2, 1)) - test(") a", hooks=error_line0, hook_status=platform_status(2, 1)) - test(Config.lorem + " && &&" + Config.lorem, hooks=error_line0, hook_status=platform_status(2, 1)) - test(Config.lorem + " || ||" + Config.lorem, hooks=error_line0, hook_status=platform_status(2, 1)) - test(Config.lorem + " ( (" + Config.lorem, hooks=error_line0, hook_status=platform_status(2, 1)) - test(Config.lorem + " ) )" + Config.lorem, hooks=error_line0, hook_status=platform_status(2, 1)) - test("(); () ;() ;() ;() ;() ;() ;() ;() ;() ;a", hooks=error_line0, hook_status=platform_status(2, 1)) + test("< && a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("> && a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(">> && a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("< || a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("> || a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(">> || a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("< ( a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("> ( a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(">> ( a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("< ) a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("> ) a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(">> ) a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("&& < a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("&& > a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("&& >> a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("&& || a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("&& ( a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("&& ) a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("|| < a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("|| > a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("|| >> a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("|| && a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("|| ( a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("|| ) a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("( < a", hooks=[error_line0, error_eof_to_expected_token], hooks_status=platform_status(2, 1)) + test("( > a", hooks=[error_line0, error_eof_to_expected_token], hooks_status=platform_status(2, 1)) + test("( >> a", hooks=[error_line0, error_eof_to_expected_token], hooks_status=platform_status(2, 1)) + test(") < a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(") > a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(") >> a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("( && a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("( || a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("( ) a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(") && a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(") || a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(") ( a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("() a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test("( a", hooks=[error_line0, error_eof_to_expected_token], hooks_status=platform_status(2, 1)) + test(") a", hooks=error_line0, hooks_status=platform_status(2, 1)) + test(Config.lorem + " && &&" + Config.lorem, hooks=error_line0, hooks_status=platform_status(2, 1)) + test(Config.lorem + " || ||" + Config.lorem, hooks=error_line0, hooks_status=platform_status(2, 1)) + test(Config.lorem + " ( (" + Config.lorem, hooks=error_line0, hooks_status=platform_status(2, 1)) + test(Config.lorem + " ) )" + Config.lorem, hooks=error_line0, hooks_status=platform_status(2, 1)) + test("(); () ;() ;() ;() ;() ;() ;() ;() ;() ;a", hooks=error_line0, hooks_status=platform_status(2, 1)) diff --git a/minishell_test/suites/preprocess.py b/minishell_test/suites/preprocess.py index 6e717a1..e3babd9 100644 --- a/minishell_test/suites/preprocess.py +++ b/minishell_test/suites/preprocess.py @@ -56,18 +56,18 @@ def suite_quote(test): test("echo '\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"'") test('echo "\'"') test('echo "\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'\'"') - test("echo '", hooks=hooks.error_line0, hook_status=hooks.platform_status(2, 1)) - test('echo "', hooks=hooks.error_line0, hook_status=hooks.platform_status(2, 1)) - test("echo '''", hooks=hooks.error_line0, hook_status=hooks.platform_status(2, 1)) - test('echo """', hooks=hooks.error_line0, hook_status=hooks.platform_status(2, 1)) - test("echo '''''''''''''''''''''''''''''''''''''''''''", hooks=hooks.error_line0, hook_status=hooks.platform_status(2, 1)) - test('echo """""""""""""""""""""""""""""""""""""""""""', hooks=hooks.error_line0, hook_status=hooks.platform_status(2, 1)) + test("echo '", hooks=hooks.error_line0, hooks_status=hooks.platform_status(2, 1)) + test('echo "', hooks=hooks.error_line0, hooks_status=hooks.platform_status(2, 1)) + test("echo '''", hooks=hooks.error_line0, hooks_status=hooks.platform_status(2, 1)) + test('echo """', hooks=hooks.error_line0, hooks_status=hooks.platform_status(2, 1)) + test("echo '''''''''''''''''''''''''''''''''''''''''''", hooks=hooks.error_line0, hooks_status=hooks.platform_status(2, 1)) + test('echo """""""""""""""""""""""""""""""""""""""""""', hooks=hooks.error_line0, hooks_status=hooks.platform_status(2, 1)) test("echo 'AH\\'") - test('echo "AH\\"', hooks=hooks.error_line0, hook_status=hooks.platform_status(2, 1)) + test('echo "AH\\"', hooks=hooks.error_line0, hooks_status=hooks.platform_status(2, 1)) test('echo "AH\\""') - test("echo '\\''", hooks=hooks.error_line0, hook_status=hooks.platform_status(2, 1)) + test("echo '\\''", hooks=hooks.error_line0, hooks_status=hooks.platform_status(2, 1)) test('echo "\\""') - test('echo "\\\\""', hooks=hooks.error_line0, hook_status=hooks.platform_status(2, 1)) + test('echo "\\\\""', hooks=hooks.error_line0, hooks_status=hooks.platform_status(2, 1)) test('echo bonjour > "fi le"', files=['fi le']) test("echo bonjour > 'fi le'", files=['fi le']) diff --git a/tests/conftest.py b/tests/conftest.py index 5e64fd1..137a024 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1 +1,10 @@ -# do not remove, used by pytest +import pytest + +from minishell_test.config import Config +from minishell_test import colors + + +@pytest.fixture(autouse=True) +def config_init(): + colors.disable() + Config.init([]) diff --git a/tests/suite/test_decorator.py b/tests/suite/test_decorator.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/suite/test_decorator.py diff --git a/tests/suite/test_suite.py b/tests/suite/test_suite.py new file mode 100644 index 0000000..925558f --- /dev/null +++ b/tests/suite/test_suite.py @@ -0,0 +1,121 @@ +# ############################################################################ # +# # +# ::: :::::::: # +# test_suite.py :+: :+: :+: # +# +:+ +:+ +:+ # +# By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2021/03/06 11:20:47 by cacharle #+# #+# # +# Updated: 2021/03/06 16:01:03 by cacharle ### ########.fr # +# # +# ############################################################################ # + +import pytest +from pathlib import Path + +from minishell_test.suite.suite import Suite, NoMatchException, SuiteExitFirstException +from minishell_test.config import Config + + +class TestSuite: + @pytest.fixture + def available_suite_names(self, monkeypatch): + s = [ + Suite(None, 'bonjour', 'grouped', False, 'nice description'), + Suite(None, 'aurevoir', 'notgrouped', False, 'not nice description'), + Suite(None, 'ft', 'yes', False, 'no'), + Suite(None, 'ft_strlen', 'yes', False, 'no'), + Suite(None, 'charles', 'cabergs', False, 'est super'), + Suite(None, 'guillaume', 'cabergs', False, 'est super'), + Suite(None, 'bonus', 'yes', True, 'est super'), + ] + monkeypatch.setattr(Suite, '_available', s) + + def test_list(self, monkeypatch, available_suite_names): + assert """\ +grouped/bonjour ....... nice description +notgrouped/aurevoir ... not nice description +yes/ft ................ no +yes/ft_strlen ......... no +cabergs/charles ....... est super +cabergs/guillaume ..... est super +yes/bonus ............. est super +""" == Suite.list() + + def test_asked_names(self, monkeypatch, available_suite_names): + def suite_names_set(suites): + return {s._name for s in suites} + monkeypatch.setattr(Config, "bonus", False) + assert {"charles"} == suite_names_set(Suite._asked_suites(["charl"])) + assert {"guillaume"} == suite_names_set(Suite._asked_suites(["gui"])) + assert {"charles", "guillaume"} == suite_names_set(Suite._asked_suites(["cab"])) + assert {"ft", "ft_strlen"} == suite_names_set(Suite._asked_suites(["ft"])) + assert {"ft_strlen"} == suite_names_set(Suite._asked_suites(["ft_"])) + assert {"ft", "ft_strlen"} == suite_names_set(Suite._asked_suites(["yes"])) + assert {"ft", "ft_strlen", "charles", "guillaume", "bonjour", "aurevoir"} == suite_names_set(Suite._asked_suites([])) + monkeypatch.setattr(Config, "bonus", True) + assert {"ft", "ft_strlen", "bonus"} == suite_names_set(Suite._asked_suites(["yes"])) + assert {"ft", "ft_strlen", "charles", "guillaume", "bonjour", "aurevoir", "bonus"} == suite_names_set(Suite._asked_suites([])) + with pytest.raises(NoMatchException) as e: + Suite._asked_suites(["notanavailablename"]) + assert "notanavailablename" == e.value._name + assert (f"Name `notanavailablename` doesn't match any suite/group name\n\t" + "Try to run with -l to see the available suites") == e.value.__str__() + + @pytest.fixture + def runnable_suite(self): + def suite_func(test): + test("echo bonjour") + monkeypatch.setattr( + Suite, + '_available', + [Suite(suite_func, "suite_name", "suite_group", False, "suite_description")] + ) + + def test_instance_run(self, monkeypatch, capsys): + def suite_func(test): + test("echo bonjour") + test("echo foo") + test("echo bar") + s = Suite(suite_func, "suite_name", "suite_group", False, "suite_description") + monkeypatch.setattr(Config, 'minishell_exec_path', Path("/bin/bash")) + s._register() + assert len(s._tests) == 3 + assert "echo bonjour" == s._tests[0]._cmd + assert "echo foo" == s._tests[1]._cmd + assert "echo bar" == s._tests[2]._cmd + monkeypatch.setattr(Config, 'term_cols', 20) + s._run() + output = capsys.readouterr() + output_lines = output.out.splitlines() + assert len(output_lines) == 4 + assert '#### suite_name ####' == output_lines[0] + assert len(s._results) == 3 + assert all(r.passed for r in s._results) + + s = Suite(suite_func, "suite_name", "suite_group", False, "suite_description") + s._register() + monkeypatch.setattr(Config, 'range', (1, 2)) + s._run() + output = capsys.readouterr() + output_lines = output.out.splitlines() + assert len(output_lines) == 3 + assert '#### suite_name ####' == output_lines[0] + assert len(s._results) == 2 + assert all(r.passed for r in s._results) + + monkeypatch.setattr(Config, 'exit_first', True) + monkeypatch.setattr(Config, 'minishell_exec_path', Path("/usr/bin/cat")) + s = Suite(suite_func, "suite_name", "suite_group", False, "suite_description") + s._register() + with pytest.raises(SuiteExitFirstException): + s._run() + output = capsys.readouterr() + output_lines = output.out.splitlines() + assert len(output_lines) == 2 + assert '#### suite_name ####' == output_lines[0] + assert len(s._results) == 1 + assert all(r.failed for r in s._results) + + def test_summarize(self): + assert False diff --git a/tests/test/test_result.py b/tests/test/test_result.py index 2e3afdb..bf23626 100644 --- a/tests/test/test_result.py +++ b/tests/test/test_result.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/01 16:26:34 by cacharle #+# #+# # -# Updated: 2021/03/06 10:01:04 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:39:03 by cacharle ### ########.fr # # # # ############################################################################ # @@ -19,10 +19,6 @@ from minishell_test.test.result import BaseResult, Result, LeakResult, LeakResul from minishell_test.test.captured import CapturedCommand, CapturedTimeout -colors.disable() -Config.init([]) - - class TestBaseResult: @pytest.fixture def base_result(self): diff --git a/tests/test/test_test.py b/tests/test/test_test.py index 11255c0..f106cd1 100644 --- a/tests/test/test_test.py +++ b/tests/test/test_test.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/02 18:48:57 by cacharle #+# #+# # -# Updated: 2021/03/06 10:07:07 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:38:12 by cacharle ### ########.fr # # # # ############################################################################ # @@ -22,15 +22,7 @@ from minishell_test.test.captured import CapturedCommand, CapturedTimeout from minishell_test.test.test import Test, TestSetupException -colors.disable() -Config.init([]) - - class TestTest: - @pytest.fixture(autouse=True) - def reset_config(self): - Config.init([]) - def test_init_timeout(self, monkeypatch): assert Config.timeout_test == Test("")._timeout assert Config.timeout_test == Test("", timeout=0)._timeout diff --git a/tests/test_config.py b/tests/test_config.py index deb9761..304103b 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/03 12:25:29 by cacharle #+# #+# # -# Updated: 2021/03/06 10:11:30 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:38:41 by cacharle ### ########.fr # # # # ############################################################################ # @@ -27,9 +27,6 @@ from minishell_test.config import ( ) -Config.init([]) - - class TestConfigParser: @pytest.fixture def config(self): diff --git a/tests/test_hooks.py b/tests/test_hooks.py index 2df31d2..75375a4 100644 --- a/tests/test_hooks.py +++ b/tests/test_hooks.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/02/27 20:03:52 by cacharle #+# #+# # -# Updated: 2021/03/06 09:56:09 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:38:22 by cacharle ### ########.fr # # # # ############################################################################ # @@ -27,9 +27,6 @@ from minishell_test.hooks import ( ) -Config.init([]) - - def test_sort_lines(): assert "a\nb\nc" == sort_lines("a\nb\nc") assert "a\nb\nc" == sort_lines("c\nb\na") diff --git a/tests/test_sandbox.py b/tests/test_sandbox.py index bb2ea98..cfd67e5 100644 --- a/tests/test_sandbox.py +++ b/tests/test_sandbox.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/03/03 08:09:00 by cacharle #+# #+# # -# Updated: 2021/03/06 09:58:17 by cacharle ### ########.fr # +# Updated: 2021/03/06 15:38:49 by cacharle ### ########.fr # # # # ############################################################################ # @@ -17,8 +17,6 @@ from pathlib import Path from minishell_test import sandbox from minishell_test.config import Config -Config.init([]) - @pytest.fixture def sandbox_dirs(): |
