aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-07-15 13:26:01 +0200
committerCharles <sircharlesaze@gmail.com>2020-07-15 13:26:01 +0200
commit9132220296cdf6ab29c570fe0534649cfcc1cd8d (patch)
treec65844a14b1abafa5a9e08d0d22a9ea52f25f994
parentcc041d1901daa8be9197a59d963466fdc7e2b404 (diff)
downloadminishell_test-9132220296cdf6ab29c570fe0534649cfcc1cd8d.tar.gz
minishell_test-9132220296cdf6ab29c570fe0534649cfcc1cd8d.tar.bz2
minishell_test-9132220296cdf6ab29c570fe0534649cfcc1cd8d.zip
Added error message comparison and basic timeout
-rw-r--r--config.py5
-rwxr-xr-xmain.py2
-rw-r--r--suites/builtin.py27
-rw-r--r--test.py23
4 files changed, 47 insertions, 10 deletions
diff --git a/config.py b/config.py
index c1f9ba9..632591a 100644
--- a/config.py
+++ b/config.py
@@ -21,7 +21,7 @@ SANDBOX_PATH = "sandbox"
EXECUTABLES_PATH = "./bin"
# commands available in test"
-AVAILABLE_COMMANDS = ["cat", "touch", "env", "ls"]
+AVAILABLE_COMMANDS = ["cat", "touch", "env", "ls", "grep"]
# $PATH environment variable passed to the shell
PATH_VARIABLE = os.path.abspath(EXECUTABLES_PATH)
@@ -51,3 +51,6 @@ MINISHELL_PATH = os.path.abspath(
# 0, 1, 2
VERBOSE_LEVEL = 1
+
+MINISHELL_ERROR_BEGIN = os.path.basename(MINISHELL_PATH) + ": "
+REFERENCE_ERROR_BEGIN = REFERENCE_PATH + ": line 0: "
diff --git a/main.py b/main.py
index 9a407c0..0210633 100755
--- a/main.py
+++ b/main.py
@@ -18,7 +18,7 @@ def main():
if not os.path.exists(config.EXECUTABLES_PATH):
os.mkdir(config.EXECUTABLES_PATH)
for cmd in config.AVAILABLE_COMMANDS:
- shutil.copy(os.path.join("/usr/bin", cmd), # search whole PATH
+ shutil.copy(os.path.join("/usr/bin", cmd), # FIXME search whole PATH
os.path.join(config.EXECUTABLES_PATH, cmd))
args = parse_args()
diff --git a/suites/builtin.py b/suites/builtin.py
index bbe8083..666a744 100644
--- a/suites/builtin.py
+++ b/suites/builtin.py
@@ -20,10 +20,16 @@ def suite_echo(test):
test(" echo bonjour je")
test(" echo -n bonjour je")
+ test("echo a '' b '' c '' d")
+ test('echo a "" b "" c "" d')
+ test("echo -n a '' b '' c '' d")
+ test('echo -n a "" b "" c "" d')
+
@suite
def suite_export(test):
test("export")
- test("export A=; env | grep A=")
+ # test("export A=; env | grep A=; echo $A")
+ # test("export A; env | grep A; echo $A")
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" +
@@ -62,6 +68,10 @@ def suite_export(test):
test(r"export A=====a; echo $A")
test(r"export A======a; echo $A")
test(r"export A=a=a=a=a=a; echo $A")
+ test("export A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C")
+ test("export 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C")
+ test("export A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf '; echo $A$B$C")
+
@suite
def suite_cd(test):
@@ -92,9 +102,24 @@ def suite_unset(test):
test("unset 'A '; echo $A", setup="export A=a")
test("unset 'A='; echo $A", setup="export A=a")
test("unset A B C; echo $A$B$C", setup="export A=a B=b C=c")
+ test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C",
+ setup="export A=a B=b C=c")
+ test("unset 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C",
+ setup="export A=a B=b C=c")
+ test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf '; echo $A$B$C",
+ setup="export A=a B=b C=c")
test("unset A; echo $A$B$C", setup="export A=a B=b C=c")
test("unset C; echo $A$B$C", setup="export A=a B=b C=c")
+ test("unset A B C", setup="export A=a B=b C=c")
+ test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C",
+ setup="export A=a B=b C=c")
+ test("unset 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C",
+ setup="export A=a B=b C=c")
+ test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf '",
+ setup="export A=a B=b C=c")
+ test("unset A", setup="export A=a B=b C=c")
+
@suite
def suite_pwd(test):
test("pwd")
diff --git a/test.py b/test.py
index 690e6a9..7f890f8 100644
--- a/test.py
+++ b/test.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/06/16 21:48:50 by charles #+# #+# #
-# Updated: 2020/06/23 09:18:29 by charles ### ########.fr #
+# Updated: 2020/07/15 12:49:46 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -18,7 +18,13 @@ import config
class Captured:
def __init__(self, output: str, status: int, files_content: [str]):
- self.output = output
+ lines = output.split('\n')
+ for i, l in enumerate(lines):
+ if l.find(config.REFERENCE_ERROR_BEGIN) == 0:
+ lines[i] = l.replace(config.REFERENCE_ERROR_BEGIN, config.MINISHELL_ERROR_BEGIN, 1)
+ self.output = '\n'.join(lines)
+
+ # self.output = output
self.status = status
self.files_content = files_content
@@ -166,12 +172,12 @@ class Test:
self.result = None
def run(self):
- expected = self._run_sandboxed(config.REFERENCE_PATH)
- actual = self._run_sandboxed(config.MINISHELL_PATH)
+ expected = self._run_sandboxed(config.REFERENCE_PATH, "-c")
+ actual = self._run_sandboxed(config.MINISHELL_PATH, "-c")
self.result = Result(self.cmd, self.files, expected, actual)
self.result.put()
- def _run_sandboxed(self, shell_path: str) -> Captured:
+ def _run_sandboxed(self, shell_path: str, shell_option: str) -> Captured:
""" run the command in a sandbox environment
capture the output (stdout and stderr)
@@ -192,11 +198,14 @@ class Test:
# TODO: add timeout
# https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module
- process_status = subprocess.run([shell_path, "-c", self.cmd],
+ process_status = subprocess.run([shell_path, shell_option, self.cmd],
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
cwd=config.SANDBOX_PATH,
- env={'PATH': config.PATH_VARIABLE, **self.exports})
+ env={'PATH': config.PATH_VARIABLE,
+ 'TERM': 'xterm-256color',
+ **self.exports},
+ timeout=1)
output = process_status.stdout.decode()
# capture watched files content