aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--args.py12
-rw-r--r--config.py14
-rwxr-xr-xmain.py20
-rw-r--r--suite.py20
-rw-r--r--suites/__init__.py12
-rw-r--r--suites/builtin.py12
-rw-r--r--suites/cmd.py152
-rw-r--r--suites/operation.py12
-rw-r--r--suites/parenthesis.py12
-rw-r--r--suites/preprocess.py21
-rw-r--r--suites/status.py12
-rw-r--r--test.py70
12 files changed, 305 insertions, 64 deletions
diff --git a/args.py b/args.py
index 724056e..60b09c4 100644
--- a/args.py
+++ b/args.py
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# args.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:32 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:33 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
import argparse
diff --git a/config.py b/config.py
index 632591a..87d86e7 100644
--- a/config.py
+++ b/config.py
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# config.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:19 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:20 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
# Minishell configuration file
import os
@@ -21,7 +33,7 @@ SANDBOX_PATH = "sandbox"
EXECUTABLES_PATH = "./bin"
# commands available in test"
-AVAILABLE_COMMANDS = ["cat", "touch", "env", "ls", "grep"]
+AVAILABLE_COMMANDS = ["cat", "touch", "env", "ls", "grep", "bash"]
# $PATH environment variable passed to the shell
PATH_VARIABLE = os.path.abspath(EXECUTABLES_PATH)
diff --git a/main.py b/main.py
index 0210633..b3437a9 100755
--- a/main.py
+++ b/main.py
@@ -1,8 +1,21 @@
#!/usr/bin/python3
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# main.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 15:11:52 by charles #+# #+# #
+# Updated: 2020/07/15 15:11:52 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
import os
import sys
import shutil
+import distutils.spawn
import config
from args import parse_args
@@ -15,10 +28,11 @@ import suites.parenthesis
import suites.status
def main():
- if not os.path.exists(config.EXECUTABLES_PATH):
- os.mkdir(config.EXECUTABLES_PATH)
+ if os.path.exists(config.EXECUTABLES_PATH):
+ shutil.rmtree(config.EXECUTABLES_PATH)
+ os.mkdir(config.EXECUTABLES_PATH)
for cmd in config.AVAILABLE_COMMANDS:
- shutil.copy(os.path.join("/usr/bin", cmd), # FIXME search whole PATH
+ shutil.copy(distutils.spawn.find_executable(cmd), # FIXME search whole PATH
os.path.join(config.EXECUTABLES_PATH, cmd))
args = parse_args()
diff --git a/suite.py b/suite.py
index 7d14230..fefd4e2 100644
--- a/suite.py
+++ b/suite.py
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# suite.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:29 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:29 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
import config
from test import Test
@@ -56,13 +68,19 @@ class Suite:
@classmethod
def summarize(cls):
+ pass_sum = 0
+ fail_sum = 0
print("\nSummary:")
for s in cls.available:
(pass_total, fail_total) = s.total()
if pass_total == -1:
continue
- print("{:<15} \033[32m{:2} [PASS]\033[0m \033[31m{:2} [FAIL]\033[0m"
+ pass_sum += pass_total
+ fail_sum += fail_total
+ print("{:<15} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m"
.format(s.name, pass_total, fail_total))
+ print("{:<15} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m"
+ .format("TOTAL", pass_sum, fail_sum))
@classmethod
def save_log(cls):
diff --git a/suites/__init__.py b/suites/__init__.py
index 736c3c5..138a69b 100644
--- a/suites/__init__.py
+++ b/suites/__init__.py
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# __init__.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:48 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:48 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
import os
import glob
diff --git a/suites/builtin.py b/suites/builtin.py
index 666a744..22c3683 100644
--- a/suites/builtin.py
+++ b/suites/builtin.py
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# builtin.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:43 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:44 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
import config
from suite import suite
diff --git a/suites/cmd.py b/suites/cmd.py
index d4dc2e5..a9fcde7 100644
--- a/suites/cmd.py
+++ b/suites/cmd.py
@@ -1,6 +1,21 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# cmd.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 15:11:46 by charles #+# #+# #
+# Updated: 2020/07/15 18:21:56 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import distutils
+
import config
from suite import suite
+
@suite
def suite_redirection(test):
test("echo bonjour > test", setup="", files=["test"])
@@ -94,41 +109,108 @@ def suite_cmd_error(test):
@suite
def suite_cmd_variable(test):
+ test("A=a bash -c 'echo $A'")
+ test("A=a B=b bash -c 'echo $A$B'")
+ test("A=a B=b C=c D=d E=e F=f G=g H=h bash -c 'echo $A$B$C$D$E$F$G$H'")
+ test("A=a A=bonjour bash -c 'echo $A'")
+ test("A=aA=bonjour bash -c 'echo $A'")
+ test("BONJOURJESUIS=a bash -c 'echo $BONJOURJESUIS'")
+ test("bonjourjesuis=a bash -c 'echo $bonjourjesuis'")
+ test("bonjour_je_suis=a bash -c 'echo $bonjour_je_suis'")
+ test("BONJOURJESUIS1=a bash -c 'echo $BONJOURJESUIS1'")
+ test("bO_nJq123o__1ju_je3234sui__a=a bash -c 'echo $bO_nJq123o__1ju_je3234sui__a'")
+ test("a0123456789=a bash -c 'echo $a0123456789")
+ test("abcdefghijklmnopqrstuvwxyz=a bash -c 'echo $abcdefghijklmnopqrstuvwxyz'")
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZ=a bash -c 'echo $ABCDEFGHIJKLMNOPQRSTUVWXYZ'")
+ test("__________________________=a bash -c 'echo $__________________________'")
+ test("_bonjour_=a bash -c 'echo $_bonjour_'")
+ test("_=a bash -c 'echo $_a'")
+ test("1=a bash -c 'echo $1'")
+ test("BONJOURJESUIS =a bash -c 'echo $BONJOURJESUIS '")
+ test("BONJOURJESUIS= a bash -c 'echo $BONJOURJESUIS'")
+ test(r"BONJOUR\\JESUIS=a bash -c 'echo $BONJOUR\\JESUIS'")
+ test(r"BONJOUR\'JESUIS=a bash -c 'echo $BONJOUR\'JESUIS'")
+ test(r'BONJOUR\"JESUIS=a bash -c "echo $BONJOUR\"JESUIS"')
+ test(r"BONJOUR\$JESUIS=a bash -c 'echo $BONJOUR\$JESUIS'")
+ test(r"BONJOUR\&JESUIS=a bash -c 'echo $BONJOUR\&JESUIS'")
+ test(r"BONJOUR\|JESUIS=a bash -c 'echo $BONJOUR\|JESUIS'")
+ test(r"BONJOUR\;JESUIS=a bash -c 'echo $BONJOUR\;JESUIS'")
+ test(r"BONJOUR\_JESUIS=a bash -c 'echo $BONJOUR\_JESUIS'")
+ test(r"BONJOUR\0JESUIS=a bash -c 'echo $BONJOUR\0JESUIS'")
+ test(r"\B\O\N\ \ \ \ \ \ \ JOURJESUIS=a bash -c 'echo $\B\O\N\ \ \ \ \ \ \ JOURJESUIS'")
+ test(r"A=\B\O\N\ \ \ \ \ \ \ JOURJESUIS bash -c 'echo $A'")
+ test(r"A='bonjour je suis charles' bash -c 'echo $A'")
+ test(r'A="bonjour je suis charles" bash -c "echo $A"')
+ test(r"A==a bash -c 'echo $A'")
+ test(r"A===a bash -c 'echo $A'")
+ test(r"A====a bash -c 'echo $A'")
+ test(r"A=====a bash -c 'echo $A'")
+ test(r"A======a bash -c 'echo $A'")
+ test(r"A=a=a=a=a=a bash -c 'echo $A'")
+
+ test("A=a; echo $A")
+ test("A=a B=b; echo $A$B")
+ test("A=a B=b C=c D=d E=e F=f G=g H=h; echo $A$B$C$D$E$F$G$H")
+ test("A=a A=bonjour; echo $A")
+ test("A=aA=bonjour; echo $A")
+ test("BONJOURJESUIS=a; echo $BONJOURJESUIS")
+ test("bonjourjesuis=a; echo $bonjourjesuis")
+ test("bonjour_je_suis=a; echo $bonjour_je_suis")
+ test("BONJOURJESUIS1=a; echo $BONJOURJESUIS1")
+ test("bO_nJq123o__1ju_je3234sui__a=a; echo $bO_nJq123o__1ju_je3234sui__a")
+ test("a0123456789=a; echo $a0123456789")
+ test("abcdefghijklmnopqrstuvwxyz=a; echo $abcdefghijklmnopqrstuvwxyz")
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZ=a; echo $ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+ test("__________________________=a; echo $__________________________")
+ test("_bonjour_=a; echo $_bonjour_")
+ test("_=a; echo $_a")
+ test("1=a; echo $1")
+ test("BONJOURJESUIS =a; echo $BONJOURJESUIS ")
+ test("BONJOURJESUIS= a; echo $BONJOURJESUIS")
+ test(r"BONJOUR\\JESUIS=a; echo $BONJOUR\\JESUIS")
+ test(r"BONJOUR\'JESUIS=a; echo $BONJOUR\'JESUIS")
+ test(r'BONJOUR\"JESUIS=a; echo $BONJOUR\"JESUIS')
+ test(r"BONJOUR\$JESUIS=a; echo $BONJOUR\$JESUIS")
+ test(r"BONJOUR\&JESUIS=a; echo $BONJOUR\&JESUIS")
+ test(r"BONJOUR\|JESUIS=a; echo $BONJOUR\|JESUIS")
+ test(r"BONJOUR\;JESUIS=a; echo $BONJOUR\;JESUIS")
+ test(r"BONJOUR\_JESUIS=a; echo $BONJOUR\_JESUIS")
+ test(r"BONJOUR\0JESUIS=a; echo $BONJOUR\0JESUIS")
+ test(r"\B\O\N\ \ \ \ \ \ \ JOURJESUIS=a; echo $\B\O\N\ \ \ \ \ \ \ JOURJESUIS")
+ test(r"A=\B\O\N\ \ \ \ \ \ \ JOURJESUIS; echo $A")
+ test(r"A='bonjour je suis charles'; echo $A")
+ test(r'A="bonjour je suis charles"; echo $A')
+ test(r"A==a; echo $A")
+ test(r"A===a; echo $A")
+ test(r"A====a; echo $A")
+ test(r"A=====a; echo $A")
+ test(r"A======a; echo $A")
+ test(r"A=a=a=a=a=a; echo $A")
+
+ test("PATH=a ls")
+ test("PATH=a echo aa")
test("A=a echo $A")
test("A=a B=b echo $A$B")
test("A=a B=b C=c D=d E=e F=f G=g H=h echo $A$B$C$D$E$F$G$H")
- test("A=a A=bonjour echo $A")
- test("A=aA=bonjour echo $A")
- test("BONJOURJESUIS=a echo $BONJOURJESUIS")
- test("bonjourjesuis=a echo $bonjourjesuis")
- test("bonjour_je_suis=a echo $bonjour_je_suis")
- test("BONJOURJESUIS1=a echo $BONJOURJESUIS1")
- test("bO_nJq123o__1ju_je3234sui__a=a echo $bO_nJq123o__1ju_je3234sui__a")
- test("a0123456789=a echo $a0123456789")
- test("abcdefghijklmnopqrstuvwxyz=a echo $abcdefghijklmnopqrstuvwxyz")
- test("ABCDEFGHIJKLMNOPQRSTUVWXYZ=a echo $ABCDEFGHIJKLMNOPQRSTUVWXYZ")
- test("__________________________=a echo $__________________________")
- test("_bonjour_=a echo $_bonjour_")
- test("_=a echo $_a")
- test("1=a echo $1")
- test("BONJOURJESUIS =a echo $BONJOURJESUIS ")
- test("BONJOURJESUIS= a echo $BONJOURJESUIS")
- test(r"BONJOUR\\JESUIS=a echo $BONJOUR\\JESUIS")
- test(r"BONJOUR\'JESUIS=a echo $BONJOUR\'JESUIS")
- test(r'BONJOUR\"JESUIS=a echo $BONJOUR\"JESUIS')
- test(r"BONJOUR\$JESUIS=a echo $BONJOUR\$JESUIS")
- test(r"BONJOUR\&JESUIS=a echo $BONJOUR\&JESUIS")
- test(r"BONJOUR\|JESUIS=a echo $BONJOUR\|JESUIS")
- test(r"BONJOUR\;JESUIS=a echo $BONJOUR\;JESUIS")
- test(r"BONJOUR\_JESUIS=a echo $BONJOUR\_JESUIS")
- test(r"BONJOUR\0JESUIS=a echo $BONJOUR\0JESUIS")
- test(r"\B\O\N\ \ \ \ \ \ \ JOURJESUIS=a echo $\B\O\N\ \ \ \ \ \ \ JOURJESUIS")
- test(r"A=\B\O\N\ \ \ \ \ \ \ JOURJESUIS echo $A")
- test(r"A='bonjour je suis charles' echo $A")
- test(r'A="bonjour je suis charles" echo $A')
- test(r"A==a echo $A")
- test(r"A===a echo $A")
- test(r"A====a echo $A")
- test(r"A=====a echo $A")
- test(r"A======a echo $A")
- test(r"A=a=a=a=a=a echo $A")
+ test("A=$PATH bash -c 'echo $A'")
+ test("A=\"$PATH je suis\" bash -c 'echo $A'")
+ test("A='$PATH je suis' bash -c 'echo $A'")
+ test("$TEST bash -c 'echo $A'", setup="export TEST='A=a'")
+
+@suite
+def suite_cmd_path(test):
+ ls_path = distutils.spawn.find_executable("ls")
+ cat_path = distutils.spawn.find_executable("cat")
+
+ test(ls_path, setup="touch a b c")
+ test(ls_path + " -l", setup="touch a b c")
+ test("./bonjour", setup="touch a b c; cp {} bonjour".format(ls_path))
+ test("./bonjour -l", setup="touch a b c; cp {} bonjour".format(ls_path))
+ test("./somedir/bonjour -l",
+ setup="mkdir somedir; touch a b c; touch somedir/d somedir/e;" +
+ "cp {} somedir/bonjour".format(ls_path))
+
+ test("./ls . a b c",
+ setup="touch a b c; echo bonjour > a; cp {} ls".format(cat_path))
+ test("ls . a b c",
+ setup="touch a b c; echo bonjour > a; cp {} ls".format(cat_path))
diff --git a/suites/operation.py b/suites/operation.py
index 8d912d3..fd54f00 100644
--- a/suites/operation.py
+++ b/suites/operation.py
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# operation.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:52 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:53 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
from suite import suite
@suite
diff --git a/suites/parenthesis.py b/suites/parenthesis.py
index 30f1cce..a06fdda 100644
--- a/suites/parenthesis.py
+++ b/suites/parenthesis.py
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# parenthesis.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:57 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:57 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
from suite import suite
@suite
diff --git a/suites/preprocess.py b/suites/preprocess.py
index 34dac00..891747e 100644
--- a/suites/preprocess.py
+++ b/suites/preprocess.py
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# preprocess.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:25:00 by charles #+# #+# #
+# Updated: 2020/07/15 18:25:01 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
import config
from suite import suite
@@ -119,6 +131,15 @@ def suite_glob(test):
test("echo */a", setup="mkdir d; touch d/a d/b d/c")
test("echo d/*", setup="mkdir d; touch d/a d/b d/c")
+ test("*")
+ test("*", setup="touch a b c")
+ test("*.c", setup="touch a b c foo.c bar.c")
+ test("src/*.c", setup="mkdir src; touch src/a src/b src/c src/foo.c src/bar.c")
+ test("*/*.c", setup="mkdir src; touch src/a src/b src/c src/foo.c src/bar.c")
+ test("*/*.c",
+ setup="mkdir src; touch src/a src/b src/c src/foo.c src/bar.c;\
+ mkdir inc; touch inc/a inc/b inc/c inc/foo.c inc/bar.c")
+
@suite
def suite_escape(test):
test(r"echo \a")
diff --git a/suites/status.py b/suites/status.py
index f116ec1..62c076e 100644
--- a/suites/status.py
+++ b/suites/status.py
@@ -1,3 +1,15 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# status.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:40 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:40 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
from suite import suite
@suite
diff --git a/test.py b/test.py
index 7f890f8..de8de07 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/07/15 12:49:46 by charles ### ########.fr #
+# Updated: 2020/07/15 18:14:28 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -17,22 +17,31 @@ import shutil
import config
class Captured:
- def __init__(self, output: str, status: int, files_content: [str]):
+ def __init__(self, output: str, status: int, files_content: [str], is_timeout: bool = False):
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)
+ elif l.find(config.REFERENCE_PATH + ": ") == 0:
+ lines[i] = l.replace(config.REFERENCE_PATH + ": ", config.MINISHELL_ERROR_BEGIN, 1)
+
self.output = '\n'.join(lines)
- # self.output = output
self.status = status
self.files_content = files_content
+ self.is_timeout = is_timeout
def __eq__(self, other: 'Result') -> bool:
+ if self.is_timeout and other.is_timeout:
+ return True
return (self.output == other.output and
self.status == other.status and
all([x == y for x, y in zip(self.files_content, other.files_content)]))
+ @staticmethod
+ def timeout():
+ return Captured("", 0, [], is_timeout = True)
+
class Result:
RED_CHARS = "\033[31m"
GREEN_CHARS = "\033[32m"
@@ -123,6 +132,8 @@ class Result:
return self.bold(self.blue(prefix + " " + title))
def file_diff(self, file_name: str, expected: str, actual: str) -> str:
+ if expected == actual:
+ return ""
return (
self.indicator("FILE {}".format(file_name), "|#") + '\n'
+ self.expected_header + '\n'
@@ -135,18 +146,22 @@ class Result:
return '\n'.join([self.file_diff(n, e, a) for n, e, a in
zip(self.file_names,
self.expected.files_content,
- self.actual.files_content)])
+ self.actual.files_content)
+ if e != a])
def output_diff(self) -> str:
- return (
- self.indicator("STATUS: expected {} actual {}"
- .format(self.expected.status, self.actual.status), "| ")
- + '\n'
- + self.expected_header + '\n'
- + self.cat_e(self.expected.output)
- + self.actual_header + '\n'
- + self.cat_e(self.actual.output)
- )
+ out = ""
+ if self.actual.is_timeout:
+ return "TIMEOUT\n"
+ if self.expected.status != self.actual.status:
+ out += self.indicator("STATUS: expected {} actual {}"
+ .format(self.expected.status, self.actual.status), "| ") + '\n'
+ if self.expected.output != self.actual.output:
+ out += (self.expected_header + '\n'
+ + self.cat_e(self.expected.output)
+ + self.actual_header + '\n'
+ + self.cat_e(self.actual.output))
+ return out
def full_diff(self) -> str:
return (self.indicator("WITH {}".format(self.cmd), "|>") + '\n'
@@ -190,22 +205,29 @@ class Test:
pass
if self.setup != "":
try:
- setup_status = subprocess.run(self.setup, shell=True, cwd=config.SANDBOX_PATH, check=True)
+ setup_status = subprocess.run(
+ self.setup, shell=True, cwd=config.SANDBOX_PATH, check=True)
except subprocess.CalledProcessError as e:
print("Error: `{}` setup command failed for `{}`\n\twith '{}'"
.format(setup, cmd, e.stderr.decode().strip()))
sys.exit(1)
- # TODO: add timeout
- # https://docs.python.org/3/library/subprocess.html#using-the-subprocess-module
- 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,
- 'TERM': 'xterm-256color',
- **self.exports},
- timeout=1)
+ try:
+ 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,
+ 'TERM': 'xterm-256color',
+ **self.exports
+ },
+ timeout=0.5
+ )
+ except subprocess.TimeoutExpired:
+ return Captured.timeout()
+
output = process_status.stdout.decode()
# capture watched files content