aboutsummaryrefslogtreecommitdiff
path: root/minishell_test/test
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-02-27 16:16:14 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-02-27 16:16:14 +0100
commit632f88fd315626bf3196024f2a67c5288ea56333 (patch)
treea041d430ac73cb6d14d61370b168b7ea1c28a2a6 /minishell_test/test
parent86355a6fd7375f954bf92cb49a14c718610c4d60 (diff)
parent820d1ee00975d2e7859e4b2aded88dbf56a3b347 (diff)
downloadminishell_test-632f88fd315626bf3196024f2a67c5288ea56333.tar.gz
minishell_test-632f88fd315626bf3196024f2a67c5288ea56333.tar.bz2
minishell_test-632f88fd315626bf3196024f2a67c5288ea56333.zip
Merge branch 'config'
Diffstat (limited to 'minishell_test/test')
-rw-r--r--minishell_test/test/captured.py15
-rw-r--r--minishell_test/test/result.py34
-rw-r--r--minishell_test/test/test.py30
3 files changed, 32 insertions, 47 deletions
diff --git a/minishell_test/test/captured.py b/minishell_test/test/captured.py
index 7db9739..6ba861b 100644
--- a/minishell_test/test/captured.py
+++ b/minishell_test/test/captured.py
@@ -6,13 +6,14 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/11 12:16:25 by charles #+# #+# #
-# Updated: 2021/02/05 17:47:10 by charles ### ########.fr #
+# Updated: 2021/02/27 16:15:13 by cacharle ### ########.fr #
# #
# ############################################################################ #
+import re
from typing import List, Optional
-import minishell_test.config as config
+from minishell_test import config
class Captured:
@@ -29,12 +30,12 @@ class Captured:
files_content: content of the files altered by the command
is_timeout: the command has timed out
"""
+
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)
+ for i, line in enumerate(lines):
+ lines[i] = line = re.sub("line [01]: ", "", lines[i], 1)
+ if line.startswith(config.SHELL_REFERENCE_PREFIX):
+ lines[i] = config.MINISHELL_PREFIX + line[len(config.SHELL_REFERENCE_PREFIX):]
self.output = '\n'.join(lines)
self.status = status
diff --git a/minishell_test/test/result.py b/minishell_test/test/result.py
index fe465e5..87eeb5d 100644
--- a/minishell_test/test/result.py
+++ b/minishell_test/test/result.py
@@ -6,15 +6,14 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/11 12:17:34 by charles #+# #+# #
-# Updated: 2021/02/24 08:56:03 by cacharle ### ########.fr #
+# Updated: 2021/02/27 12:28:20 by cacharle ### ########.fr #
# #
# ############################################################################ #
-import sys
import re
from typing import Match, List, Optional
-import minishell_test.config as config
+from minishell_test import config
from minishell_test.test.captured import Captured
@@ -42,31 +41,18 @@ class BaseResult:
def __repr__(self):
"""Returns a representation of the result based on the verbosity"""
- if config.VERBOSE_LEVEL == 0:
- return self.green('.') if self.passed else self.red('!')
- if config.VERBOSE_LEVEL == 1:
- printed = self._escaped_cmd[:]
- if config.SHOW_RANGE:
- printed = "{:2}: ".format(self.index) + printed
- if len(printed) > config.TERM_COLS - 7:
- printed = printed[:config.TERM_COLS - 10] + "..."
- fmt = self.green("{:{width}} [PASS]") if self.passed else self.red("{:{width}} [FAIL]")
- return fmt.format(printed, width=config.TERM_COLS - 7)
- elif config.VERBOSE_LEVEL == 2:
- return self.full_diff()
- else:
- raise RuntimeError("Invalid verbose level")
+ printed = self._escaped_cmd[:]
+ if config.SHOW_RANGE:
+ printed = "{:2}: ".format(self.index) + printed
+ if len(printed) > config.TERM_COLS - 7:
+ printed = printed[:config.TERM_COLS - 10] + "..."
+ fmt = self.green("{:{width}} [PASS]") if self.passed else self.red("{:{width}} [FAIL]")
+ return fmt.format(printed, width=config.TERM_COLS - 7)
def put(self, index: int) -> None:
"""Print a summary of the result"""
- if config.VERBOSE_LEVEL == 2 and self.passed:
- return
self.index = index
- print(self, end="")
- if config.VERBOSE_LEVEL == 0:
- sys.stdout.flush()
- else:
- print()
+ print(self)
def indicator(self, title: str, prefix: str) -> str:
return self.bold(self.blue(prefix + " " + title))
diff --git a/minishell_test/test/test.py b/minishell_test/test/test.py
index ff60522..c0e402f 100644
--- a/minishell_test/test/test.py
+++ b/minishell_test/test/test.py
@@ -6,19 +6,20 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/06/16 21:48:50 by charles #+# #+# #
-# Updated: 2021/02/24 09:09:39 by cacharle ### ########.fr #
+# Updated: 2021/02/27 12:19:15 by cacharle ### ########.fr #
# #
# ############################################################################ #
import os
import sys
import subprocess
+from pathlib import Path
from typing import Optional, List, Dict, Union, Callable
-import minishell_test.config as config
+from minishell_test import config
from minishell_test.test.captured import Captured
from minishell_test.test.result import Result, LeakResult
-import minishell_test.sandbox as sandbox
+from minishell_test import sandbox
HookType = Union[Callable[[str], str], List[Callable[[str], str]]]
HookStatusType = Union[Callable[[int], int], List[Callable[[int], int]]]
@@ -31,7 +32,7 @@ class Test:
setup: str = "",
files: List[str] = [],
exports: Dict[str, str] = {},
- timeout: float = config.TIMEOUT,
+ timeout: float = config.TIMEOUT_TEST,
hook: HookType = [],
hook_status: HookStatusType = [],
):
@@ -64,18 +65,16 @@ class Test:
self.hook = []
self.hook_status = []
captured = self._run_sandboxed([*config.VALGRIND_CMD, "-c"])
- if config.VERBOSE_LEVEL == 2:
- print(captured.output)
self.result = LeakResult(self.full_cmd, captured)
self.result.put(index)
return
- expected = self._run_sandboxed([config.REFERENCE_PATH, *config.REFERENCE_ARGS, "-c"])
- actual = self._run_sandboxed([config.MINISHELL_PATH, "-c"])
+ expected = self._run_sandboxed([config.SHELL_REFERENCE_PATH, *config.SHELL_REFERENCE_ARGS, "-c"])
+ actual = self._run_sandboxed([config.MINISHELL_EXEC_PATH, "-c"])
self.result = Result(self.full_cmd, self.files, expected, actual)
self.result.put(index)
- def _run_sandboxed(self, shell_cmd: List[str]) -> Captured:
+ def _run_sandboxed(self, shell_cmd: List[Union[str, Path]]) -> Captured:
""" Run the command in a sandbox environment """
with sandbox.context():
if self.setup != "":
@@ -83,7 +82,7 @@ class Test:
subprocess.run(
self.setup,
shell=True,
- cwd=config.SANDBOX_PATH,
+ cwd=config.SANDBOX_DIR,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
check=True
@@ -97,7 +96,7 @@ class Test:
sys.exit(1)
return self._run_capture(shell_cmd)
- def _run_capture(self, shell_cmd: List[str]) -> Captured:
+ def _run_capture(self, shell_cmd: List[Union[str, Path]]) -> Captured:
""" Capture the output (stdout and stderr)
Capture the content of the watched files after the command is run
"""
@@ -106,9 +105,9 @@ class Test:
[*shell_cmd, self.cmd],
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
- cwd=config.SANDBOX_PATH,
+ cwd=config.SANDBOX_DIR,
env={
- 'PATH': config.PATH_VARIABLE,
+ 'PATH': config.SHELL_PATH_VARIABLE,
'TERM': 'xterm-256color',
**self.exports,
},
@@ -117,7 +116,7 @@ class Test:
# https://docs.python.org/3/library/subprocess.html#subprocess.Popen.communicate
try:
stdout, _ = process.communicate(
- timeout=(self.timeout if not config.CHECK_LEAKS else config.CHECK_LEAKS_TIMEOUT))
+ timeout=(self.timeout if not config.CHECK_LEAKS else config.TIMEOUT_LEAKS))
except subprocess.TimeoutExpired:
process.kill()
# _, _ = process.communicate(timeout=2)
@@ -131,7 +130,7 @@ class Test:
files_content: List[Optional[str]] = []
for file_name in self.files:
try:
- with open(os.path.join(config.SANDBOX_PATH, file_name), "rb") as f:
+ with open(os.path.join(config.SANDBOX_DIR, file_name), "rb") as f:
files_content.append(f.read().decode())
except FileNotFoundError:
files_content.append(None)
@@ -156,7 +155,6 @@ class Test:
@classmethod
def try_run(cls, cmd: str) -> str:
- config.VERBOSE_LEVEL = 2
test = Test(cmd)
test.run(0)
if isinstance(test.result, LeakResult):