From 93ead396473526e5f4849ad2f4194b8cc6c9ce45 Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 8 Oct 2020 17:04:32 +0200 Subject: Added flow syntax error tests --- .gitignore | 1 + README.md | 7 +++- src/args.py | 7 +++- src/suites/flow.py | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 116 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 5f8f35e..b3dbef6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *__pycache__* *.log bin +tags diff --git a/README.md b/README.md index a0ea7d8..9e15bae 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,7 @@ $ ./minishell -c 'ls' README.md test.sh ``` +With this setup `argv[2]` is what you would usually get in `line` from `get_next_line`. This allows you to set the prompt to whatever you want. This test works with python >= 3.5. @@ -74,7 +75,7 @@ Their is 3 different method to enable the bonus tests: `./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 +## Don't check error messages 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`. @@ -88,6 +89,8 @@ The tester will try to convert to output/status code of bash on Linux to the one ## Add new tests +You can find the suites in the [src/suites](src/suites) directory. + ### Add individual test In your suite function you can use the `test` function. With the following arguments: @@ -101,6 +104,7 @@ test("echo bonjour je suis") # simple command test("cat < somefile", setup="echo file content > somefile") # setup test("ls > somefile", setup="", files=["somefile"]) # watch a file test("echo $A", exports={"A": "a"}) # export variables in the environment +test("echo bonjour", hook=lambda s: s.replace("o", "a")) # pass the shell output through a hook function test("cat < somefile > otherfile", setup="echo file content > somefile", @@ -114,6 +118,7 @@ A test suite is a group of related tests. ```python @suite() # @suite(bonus=True) if it's a bonus suite def suite_yoursuitename(test): + """ a description of the suite """ test(...) test(...) test(...) diff --git a/src/args.py b/src/args.py index 5536ff5..7d1f260 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 09:02:52 by cacharle ### ########.fr # +# Updated: 2020/10/08 16:29:25 by cacharle ### ########.fr # # # # ############################################################################ # @@ -16,7 +16,10 @@ import argparse def parse_args(): """Parse command line arguments""" - parser = argparse.ArgumentParser(description="Minishell test") + parser = argparse.ArgumentParser( + description="Minishell test", + epilog="Signal handling is not tested" + ) parser.add_argument( "-k", "--check-leaks", action="store_true", help="Run valgrind on tests (disable usual comparison with bash)" diff --git a/src/suites/flow.py b/src/suites/flow.py index bcee31e..eac9459 100644 --- a/src/suites/flow.py +++ b/src/suites/flow.py @@ -6,10 +6,11 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:52 by charles #+# #+# # -# Updated: 2020/10/08 08:40:56 by cacharle ### ########.fr # +# Updated: 2020/10/08 16:45:19 by cacharle ### ########.fr # # # # ############################################################################ # +import config from suite import suite from hooks import error_line0, platform_status, discard, replace_double_semi_colon @@ -202,3 +203,105 @@ 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") + + +@suite() +def suite_syntax_error(test): + """ separator syntax error test """ + test("< |", hook=error_line0) + test("> |", hook=error_line0) + test(">> |", hook=error_line0) + test("< ;", hook=error_line0) + test("> ;", hook=error_line0) + test(">> ;", hook=error_line0) + test("; |", hook=error_line0) + test("; |", hook=error_line0) + test("; |", hook=error_line0) + test("; <", hook=error_line0) + test("; >", hook=error_line0) + test("; >>", hook=error_line0) + test("| ;", hook=error_line0) + test("| ;", hook=error_line0) + test("| ;", hook=error_line0) + test("| <", hook=error_line0) + test("| >", hook=error_line0) + test("| >>", hook=error_line0) + test("> a ;", hook=error_line0) + test("< a ;", hook=error_line0) + test(">> a ;", hook=error_line0) + test(config.LOREM + " > >" + config.LOREM, hook=error_line0) + test(config.LOREM + " < <" + config.LOREM, hook=error_line0) + test(config.LOREM + " ; |" + config.LOREM, hook=error_line0) + test(config.LOREM + " | ;" + config.LOREM, hook=error_line0) + + +@suite(bonus=True) +def suite_syntax_error_bonus(test): + """ separator syntax error bonus test """ + test("< &&", hook=error_line0) + test("> &&", hook=error_line0) + test(">> &&", hook=error_line0) + test("< ||", hook=error_line0) + test("> ||", hook=error_line0) + test(">> ||", hook=error_line0) + test("< (", hook=error_line0) + test("> (", hook=error_line0) + test(">> (", hook=error_line0) + test("< )", hook=error_line0) + test("> )", hook=error_line0) + test(">> )", hook=error_line0) + test("&& <", hook=error_line0) + test("&& >", hook=error_line0) + test("&& >>", hook=error_line0) + test("&& ||", hook=error_line0) + test("&& ||", hook=error_line0) + test("&& ||", hook=error_line0) + test("&& (", hook=error_line0) + test("&& (", hook=error_line0) + test("&& (", hook=error_line0) + test("&& )", hook=error_line0) + test("&& )", hook=error_line0) + test("&& )", hook=error_line0) + test("|| <", hook=error_line0) + test("|| >", hook=error_line0) + test("|| >>", hook=error_line0) + test("|| &&", hook=error_line0) + test("|| &&", hook=error_line0) + test("|| &&", hook=error_line0) + test("|| (", hook=error_line0) + test("|| (", hook=error_line0) + test("|| (", hook=error_line0) + test("|| )", hook=error_line0) + test("|| )", hook=error_line0) + test("|| )", hook=error_line0) + test("( <", hook=error_line0) + test("( >", hook=error_line0) + test("( >>", hook=error_line0) + test("( &&", hook=error_line0) + test("( &&", hook=error_line0) + test("( &&", hook=error_line0) + test("( ||", hook=error_line0) + test("( ||", hook=error_line0) + test("( ||", hook=error_line0) + test("( )", hook=error_line0) + test("( )", hook=error_line0) + test("( )", hook=error_line0) + test(") <", hook=error_line0) + test(") >", hook=error_line0) + test(") >>", hook=error_line0) + test(") &&", hook=error_line0) + test(") &&", hook=error_line0) + test(") &&", hook=error_line0) + test(") ||", hook=error_line0) + test(") ||", hook=error_line0) + test(") ||", hook=error_line0) + test(") (", hook=error_line0) + test(") (", hook=error_line0) + test(") (", hook=error_line0) + test("()", hook=error_line0) + test("(", hook=[error_line0, lambda o: o.replace("-c: line 1: ", "")]) + test(")", hook=error_line0) + test(config.LOREM + " && &&" + config.LOREM, hook=error_line0) + test(config.LOREM + " || ||" + config.LOREM, hook=error_line0) + test(config.LOREM + " ( (" + config.LOREM, hook=error_line0) + test(config.LOREM + " ) )" + config.LOREM, hook=error_line0) -- cgit