From dcb4a6453ca1ca6789c3121a739f373abeaba14c Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Fri, 11 Sep 2020 15:52:01 +0200 Subject: Added output hook and sort_lines hook --- src/config.py | 2 +- src/hooks.py | 14 ++++++++++++++ src/suites/builtin.py | 17 +++++++++-------- src/suites/cmd.py | 16 +++++++++++++++- src/suites/parenthesis.py | 7 ++++++- src/suites/status.py | 30 ------------------------------ src/test/test.py | 9 +++++++-- 7 files changed, 52 insertions(+), 43 deletions(-) create mode 100644 src/hooks.py delete mode 100644 src/suites/status.py (limited to 'src') diff --git a/src/config.py b/src/config.py index 59c7dad..27d524e 100644 --- a/src/config.py +++ b/src/config.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:19 by charles #+# #+# # -# Updated: 2020/09/11 14:21:14 by charles ### ########.fr # +# Updated: 2020/09/11 15:51:31 by charles ### ########.fr # # # # ############################################################################ # diff --git a/src/hooks.py b/src/hooks.py new file mode 100644 index 0000000..cd165a3 --- /dev/null +++ b/src/hooks.py @@ -0,0 +1,14 @@ +# ############################################################################ # +# # +# ::: :::::::: # +# hooks.py :+: :+: :+: # +# +:+ +:+ +:+ # +# By: charles +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# Created: 2020/09/11 16:10:20 by charles #+# #+# # +# Updated: 2020/09/11 16:10:51 by charles ### ########.fr # +# # +# ############################################################################ # + +def sort_lines(output): + return '\n'.join(sorted(output.split('\n'))) diff --git a/src/suites/builtin.py b/src/suites/builtin.py index da146e0..c782f4d 100644 --- a/src/suites/builtin.py +++ b/src/suites/builtin.py @@ -6,13 +6,14 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:43 by charles #+# #+# # -# Updated: 2020/09/09 13:28:02 by charles ### ########.fr # +# Updated: 2020/09/11 16:13:26 by charles ### ########.fr # # # # ############################################################################ # import os import config +import hooks from suite import suite @suite() @@ -42,7 +43,7 @@ def suite_echo(test): @suite() def suite_export(test): - test("export") + test("export", hook=hooks.sort_lines) # test("export A=; env | grep A=; echo $A") # test("export A; env | grep A; echo $A") test("export A=a; echo $A") @@ -105,8 +106,8 @@ def suite_cd(test): test("cd '' ''; pwd; echo $PWD"); test("cd '' '' ''; pwd; echo $PWD"); test("cd ' '; pwd; echo $PWD"); - test("cd '\t'; pwd; echo $PWD"); - test("cd '\t \t\t\t '; pwd; echo $PWD"); + # test("cd '\t'; pwd; echo $PWD"); + # test("cd '\t \t\t\t '; pwd; echo $PWD"); test("cd d ''; pwd; echo $PWD", setup="mkdir d") test("cd d d; pwd; echo $PWD", setup="mkdir d") test("cd d ' '; pwd; echo $PWD", setup="mkdir d") @@ -220,10 +221,10 @@ def suite_pwd(test): @suite() def suite_env(test): - test("env") # TODO ordering doesn't mater flag - test("env", setup="export A=a") - test("env", setup="export A=a B=b C=c") - test("env | cat -e", setup="export A=a B=b C=c") + test("env", hook=hooks.sort_lines) + test("env", setup="export A=a", hook=hooks.sort_lines) + test("env", setup="export A=a B=b C=c", hook=hooks.sort_lines) + test("env | cat -e", setup="export A=a B=b C=c", hook=hooks.sort_lines) @suite() def suite_exit(test): diff --git a/src/suites/cmd.py b/src/suites/cmd.py index 4fc5f55..8698392 100644 --- a/src/suites/cmd.py +++ b/src/suites/cmd.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 15:11:46 by charles #+# #+# # -# Updated: 2020/09/11 14:25:04 by charles ### ########.fr # +# Updated: 2020/09/11 16:14:18 by charles ### ########.fr # # # # ############################################################################ # @@ -315,3 +315,17 @@ def suite_cmd_path(test): test("./somedir", setup='mkdir somedir && chmod 6777 somedir') test("./somedir", setup='mkdir somedir && chmod 0000 somedir') test("./somedir", setup='mkdir somedir && chmod 0000 somedir') + + +@suite() +def suite_status(test): + test("echo $?") + test("echo; echo $?") + test("notfound; echo $?") + test("cat < doesntexist; echo $?") + test("cat < noperm; echo $?", setup="echo bonjour > noperm; chmod 000 noperm") + + test("echo") + test("notfound") + test("cat < doesntexist") + test("cat < noperm", setup="echo bonjour > noperm; chmod 000 noperm") diff --git a/src/suites/parenthesis.py b/src/suites/parenthesis.py index 98320e8..d3ec5bf 100644 --- a/src/suites/parenthesis.py +++ b/src/suites/parenthesis.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:57 by charles #+# #+# # -# Updated: 2020/09/11 14:23:35 by charles ### ########.fr # +# Updated: 2020/09/11 16:13:54 by charles ### ########.fr # # # # ############################################################################ # @@ -55,3 +55,8 @@ def suite_parenthesis(test): test("(exit); echo bonjour") test("(echo bonjour; exit; echo aurevoir)") + + test("(ls && ls)") + test("(ls doesntexist || ls)") + test("(ls doesntexist && ls)") + test("(ls && ls) && echo $?") diff --git a/src/suites/status.py b/src/suites/status.py deleted file mode 100644 index 416b69a..0000000 --- a/src/suites/status.py +++ /dev/null @@ -1,30 +0,0 @@ -# ############################################################################ # -# # -# ::: :::::::: # -# status.py :+: :+: :+: # -# +:+ +:+ +:+ # -# By: charles +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# Created: 2020/07/15 18:24:40 by charles #+# #+# # -# Updated: 2020/07/15 18:24:40 by charles ### ########.fr # -# # -# ############################################################################ # - -from suite import suite - -@suite() -def suite_status(test): - test("echo $?") - test("echo; echo $?") - test("notfound; echo $?") - test("cat < doesntexist; echo $?") - test("cat < noperm; echo $?", setup="echo bonjour > noperm; chmod 000 noperm") - test("(ls && ls) && echo $?") - - test("echo") - test("notfound") - test("cat < doesntexist") - test("cat < noperm", setup="echo bonjour > noperm; chmod 000 noperm") - test("(ls && ls)") - test("(ls doesntexist || ls)") - test("(ls doesntexist && ls)") diff --git a/src/test/test.py b/src/test/test.py index f75600a..bd7ed0d 100644 --- a/src/test/test.py +++ b/src/test/test.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/06/16 21:48:50 by charles #+# #+# # -# Updated: 2020/09/11 13:50:16 by charles ### ########.fr # +# Updated: 2020/09/11 16:08:07 by charles ### ########.fr # # # # ############################################################################ # @@ -28,7 +28,8 @@ class Test: files: [str] = [], exports: {str: str} = {}, timeout: float = config.TIMEOUT, - signal = None): + signal = None, + hook = None): self.cmd = cmd self.setup = setup self.files = files @@ -36,6 +37,7 @@ class Test: self.result = None self.timeout = timeout self.signal = signal + self.hook = hook def run(self): expected = self._run_sandboxed(config.REFERENCE_PATH, "-c") @@ -109,4 +111,7 @@ class Test: except FileNotFoundError as e: files_content.append(None) sandbox.remove() + if self.hook is not None: + output = self.hook(output) + output = '\n'.join(sorted(output.split('\n'))) return Captured(output, process.returncode, files_content) -- cgit