aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/config.py4
-rw-r--r--src/hooks.py7
-rw-r--r--src/suites/flow.py19
-rw-r--r--src/test/test.py11
4 files changed, 31 insertions, 10 deletions
diff --git a/src/config.py b/src/config.py
index a1bc12f..47c08cd 100644
--- a/src/config.py
+++ b/src/config.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:19 by charles #+# #+# #
-# Updated: 2020/09/13 14:31:21 by charles ### ########.fr #
+# Updated: 2020/09/16 11:33:54 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -50,7 +50,7 @@ SANDBOX_PATH = "sandbox"
EXECUTABLES_PATH = "./bin"
# commands available in test"
-AVAILABLE_COMMANDS = ["rmdir", "env", "cat", "touch", "ls", "grep", "sh"]
+AVAILABLE_COMMANDS = ["rmdir", "env", "cat", "touch", "ls", "grep", "sh", "head"]
# $PATH environment variable passed to the shell
PATH_VARIABLE = os.path.abspath(EXECUTABLES_PATH)
diff --git a/src/hooks.py b/src/hooks.py
index f14c8f7..1e01712 100644
--- a/src/hooks.py
+++ b/src/hooks.py
@@ -6,7 +6,7 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/11 16:10:20 by charles #+# #+# #
-# Updated: 2020/09/15 11:44:14 by charles ### ########.fr #
+# Updated: 2020/09/17 11:06:52 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -48,3 +48,8 @@ def export_singleton(output):
def replace_double_slash(output):
"""Replace occurence of double slash by one"""
return output.replace("//", "/")
+
+
+def replace_double_semi_colon(output):
+ """Replace occurence of double semi-colon by one"""
+ return output.replace(";;", ";")
diff --git a/src/suites/flow.py b/src/suites/flow.py
index ec4167c..babfd65 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/09/15 16:45:47 by charles ### ########.fr #
+# Updated: 2020/09/17 11:03:23 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -36,6 +36,16 @@ def suite_end(test):
test("ls doesnotexists; echo bonjour")
test("echo bonjour; ls doesnotexists")
test("echo a ; ;", hook=hooks.error_line0)
+ test("echo a ; ;", hook=hooks.error_line0)
+ test(";", hook=hooks.error_line0)
+ test("; ;", hook=hooks.error_line0)
+ test("; ; ;", hook=hooks.error_line0)
+ test("echo a ; ; echo b", hook=hooks.error_line0)
+ test(";;", hook=[hooks.error_line0, hooks.replace_double_semi_colon])
+ test(";;;", hook=[hooks.error_line0, hooks.replace_double_semi_colon])
+ test(";;;;;", hook=[hooks.error_line0, hooks.replace_double_semi_colon])
+ test("echo a ;; echo b", hook=[hooks.error_line0, hooks.replace_double_semi_colon])
+ test("echo a ;;;;; echo b", hook=[hooks.error_line0, hooks.replace_double_semi_colon])
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")
@@ -67,11 +77,14 @@ def suite_pipe(test):
test(" | cat", hook=hooks.error_line0)
test("echo a | export A=a; echo $A")
test("export A=a | cat; echo $A")
+ test("echo bonjour | | cat -e", hook=hooks.error_line0)
+ test("echo bonjour | asdf")
+ test("asdf | echo bonjour")
+ test("echo a ||| echo b")
test("ls " + 40 * " | ls", setup="touch a b c")
test("ls " + 80 * " | ls", setup="touch a b c")
test("echo bonjour " + 40 * " | cat -e")
test("echo bonjour " + 80 * " | cat -e")
- test("echo bonjour | | cat -e", hook=hooks.error_line0)
@suite(bonus=True)
@@ -176,7 +189,7 @@ def suite_parenthesis(test):
test("echo a | (cat -e | cat -e | cat -e) | cat -e")
test("(echo a) | (cat -e | cat -e | cat -e) | cat -e")
test("(echo a) | (cat -e | cat -e | cat -e) | (cat -e)")
- # test("(echo bonjour ; echo aurevoir) | (cat -e | cat -e) | cat -e")
+ test("(echo bonjour ; echo aurevoir) | (cat -e | cat -e) | cat -e")
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")
diff --git a/src/test/test.py b/src/test/test.py
index 00e5516..c37a865 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/12 17:07:22 by charles ### ########.fr #
+# Updated: 2020/09/17 11:05:46 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -29,7 +29,7 @@ class Test:
exports: {str: str} = {},
timeout: float = config.TIMEOUT,
signal=None,
- hook=None):
+ hook=[]):
"""Test class
cmd: command to execute
setup: command to execute before tested command
@@ -47,6 +47,8 @@ class Test:
self.timeout = timeout
self.signal = signal
self.hook = hook
+ if type(self.hook) is not list:
+ self.hook = [self.hook]
def run(self):
"""Run the test for minishell and the reference shell and print the result out"""
@@ -126,6 +128,7 @@ class Test:
files_content.append(None)
# sandbox.remove()
- if self.hook is not None:
- output = self.hook(output)
+ for h in self.hook:
+ output = h(output)
+
return Captured(output, process.returncode, files_content)