aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-10-08 08:43:12 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-10-08 08:43:12 +0200
commitc20cbfea9bb878fc88e76f0ba773ded5a7b149ca (patch)
treea49139c7f4a85cfab07df1d41be15a0275010fe6 /src
parent0cf5d76836a6499de4e30c4066d8709099ff6331 (diff)
downloadminishell_test-c20cbfea9bb878fc88e76f0ba773ded5a7b149ca.tar.gz
minishell_test-c20cbfea9bb878fc88e76f0ba773ded5a7b149ca.tar.bz2
minishell_test-c20cbfea9bb878fc88e76f0ba773ded5a7b149ca.zip
Added suite description for -l option
Diffstat (limited to 'src')
-rw-r--r--src/args.py10
-rwxr-xr-xsrc/main.py5
-rw-r--r--src/suite/decorator.py13
-rw-r--r--src/suite/suite.py39
-rw-r--r--src/suites/builtin.py9
-rw-r--r--src/suites/cmd.py6
-rw-r--r--src/suites/flow.py7
-rw-r--r--src/suites/path.py4
-rw-r--r--src/suites/preprocess.py6
9 files changed, 71 insertions, 28 deletions
diff --git a/src/args.py b/src/args.py
index b606285..880bf6a 100644
--- a/src/args.py
+++ b/src/args.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:32 by charles #+# #+# #
-# Updated: 2020/10/07 18:21:33 by cacharle ### ########.fr #
+# Updated: 2020/10/08 08:13:05 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -26,6 +26,14 @@ 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)"
+ )
+ parser.add_argument(
+ "--show-index", action="store_true",
+ help="Show test index (useful with --range)"
+ )
+ parser.add_argument(
"-v", "--verbose", action="count",
help="Increase verbosity level (e.g -vv == 2)"
)
diff --git a/src/main.py b/src/main.py
index 204abee..1bebb89 100755
--- a/src/main.py
+++ b/src/main.py
@@ -28,10 +28,7 @@ from suites import * # noqa: F403,F401
def main():
args = parse_args()
if args.list:
- print("The available suites are:")
- print('\n'.join([" - " + s.name for s in Suite.available]))
- print("Groups:")
- print('\n'.join([" - " + ', '.join(s.groups) for s in Suite.available]))
+ Suite.list()
sys.exit(0)
if config.MINISHELL_MAKE or args.make:
diff --git a/src/suite/decorator.py b/src/suite/decorator.py
index d4801c3..12f58a6 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/09/11 22:08:36 by charles ### ########.fr #
+# Updated: 2020/10/08 08:34:10 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -22,10 +22,15 @@ def suite(groups: [str] = [], bonus: bool = False):
"""Decorator for a suite function (fmt: suite_[name]) """
mod_name = inspect.getmodule(origin).__name__[len("suites."):]
- # print(mod_name)
-
name = "{}/{}".format(mod_name, origin.__name__[len("suite_"):])
- s = Suite(name, groups + [mod_name], bonus)
+ description = origin.__doc__
+ if description is None:
+ 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):
diff --git a/src/suite/suite.py b/src/suite/suite.py
index dc5611a..b5eb96c 100644
--- a/src/suite/suite.py
+++ b/src/suite/suite.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:29 by charles #+# #+# #
-# Updated: 2020/10/07 18:24:20 by cacharle ### ########.fr #
+# Updated: 2020/10/08 08:42:50 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -17,18 +17,6 @@ import termios
import config
-# # from: https://stackoverflow.com/questions/510357
-# def getchar():
-# fd = sys.stdin.fileno()
-# old_settings = termios.tcgetattr(fd)
-# try:
-# tty.setraw(sys.stdin.fileno())
-# char = sys.stdin.read(1)
-# finally:
-# termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
-# return char
-
-
class Suite:
available = []
@@ -85,7 +73,29 @@ class Suite:
"""List of available suites names"""
return [s.name for s in cls.available]
- def __init__(self, name: str, groups: [str], bonus: bool = False):
+ @classmethod
+ def list(cls):
+ print("Groups:")
+ print("\n".join(set([" - " + ', '.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 __init__(
+ self,
+ name: str,
+ groups: [str],
+ bonus: bool = False,
+ description: str = "no description",
+ ):
"""Suite class
name: suite id
groups: list of suite groups
@@ -93,6 +103,7 @@ class Suite:
"""
self.name = name
self.groups = groups
+ self.description = description
self.bonus = bonus
self.generator_func = None
self.tests = []
diff --git a/src/suites/builtin.py b/src/suites/builtin.py
index e90b798..932375b 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/07 11:56:46 by cacharle ### ########.fr #
+# Updated: 2020/10/08 08:40:18 by cacharle ### ########.fr #
# Updated: 2020/09/11 18:01:27 by juligonz ### ########.fr #
# #
# **************************************************************************** #
@@ -20,6 +20,7 @@ from suite import suite
@suite()
def suite_echo(test):
+ """ echo builtin tests """
test("echo")
test("echo bonjour")
test("echo lalalala lalalalal alalalalal alalalala")
@@ -43,6 +44,7 @@ def suite_echo(test):
@suite()
def suite_export(test):
+ """ export builtin tests """
test("export", hook=hooks.export_singleton)
test("export", exports={"A": ""}, hook=hooks.export_singleton)
test("export", exports={"A": "\""}, hook=hooks.export_singleton)
@@ -115,6 +117,7 @@ def suite_export(test):
@suite()
def suite_cd(test):
+ """ cd builtin tests """
test("cd .; pwd; echo $PWD")
test("cd ..; pwd; echo $PWD")
test("cd ../..; pwd; echo $PWD")
@@ -205,6 +208,7 @@ def suite_cd(test):
@suite()
def suite_unset(test):
+ """ unset builtin tests """
test("unset")
test("unset A; echo $A", exports={"A": "a"})
test("unset 'A '; echo $A", exports={"A": "a"})
@@ -239,6 +243,7 @@ def suite_unset(test):
@suite()
def suite_pwd(test):
+ """ pwd builtin tests """
test("pwd")
test("pwd", setup="cd ..")
test("pwd", setup="cd ../..")
@@ -252,6 +257,7 @@ def suite_pwd(test):
@suite()
def suite_env(test):
+ """ env builtin tests """
test("env", hook=[hooks.sort_lines, hooks.shlvl_0_to_1])
test("env", setup="export A=a", hook=[hooks.sort_lines, hooks.shlvl_0_to_1])
test("env", setup="export A=a B=b C=c", hook=[hooks.sort_lines, hooks.shlvl_0_to_1])
@@ -260,6 +266,7 @@ def suite_env(test):
@suite()
def suite_exit(test):
+ """ exit builtin tests """
test("exit")
test("exit 1")
test("exit 2")
diff --git a/src/suites/cmd.py b/src/suites/cmd.py
index 25ca49b..c4db2a8 100644
--- a/src/suites/cmd.py
+++ b/src/suites/cmd.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 15:11:46 by charles #+# #+# #
-# Updated: 2020/10/07 08:11:04 by charles ### ########.fr #
+# Updated: 2020/10/08 08:39:36 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -19,6 +19,7 @@ from suite import suite
@suite()
def suite_redirection(test):
+ """ append/write/read redirections """
test("echo bonjour > test", setup="", files=["test"])
test("echo > test bonjour", setup="", files=["test"])
test("> test echo bonjour", setup="", files=["test"])
@@ -87,6 +88,7 @@ def suite_redirection(test):
@suite()
def suite_cmd(test):
+ """ long cmd, cmd not found tests """
test("notfound")
test("notfound a b c")
test('echo "\\"" >>a"b""c" ', files=["abc"])
@@ -105,6 +107,7 @@ def suite_cmd(test):
@suite()
def suite_status(test):
+ """ $? tests """
test("echo $?")
test("echo; echo $?")
test("notfound; echo $?")
@@ -118,6 +121,7 @@ def suite_status(test):
@suite()
def suite_cmd_path(test):
+ """ cmd is a relative path, permissions on executable """
ls_path = distutils.spawn.find_executable("ls")
cat_path = distutils.spawn.find_executable("cat")
test(ls_path, setup="touch a b c")
diff --git a/src/suites/flow.py b/src/suites/flow.py
index d1b70d7..bcee31e 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/07 11:59:21 by cacharle ### ########.fr #
+# Updated: 2020/10/08 08:40:56 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -16,6 +16,7 @@ from hooks import error_line0, platform_status, discard, replace_double_semi_col
@suite()
def suite_end(test):
+ """ `;` tests """
test("echo bonjour; echo je")
test("echo bonjour ;echo je")
test("echo bonjour ; echo je")
@@ -54,6 +55,7 @@ def suite_end(test):
@suite()
def suite_pipe(test):
+ """ `|` tests """
test("cat /etc/shells | head -c 10")
test("cat -e /etc/shells | head -c 10")
test("cat -e /etc/shells | cat -e | head -c 10")
@@ -93,6 +95,7 @@ def suite_pipe(test):
@suite(bonus=True)
def suite_and(test):
+ """ `&&` tests """
test("echo bonjour&& echo je")
test("echo bonjour &&echo je")
test("echo bonjour && echo je")
@@ -118,6 +121,7 @@ def suite_and(test):
@suite(bonus=True)
def suite_or(test):
+ """ `||` tests """
test("echo bonjour|| echo je")
test("echo bonjour ||echo je")
test("echo bonjour || echo je")
@@ -143,6 +147,7 @@ def suite_or(test):
@suite(bonus=True)
def suite_parenthesis(test):
+ """ `(`, `)` tests """
test("(echo bonjour)")
test("(echo bonjour )")
test("( echo bonjour )")
diff --git a/src/suites/path.py b/src/suites/path.py
index d5dabb6..13866de 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/07 15:16:49 by cacharle ### ########.fr #
+# Updated: 2020/10/08 08:41:38 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -17,6 +17,7 @@ from suite import suite
@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 +
@@ -78,6 +79,7 @@ def suite_path(test):
@suite()
def suite_path_variable(test):
+ """ $PATH environment variable tests """
test("echo $PATH", exports={"PATH": "doesnotexits"})
test("echo $PATH", exports={"PATH": "doesnotexits:asdfasdfas"})
test("echo $PATH", exports={"PATH": "a:b:c:d:e:f:g:h:i:j:k:l:m:n:o:p:q:r:s:t:u:v:w:x:y:z"})
diff --git a/src/suites/preprocess.py b/src/suites/preprocess.py
index 506cb32..3b70666 100644
--- a/src/suites/preprocess.py
+++ b/src/suites/preprocess.py
@@ -6,7 +6,7 @@
# By: juligonz <juligonz@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:25:00 by charles #+# #+# #
-# Updated: 2020/10/07 08:27:57 by charles ### ########.fr #
+# Updated: 2020/10/08 08:37:19 by cacharle ### ########.fr #
# #
# **************************************************************************** #
@@ -17,6 +17,7 @@ from suite import suite
@suite()
def suite_quote(test):
+ """ double and single quote test, escape in quotes, quote missmatch """
test("'echo' 'bonjour'")
test("'echo' 'je' 'suis' 'charles'")
test('"echo" "bonjour"')
@@ -71,6 +72,7 @@ def suite_quote(test):
@suite()
def suite_interpolation(test):
+ """environment variable interpolation tests, valid name, escape in variable"""
test("echo $TEST", exports={"TEST": "bonjour"})
test("echo $TES", exports={"TEST": "bonjour"})
test("echo $TEST_", exports={"TEST": "bonjour"})
@@ -168,6 +170,7 @@ def suite_interpolation(test):
@suite()
def suite_escape(test):
+ """ escape test, in command, with space, before quote """
test(r"echo \a")
test(r"\e\c\h\o bonjour")
test(r"echo charles\ ")
@@ -223,6 +226,7 @@ def suite_escape(test):
@suite()
def suite_spaces(test):
+ """ field splitting with spaces and tabs """
test("echo foo")
test("echo foo")
test(" echo foo")