diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2020-10-06 17:06:30 +0200 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2020-10-06 17:06:30 +0200 |
| commit | 058491e35baa8bc73e14b48ceb765a3fe3c07e1f (patch) | |
| tree | 26b44b71ea12cb6cd825783d2ddebe0902c4999a | |
| parent | 1e713de9e5013c91495e0428179947f0764409a8 (diff) | |
| download | minishell_test-058491e35baa8bc73e14b48ceb765a3fe3c07e1f.tar.gz minishell_test-058491e35baa8bc73e14b48ceb765a3fe3c07e1f.tar.bz2 minishell_test-058491e35baa8bc73e14b48ceb765a3fe3c07e1f.zip | |
Added variable terminal size
| -rw-r--r-- | src/config.py | 7 | ||||
| -rw-r--r-- | src/hooks.py | 18 | ||||
| -rw-r--r-- | src/suite/suite.py | 21 | ||||
| -rw-r--r-- | src/suites/flow.py | 4 | ||||
| -rw-r--r-- | src/suites/preprocess.py | 4 | ||||
| -rw-r--r-- | src/test/result.py | 10 | ||||
| -rw-r--r-- | src/test/test.py | 28 |
7 files changed, 63 insertions, 29 deletions
diff --git a/src/config.py b/src/config.py index 47c08cd..0390194 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/16 11:33:54 by charles ### ########.fr # +# Updated: 2020/10/06 17:06:17 by cacharle ### ########.fr # # # # ############################################################################ # @@ -15,6 +15,7 @@ ################################################################################ import os +import shutil # run the bonus tests # can be changed with `export MINISHELL_TEST_BONUS=yes` in your shell rc file. @@ -88,3 +89,7 @@ VERBOSE_LEVEL = 1 MINISHELL_ERROR_BEGIN = os.path.basename(MINISHELL_PATH) + ": " REFERENCE_ERROR_BEGIN = REFERENCE_PATH + ": line 0: " + +TERM_COLS = shutil.get_terminal_size().columns +if TERM_COLS < 40: + raise RuntimeError("You're terminal isn't wide enough") diff --git a/src/hooks.py b/src/hooks.py index 1e01712..01319d1 100644 --- a/src/hooks.py +++ b/src/hooks.py @@ -6,11 +6,13 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 16:10:20 by charles #+# #+# # -# Updated: 2020/09/17 11:06:52 by charles ### ########.fr # +# Updated: 2020/10/06 09:12:52 by cacharle ### ########.fr # # # # ############################################################################ # import re +import os +import sys import config @@ -53,3 +55,17 @@ def replace_double_slash(output): def replace_double_semi_colon(output): """Replace occurence of double semi-colon by one""" return output.replace(";;", ";") + + +def platform_exit_status(darwin_status, linux_status, windows_status=None): + def hook(status): + name = os.uname().sysname + if name == "Darwin": + return status + elif name == "Linux": + return (darwin_status if status == linux_status else status) + else: + raise RuntimeError("This platform exit codes are not supported yet," + "feel free to contact me to add it.") + sys.exit(2) + return status diff --git a/src/suite/suite.py b/src/suite/suite.py index 63421f6..91cfaa4 100644 --- a/src/suite/suite.py +++ b/src/suite/suite.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:29 by charles #+# #+# # -# Updated: 2020/09/12 17:07:00 by charles ### ########.fr # +# Updated: 2020/10/06 17:04:25 by cacharle ### ########.fr # # # # ############################################################################ # @@ -86,12 +86,21 @@ class Suite: """Append a test to the suite""" self.tests.append(test) + BLUE_CHARS = "\033[34m" + CLOSE_CHARS = "\033[0m" + def run(self): """Run all test in the suite""" if config.VERBOSE_LEVEL == 0: print(self.name + ": ", end="") else: - print("{} {:#<41}".format("#" * 39, self.name + " ")) + print("{}{} {:#<{width}}{}".format( + self.BLUE_CHARS, + "#" * (config.TERM_COLS // 2 - 1), + self.name + " ", + self.CLOSE_CHARS, + width=config.TERM_COLS // 2 + )) for t in self.tests: t.run() if config.VERBOSE_LEVEL == 0: @@ -119,10 +128,10 @@ class Suite: continue pass_sum += pass_total fail_sum += fail_total - print("{:<30} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m" - .format(s.name, pass_total, fail_total)) - print("{:<30} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m" - .format("TOTAL", pass_sum, fail_sum)) + print("{:.<{width}} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m" + .format(s.name + " ", pass_total, fail_total, width=config.TERM_COLS - 22)) + print("{:.<{width}} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m" + .format("TOTAL ", pass_sum, fail_sum, width=config.TERM_COLS - 22)) @classmethod def save_log(cls): diff --git a/src/suites/flow.py b/src/suites/flow.py index babfd65..4f61283 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/17 11:03:23 by charles ### ########.fr # +# Updated: 2020/10/06 16:16:12 by cacharle ### ########.fr # # # # ############################################################################ # @@ -80,7 +80,7 @@ def suite_pipe(test): test("echo bonjour | | cat -e", hook=hooks.error_line0) test("echo bonjour | asdf") test("asdf | echo bonjour") - test("echo a ||| echo b") + test("echo a ||| echo b", hook=hooks.error_line0) test("ls " + 40 * " | ls", setup="touch a b c") test("ls " + 80 * " | ls", setup="touch a b c") test("echo bonjour " + 40 * " | cat -e") diff --git a/src/suites/preprocess.py b/src/suites/preprocess.py index bf88c49..fde8cc5 100644 --- a/src/suites/preprocess.py +++ b/src/suites/preprocess.py @@ -6,7 +6,7 @@ # By: juligonz <juligonz@student.42.fr> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:25:00 by charles #+# #+# # -# Updated: 2020/09/15 18:34:34 by charles ### ########.fr # +# Updated: 2020/10/06 16:31:11 by cacharle ### ########.fr # # # # **************************************************************************** # @@ -217,7 +217,7 @@ def suite_escape(test): test(r"/bin/echo ' \$? '") test(r"/bin/echo ' \\ '") test(r"/bin/echo ' \\\ '") - test("echo \\") + test("echo \\") # noting on linux test("echo \"\\\"\"'bonjour'") diff --git a/src/test/result.py b/src/test/result.py index c64f20a..5e7c2e9 100644 --- a/src/test/result.py +++ b/src/test/result.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:17:34 by charles #+# #+# # -# Updated: 2020/09/11 22:20:03 by charles ### ########.fr # +# Updated: 2020/10/06 16:56:30 by cacharle ### ########.fr # # # # ############################################################################ # @@ -80,10 +80,10 @@ class Result: return self.green('.') if self.passed else self.red('!') elif config.VERBOSE_LEVEL == 1: printed = self.escaped_cmd[:] - if len(printed) > 70: - printed = printed[:67] + "..." - fmt = self.green("{:74} [PASS]") if self.passed else self.red("{:74} [FAIL]") - return fmt.format(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: diff --git a/src/test/test.py b/src/test/test.py index c37a865..da013d1 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/17 11:05:46 by charles ### ########.fr # +# Updated: 2020/10/06 15:54:12 by cacharle ### ########.fr # # # # ############################################################################ # @@ -29,15 +29,17 @@ class Test: exports: {str: str} = {}, timeout: float = config.TIMEOUT, signal=None, - hook=[]): - """Test class - cmd: command to execute - setup: command to execute before tested command - files: files to watch (check content after test) - exports: exported variables - timeout: maximum amount of time taken by the test - signal: signal to send to the test - hook: function to execute on the output of the test + hook=[], + hook_status=[]): + """ Test class + cmd: command to execute + setup: command to execute before tested command + files: files to watch (check content after test) + exports: exported variables + timeout: maximum amount of time taken by the test + signal: signal to send to the test + hook: function to execute on the output of the test + hook_status: function to execute on status code """ self.cmd = cmd self.setup = setup @@ -47,11 +49,12 @@ class Test: self.timeout = timeout self.signal = signal self.hook = hook + self.hook_status = hook_status 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""" + """ Run the test for minishell and the reference shell and print the result out """ expected = self._run_sandboxed(config.REFERENCE_PATH, config.REFERENCE_ARGS + ["-c"]) actual = self._run_sandboxed(config.MINISHELL_PATH, ["-c"]) s = self.cmd @@ -130,5 +133,6 @@ class Test: # sandbox.remove() for h in self.hook: output = h(output) - + for h in self.hook_status: + process.returncode = h(process.returncode) return Captured(output, process.returncode, files_content) |
