diff options
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | config.py | 11 | ||||
| -rwxr-xr-x | main.py | 8 | ||||
| -rw-r--r-- | suites.py | 24 | ||||
| -rw-r--r-- | utils.py | 10 |
5 files changed, 50 insertions, 4 deletions
@@ -1,2 +1,3 @@ *__pycache__* *.log +bin @@ -1,4 +1,5 @@ # Minishell configuration file +import os # minishell dir path MINISHELL_DIR = ".." @@ -16,6 +17,15 @@ LOG_PATH = "result.log" # path to the sandbox directory SANDBOX_PATH = "sandbox" +# where the availables commands are stored +EXECUTABLES_PATH = "./bin" + +# commands available in test" +AVAILABLE_COMMANDS = ["cat", "touch"] + +# $PATH environment variable passed to the shell +PATH_VARIABLE = os.path.abspath(EXECUTABLES_PATH) + LOREM = """ Mollitia asperiores assumenda excepturi et ipsa. Nihil corporis facere aut a rem consequatur. Quas molestiae corporis et quibusdam maiores. Molestiae sed unde aut at sed. @@ -35,7 +45,6 @@ LOREM = ' '.join(LOREM.split('\n')) # do not edit -import os MINISHELL_PATH = os.path.abspath( os.path.join(MINISHELL_DIR, MINISHELL_EXEC) @@ -1,5 +1,6 @@ #!/usr/bin/python3 +import os import sys import argparse import shutil @@ -9,11 +10,18 @@ import config import suites 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 + os.path.join(config.EXECUTABLES_PATH, cmd)) + try: suites.suite_quote() suites.suite_echo() suites.suite_redirection() suites.suite_edgecases() + suites.suite_cmd_error() except KeyboardInterrupt: shutil.rmtree(config.SANDBOX_PATH) @@ -77,7 +77,31 @@ def suite_redirection(): test("echo bonjour>>test>je>>suis", setup="", files=["test", "je", "suis"]) test("cat<test<je", setup="echo bonjour > test; echo salut > je") + test("echo bonjour > a'b'c'd'e'f'g'h'i'j'k'l'm'n'o'p'q'r's't'u'v'w'x'y'z'", files=["abcdefghijklmnopqrstuvzxyz"]) + test('echo bonjour > a"b"c"d"e"f"g"h"i"j"k"l"m"n"o"p"q"r"s"t"u"v"w"x"y"z"', files=["abcdefghijklmnopqrstuvzxyz"]) + test('echo bonjour > a\'b\'c"d"e\'f\'g"h"i\'j\'k"l"m\'n\'o"p\'q\'r"s\'t\'u"v"w"x"y\'z\'', files=["abcdefghijklmnopqrstuvzxyz"]) @suite def suite_edgecases(): test('echo "\\"" >>a"b""c" ', files=["abc"]) + +@suite +def suite_cmd_error(): + test(">") + test(">>") + test("<") + test("echo >") + test("echo >>") + test("echo <") + + test("> test", files=["test"]) + test(">> test", files=["test"]) + test("< test", setup="touch test") + + test("echo foo >>> bar") + test("echo foo >>>> bar") + test("echo foo >>>>> bar") + + test("cat <<< bar", setup="echo bonjour > bar") + test("cat <<<< bar", setup="echo bonjour > bar") + test("cat <<<<< bar", setup="echo bonjour > bar") @@ -108,7 +108,8 @@ def run_sandboxed(program: str, cmd: str, setup: str = None, files: [str] = []) process_status = subprocess.run([program, "-c", cmd], stderr=subprocess.STDOUT, stdout=subprocess.PIPE, - cwd=config.SANDBOX_PATH) + cwd=config.SANDBOX_PATH, + env={'PATH': config.PATH_VARIABLE}) output = process_status.stdout.decode() output_files = [] @@ -144,8 +145,11 @@ def test(cmd: str, setup: str = None, files: [str] = []): if not verbose: put_result(passed, cmd) - if verbose and not passed: - print(diff(cmd, expected, actual, files, expected_files, actual_files, color=True)) + if verbose: + if not passed: + print(diff(cmd, expected, actual, files, expected_files, actual_files, color=True)) + else: + put_result(passed, cmd) if runned_suites.get(current_suite) is None: runned_suites[current_suite] = [] |
