aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/args.py8
-rw-r--r--src/config.py4
-rwxr-xr-xsrc/main.py4
-rw-r--r--src/suite/suite.py32
-rw-r--r--src/suites/builtin.py14
-rw-r--r--src/suites/cmd.py4
-rw-r--r--src/test/test.py10
7 files changed, 53 insertions, 23 deletions
diff --git a/src/args.py b/src/args.py
index a79ce15..9f31d98 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/09/11 22:09:04 by charles ### ########.fr #
+# Updated: 2020/09/12 02:21:51 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -18,7 +18,7 @@ def parse_args():
parser = argparse.ArgumentParser(
description="Minishell test",
- epilog="Make sure read README.md"
+ epilog="Make sure read the README.md"
)
parser.add_argument(
"-v", "--verbose", action="count",
@@ -42,7 +42,9 @@ def parse_args():
)
parser.add_argument(
"suites", nargs='*', metavar="suite",
- help="test suites/group to run"
+ help="test suites/group to run, "
+ "It tries to be smart and auto complete the suite name "
+ "you put in (e.g ./run int -> ./run preprocess/interpolation)"
)
tmp = parser.parse_args()
if tmp.verbose is None:
diff --git a/src/config.py b/src/config.py
index 27d524e..a9a3b78 100644
--- a/src/config.py
+++ b/src/config.py
@@ -6,11 +6,10 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:19 by charles #+# #+# #
-# Updated: 2020/09/11 15:51:31 by charles ### ########.fr #
+# Updated: 2020/09/12 01:33:18 by charles ### ########.fr #
# #
# ############################################################################ #
-
################################################################################
# Minishell configuration file #
################################################################################
@@ -32,6 +31,7 @@ MINISHELL_MAKE = True
# path to reference shell (shell which will be compared minishell)
# has to support the -c option (sh, bash and zsh support it)
REFERENCE_PATH = "/bin/bash"
+REFERENCE_ARGS = ["--posix"]
# log file path
LOG_PATH = "result.log"
diff --git a/src/main.py b/src/main.py
index 75b8947..9b49ce8 100755
--- a/src/main.py
+++ b/src/main.py
@@ -36,7 +36,9 @@ def main():
if config.MINISHELL_MAKE or args.make:
try:
+ print("========================================MAKE====================================")
subprocess.run(["make", "-C", config.MINISHELL_DIR], check=True)
+ print("================================================================================")
except subprocess.CalledProcessError:
sys.exit(1)
if args.make:
@@ -45,7 +47,7 @@ def main():
shutil.rmtree(config.EXECUTABLES_PATH)
os.mkdir(config.EXECUTABLES_PATH)
for cmd in config.AVAILABLE_COMMANDS:
- shutil.copy(distutils.spawn.find_executable(cmd), # FIXME search whole PATH
+ shutil.copy(distutils.spawn.find_executable(cmd),
os.path.join(config.EXECUTABLES_PATH, cmd))
config.VERBOSE_LEVEL = args.verbose
diff --git a/src/suite/suite.py b/src/suite/suite.py
index 2ac64e4..b81205e 100644
--- a/src/suite/suite.py
+++ b/src/suite/suite.py
@@ -6,10 +6,12 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:29 by charles #+# #+# #
-# Updated: 2020/09/11 20:35:13 by charles ### ########.fr #
+# Updated: 2020/09/12 02:14:58 by charles ### ########.fr #
# #
# ############################################################################ #
+import sys
+
import config
@@ -27,15 +29,39 @@ class Suite:
"""Remove not asked suite from available suites"""
if len(asked_names) == 0:
asked_names = [s.name for s in cls.available]
+
if not config.BONUS:
cls.available = [s for s in cls.available if not s.bonus]
+
+ names = []
+ for i, name in enumerate(asked_names):
+ matches = [s.name for s in cls.available
+ if s.name.find("/") != -1
+ and s.name[s.name.find("/") + 1:].startswith(name)
+ or s.name.startswith(name)]
+ if len(matches) == 1:
+ names.append(matches[0])
+ elif 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)))
+ sys.exit(1)
+ elif len(matches) == 0:
+ print(("No suite named `{}` found\n\t{}\n"
+ "Try to run with -l to see the available suites")
+ .format(name, ', '.join(matches)))
+ sys.exit(1)
+
cls.available = list(set(
- [s for s in cls.available if s.name in asked_names]
- + [s for s in cls.available if any([g for g in s.groups if g in asked_names])]
+ [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])]
))
for s in cls.available:
s.generator_func()
+
@classmethod
def available_names(cls) -> [str]:
"""List of available suites names"""
diff --git a/src/suites/builtin.py b/src/suites/builtin.py
index 06686bb..ff094e0 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/09/11 19:56:44 by charles ### ########.fr #
+# Updated: 2020/09/12 01:40:08 by charles ### ########.fr #
# Updated: 2020/09/11 18:01:27 by juligonz ### ########.fr #
# #
# **************************************************************************** #
@@ -43,12 +43,12 @@ def suite_echo(test):
@suite()
def suite_export(test):
- test("export", hook=hooks.export_singleton)
- test("export", exports={"A": ""}, hook=hooks.export_singleton)
- test("export", exports={"A": "\""}, hook=hooks.export_singleton)
- test("export", exports={"A": "\t"}, hook=hooks.export_singleton)
- test("export", exports={"A": "'"}, hook=hooks.export_singleton)
- test("export", exports={"A": "a"}, hook=hooks.export_singleton)
+ test("export")#, hook=hooks.export_singleton)
+ test("export", exports={"A": ""})#, hook=hooks.export_singleton)
+ test("export", exports={"A": "\""})#, hook=hooks.export_singleton)
+ test("export", exports={"A": "\t"})#, hook=hooks.export_singleton)
+ test("export", exports={"A": "'"})#, hook=hooks.export_singleton)
+ test("export", exports={"A": "a"})#, hook=hooks.export_singleton)
test("export A=a; echo $A")
test("export A=a B=b C=c; echo $A$B$C")
test("export A=a B=b C=c D=d E=e F=f G=g H=h I=i J=j K=k L=l"
diff --git a/src/suites/cmd.py b/src/suites/cmd.py
index f258dd4..2493a0e 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/09/11 20:12:16 by charles ### ########.fr #
+# Updated: 2020/09/12 01:31:00 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -179,7 +179,7 @@ def suite_cmd_path(test):
test("_", setup="touch _")
test("'-'", setup="touch -")
test("./_", setup="touch _")
- test("./-", setup="touch -")
+ test("./-", setup="touch a; mv a -- -")
test("./.", setup="touch .")
test("./..", setup="touch ..")
test("./somefile", setup='touch somefile && chmod 0777 somefile')
diff --git a/src/test/test.py b/src/test/test.py
index 054086a..b5abd85 100644
--- a/src/test/test.py
+++ b/src/test/test.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/06/16 21:48:50 by charles #+# #+# #
-# Updated: 2020/09/11 20:39:52 by charles ### ########.fr #
+# Updated: 2020/09/12 01:35:46 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -50,8 +50,8 @@ class Test:
def run(self):
"""Run the test for minishell and the reference shell and print the result out"""
- expected = self._run_sandboxed(config.REFERENCE_PATH, "-c")
- actual = self._run_sandboxed(config.MINISHELL_PATH, "-c")
+ expected = self._run_sandboxed(config.REFERENCE_PATH, config.REFERENCE_ARGS + ["-c"])
+ actual = self._run_sandboxed(config.MINISHELL_PATH, ["-c"])
s = self.cmd
if self.setup != "":
s = "[SETUP {}] {}".format(self.setup, s)
@@ -61,7 +61,7 @@ class Test:
self.result = Result(s, self.files, expected, actual)
self.result.put()
- def _run_sandboxed(self, shell_path: str, shell_option: str) -> Captured:
+ def _run_sandboxed(self, shell_path: str, shell_options: str) -> Captured:
""" Run the command in a sandbox environment
Capture the output (stdout and stderr)
Capture the content of the watched files after the command is run
@@ -88,7 +88,7 @@ class Test:
# run the command in the sandbox
process = subprocess.Popen(
- [shell_path, shell_option, self.cmd],
+ [shell_path, *shell_options, self.cmd],
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
cwd=config.SANDBOX_PATH,