diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/hooks.py | 6 | ||||
| -rwxr-xr-x | src/main.py | 4 | ||||
| -rw-r--r-- | src/sandbox.py | 5 | ||||
| -rw-r--r-- | src/suite/__init__.py | 4 | ||||
| -rw-r--r-- | src/suite/decorator.py | 5 | ||||
| -rw-r--r-- | src/suite/suite.py | 10 | ||||
| -rw-r--r-- | src/suites/builtin.py | 92 | ||||
| -rw-r--r-- | src/suites/cmd.py | 35 | ||||
| -rw-r--r-- | src/suites/operation.py | 26 | ||||
| -rw-r--r-- | src/suites/parenthesis.py | 14 | ||||
| -rw-r--r-- | src/suites/path.py | 4 | ||||
| -rw-r--r-- | src/suites/preprocess.py | 136 | ||||
| -rw-r--r-- | src/test/__init__.py | 4 | ||||
| -rw-r--r-- | src/test/captured.py | 13 | ||||
| -rw-r--r-- | src/test/result.py | 22 | ||||
| -rw-r--r-- | src/test/test.py | 12 |
16 files changed, 202 insertions, 190 deletions
diff --git a/src/hooks.py b/src/hooks.py index 7ee1334..7582c6e 100644 --- a/src/hooks.py +++ b/src/hooks.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 16:10:20 by charles #+# #+# # -# Updated: 2020/09/11 18:26:58 by charles ### ########.fr # +# Updated: 2020/09/11 19:53:43 by charles ### ########.fr # # # # ############################################################################ # @@ -35,6 +35,6 @@ def discard(output): def export_singleton(output): return sort_lines( - '\n'.join([l for l in output.split('\n') - if regex.match("^declare -x .+=\".*\"$", l) is not None]) + '\n'.join([line for line in output.split('\n') + if regex.match("^declare -x .+=\".*\"$", line) is not None]) ) diff --git a/src/main.py b/src/main.py index 3ad1ae4..75b8947 100755 --- a/src/main.py +++ b/src/main.py @@ -22,7 +22,8 @@ import config import sandbox from args import parse_args from suite import Suite -from suites import * +from suites import * # noqa: F403,F401 + def main(): args = parse_args() @@ -47,7 +48,6 @@ def main(): shutil.copy(distutils.spawn.find_executable(cmd), # FIXME search whole PATH os.path.join(config.EXECUTABLES_PATH, cmd)) - config.VERBOSE_LEVEL = args.verbose if args.bonus: config.BONUS = True diff --git a/src/sandbox.py b/src/sandbox.py index e900076..418243e 100644 --- a/src/sandbox.py +++ b/src/sandbox.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 13:48:07 by charles #+# #+# # -# Updated: 2020/09/11 13:50:08 by charles ### ########.fr # +# Updated: 2020/09/11 19:53:13 by charles ### ########.fr # # # # ############################################################################ # @@ -17,6 +17,7 @@ import subprocess import config + def create(): try: os.mkdir(config.SANDBOX_PATH) @@ -27,6 +28,6 @@ def create(): def remove(): try: shutil.rmtree(config.SANDBOX_PATH) - except: + except PermissionError: subprocess.run(["chmod", "777", *glob.glob(config.SANDBOX_PATH + "/*")], check=True) subprocess.run(["rm", "-rf", config.SANDBOX_PATH], check=True) diff --git a/src/suite/__init__.py b/src/suite/__init__.py index 55beb35..6f7f321 100644 --- a/src/suite/__init__.py +++ b/src/suite/__init__.py @@ -1,2 +1,2 @@ -from suite.suite import Suite -from suite.decorator import suite +from suite.suite import Suite # noqa: F401 +from suite.decorator import suite # noqa: F401 diff --git a/src/suite/decorator.py b/src/suite/decorator.py index e825839..448e0a3 100644 --- a/src/suite/decorator.py +++ b/src/suite/decorator.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:28:00 by charles #+# #+# # -# Updated: 2020/09/11 16:43:00 by charles ### ########.fr # +# Updated: 2020/09/11 20:08:27 by charles ### ########.fr # # # # ############################################################################ # @@ -14,6 +14,7 @@ from suite import Suite from test import Test import inspect + def suite(groups: [str] = [], bonus: bool = False): def suite_wrapper(origin): """ decorator for a suite function (fmt: suite_[name]) """ @@ -23,10 +24,12 @@ def suite(groups: [str] = [], bonus: bool = False): name = "{}/{}".format(mod_name, origin.__name__[len("suite_"):]) s = Suite(name, groups + [mod_name], bonus) + def test_generator(): def test(*args, **kwargs): s.add(Test(*args, **kwargs)) origin(test) + s.add_generator(test_generator) Suite.available.append(s) return test_generator diff --git a/src/suite/suite.py b/src/suite/suite.py index 7f78d33..a51da65 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/11 17:48:25 by charles ### ########.fr # +# Updated: 2020/09/11 20:08:39 by charles ### ########.fr # # # # ############################################################################ # @@ -28,8 +28,8 @@ class Suite: if not config.BONUS: cls.available = [s for s in cls.available if not s.bonus] cls.available = list(set( - [s for s in cls.available if s.name in asked_names] + - [s for s in cls.available if any([g for g in s.groups if g in asked_names])] + [s for s in cls.available if s.name in asked_names] + + [s for s in cls.available if any([g for g in s.groups if g in asked_names])] )) for s in cls.available: s.generate() @@ -85,9 +85,9 @@ class Suite: 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)) + .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)) + .format("TOTAL", pass_sum, fail_sum)) @classmethod def save_log(cls): diff --git a/src/suites/builtin.py b/src/suites/builtin.py index 95e9ed5..06686bb 100644 --- a/src/suites/builtin.py +++ b/src/suites/builtin.py @@ -6,7 +6,7 @@ # By: juligonz <juligonz@student.42.fr> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:43 by charles #+# #+# # -# Updated: 2020/09/11 18:45:03 by charles ### ########.fr # +# Updated: 2020/09/11 19:56:44 by charles ### ########.fr # # Updated: 2020/09/11 18:01:27 by juligonz ### ########.fr # # # # **************************************************************************** # @@ -17,6 +17,7 @@ import config import hooks from suite import suite + @suite() def suite_echo(test): test("echo") @@ -39,6 +40,7 @@ def suite_echo(test): test('echo -n a "" b "" c "" d') test("echo '' '' ''") + @suite() def suite_export(test): test("export", hook=hooks.export_singleton) @@ -49,9 +51,9 @@ def suite_export(test): test("export", exports={"A": "a"}, hook=hooks.export_singleton) test("export A=a; echo $A") test("export A=a B=b C=c; echo $A$B$C") - test("export A=a B=b C=c D=d E=e F=f G=g H=h I=i J=j K=k L=l" + - "M=m N=n O=o P=p Q=q R=r S=s T=t U=u V=v W=w X=x Y=y Z=z" + - "; echo $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") + test("export A=a B=b C=c D=d E=e F=f G=g H=h I=i J=j K=k L=l" + "M=m N=n O=o P=p Q=q R=r S=s T=t U=u V=v W=w X=x Y=y Z=z" + "; echo $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") test("export BONJOURJESUIS=a; echo $BONJOURJESUIS") test("export bonjourjesuis=a; echo $bonjourjesuis") test("export bonjour_je_suis=a; echo $bonjour_je_suis") @@ -112,32 +114,32 @@ def suite_export(test): @suite() def suite_cd(test): - test("cd .; pwd; echo $PWD"); - test("cd ..; pwd; echo $PWD"); - test("cd ../..; pwd; echo $PWD"); - test("cd ../../..; pwd; echo $PWD"); - test("cd ../../../..; pwd; echo $PWD"); - test("cd ../../../../..; pwd; echo $PWD"); - test("cd ../../../../../..; pwd; echo $PWD"); - test("cd /; pwd; echo $PWD"); - test("cd /etc; pwd; echo $PWD"); - test("cd ''; pwd; echo $PWD"); - test("cd '' ''; pwd; echo $PWD"); - test("cd '' '' ''; pwd; echo $PWD"); - test("cd ' '; pwd; echo $PWD"); + test("cd .; pwd; echo $PWD") + test("cd ..; pwd; echo $PWD") + test("cd ../..; pwd; echo $PWD") + test("cd ../../..; pwd; echo $PWD") + test("cd ../../../..; pwd; echo $PWD") + test("cd ../../../../..; pwd; echo $PWD") + test("cd ../../../../../..; pwd; echo $PWD") + test("cd /; pwd; echo $PWD") + test("cd /etc; pwd; echo $PWD") + test("cd ''; pwd; echo $PWD") + test("cd '' ''; pwd; echo $PWD") + test("cd '' '' ''; pwd; echo $PWD") + test("cd ' '; 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") - test("cd $HOME; pwd; echo $PWD"); - test("cd $HOME; pwd; echo $PWD", exports={"HOME": os.getenv("HOME")}); - test("cd /; pwd; echo $PWD"); - test("cd /.; pwd; echo $PWD"); - test("cd /./; pwd; echo $PWD"); - test("cd /././././; pwd; echo $PWD"); - test("cd //; pwd; echo $PWD"); - test("cd ///; pwd; echo $PWD"); - test("cd ////; pwd; echo $PWD"); - test("cd //////////////////////////////////////////////////////; pwd; echo $PWD"); + test("cd $HOME; pwd; echo $PWD") + test("cd $HOME; pwd; echo $PWD", exports={"HOME": os.getenv("HOME")}) + test("cd /; pwd; echo $PWD") + test("cd /.; pwd; echo $PWD") + test("cd /./; pwd; echo $PWD") + test("cd /././././; pwd; echo $PWD") + test("cd //; pwd; echo $PWD") + test("cd ///; pwd; echo $PWD") + test("cd ////; pwd; echo $PWD") + test("cd //////////////////////////////////////////////////////; pwd; echo $PWD") test("cd") test("cd ' /'; pwd; echo $PWD") test("cd ' / '; pwd; echo $PWD") @@ -206,22 +208,21 @@ def suite_unset(test): test("unset 'A='; echo $A", exports={"A": "a"}) test("unset A B C; echo $A$B$C", exports={"A": "a", "B": "b", "C": "c"}) test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C", - exports={"A": "a", "B": "b", "C": "c"}) + exports={"A": "a", "B": "b", "C": "c"}) test("unset 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C", - exports={"A": "a", "B": "b", "C": "c"}) + exports={"A": "a", "B": "b", "C": "c"}) test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf '; echo $A$B$C", - exports={"A": "a", "B": "b", "C": "c"}) + exports={"A": "a", "B": "b", "C": "c"}) test("unset A; echo $A$B$C", exports={"A": "a", "B": "b", "C": "c"}) test("unset C; echo $A$B$C", exports={"A": "a", "B": "b", "C": "c"}) test("unset A B C", exports={"A": "a", "B": "b", "C": "c"}) test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C", - exports={"A": "a", "B": "b", "C": "c"}) + exports={"A": "a", "B": "b", "C": "c"}) test("unset 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C", - exports={"A": "a", "B": "b", "C": "c"}) + exports={"A": "a", "B": "b", "C": "c"}) test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf '", - exports={"A": "a", "B": "b", "C": "c"}) + exports={"A": "a", "B": "b", "C": "c"}) test("unset A", exports={"A": "a", "B": "b", "C": "c"}) - test("unset 'AH@'=nop") test("unset \"AH'\"=nop") test("unset 'AH\"'=nop") @@ -232,6 +233,7 @@ def suite_unset(test): test("unset 'AH&'=nop") test("unset 'AH\\'=nop") + @suite() def suite_pwd(test): test("pwd") @@ -243,6 +245,7 @@ def suite_pwd(test): test("pwd | cat -e") # test("cd lnk; rmdir ../d; pwd", setup="mkdir d; ln -s d lnk") + @suite() def suite_env(test): test("env", hook=hooks.sort_lines) @@ -250,6 +253,7 @@ def suite_env(test): 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): test("exit") @@ -316,16 +320,16 @@ def suite_exit(test): test("exit 0123456789") test("exit -0123456789") test("exit 00000000000000000000000000000000000000000000001") - test("exit 00000000000000000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000001") - test("exit 00000000000000000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000000") - test("exit -00000000000000000000000000000000000000000000000" + - "00000000000000000000000000000000000000000000001") - test("exit -99999999999999999999999999999999999999999999" + - "99999999999999999999999999999999999999999999") - test("exit 99999999999999999999999999999999999999999999" + - "99999999999999999999999999999999999999999999") + test("exit 00000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000001") + test("exit 00000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000000") + test("exit -00000000000000000000000000000000000000000000000" + "00000000000000000000000000000000000000000000001") + test("exit -99999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999") + test("exit 99999999999999999999999999999999999999999999" + "99999999999999999999999999999999999999999999") test("exit 0 bonjour") test("exit bonjour 0") test("exit 0 1") diff --git a/src/suites/cmd.py b/src/suites/cmd.py index 7294f3a..f258dd4 100644 --- a/src/suites/cmd.py +++ b/src/suites/cmd.py @@ -6,13 +6,12 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 15:11:46 by charles #+# #+# # -# Updated: 2020/09/11 18:29:06 by charles ### ########.fr # +# Updated: 2020/09/11 20:12:16 by charles ### ########.fr # # # # ############################################################################ # import distutils -import config import hooks from suite import suite @@ -60,11 +59,11 @@ def suite_redirection(test): 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=["abcdefghijklmnopqrstuvwxyz"]) + files=["abcdefghijklmnopqrstuvwxyz"]) 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=["abcdefghijklmnopqrstuvwxyz"]) + files=["abcdefghijklmnopqrstuvwxyz"]) 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=["abcdefghijklmnopqrstuvwxyz"]) + files=["abcdefghijklmnopqrstuvwxyz"]) test("> file", files=["file"]) test("< file", setup="echo bonjour > file") test(">", hook=hooks.error_line0) @@ -119,12 +118,12 @@ def suite_cmd_path(test): 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)) + 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)) + 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)) + setup="touch a b c; echo bonjour > a; cp {} ls".format(cat_path)) test("./somefile", setup="touch somefile; chmod 000 somefile") test("./somefile", setup="touch somefile; chmod 001 somefile") test("./somefile", setup="touch somefile; chmod 002 somefile") @@ -165,17 +164,17 @@ def suite_cmd_path(test): test("somedirsoftlink", setup="mkdir somedir; ln -s somedir somedirsoftlink") test("./someremovedlink", setup="touch somefile; ln -s somefile someremovedlink; rm -f somefile") test("./somelink2", setup="touch somefile; ln -s somefile somelink1; ln -s somelink1 somelink2") - test("./somelink3", setup="touch somefile; ln -s somefile somelink1; ln -s somelink1 somelink2;" + - "ln -s somelink2 somelink3") - test("./somelink4", setup="touch somefile; ln -s somefile somelink1; ln -s somelink1 somelink2;" + - "ln -s somelink2 somelink3; ln -s somelink3 somelink4") - test("./somelink2ls", setup="cp " + ls_path + " somefile;" + + test("./somelink3", setup="touch somefile; ln -s somefile somelink1; ln -s somelink1 somelink2;" + "ln -s somelink2 somelink3") + test("./somelink4", setup="touch somefile; ln -s somefile somelink1; ln -s somelink1 somelink2;" + "ln -s somelink2 somelink3; ln -s somelink3 somelink4") + test("./somelink2ls", setup="cp " + ls_path + " somefile;" "ln -s somefile somelink1; ln -s somelink1 somelink2") - test("./somelink3ls", setup="cp " + ls_path + " somefile;" + - "ln -s somefile somelink1; ln -s somelink1 somelink2;" + + test("./somelink3ls", setup="cp " + ls_path + " somefile;" + "ln -s somefile somelink1; ln -s somelink1 somelink2;" "ln -s somelink2 somelink3") - test("./somelink4ls", setup="cp " + ls_path + " somefile;" + - "ln -s somefile somelink1; ln -s somelink1 somelink2;" + + test("./somelink4ls", setup="cp " + ls_path + " somefile;" + "ln -s somefile somelink1; ln -s somelink1 somelink2;" "ln -s somelink2 somelink3; ln -s somelink3 somelink4") test("_", setup="touch _") test("'-'", setup="touch -") diff --git a/src/suites/operation.py b/src/suites/operation.py index 9d9c6d8..18ebd72 100644 --- a/src/suites/operation.py +++ b/src/suites/operation.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:52 by charles #+# #+# # -# Updated: 2020/09/11 17:43:58 by charles ### ########.fr # +# Updated: 2020/09/11 20:12:54 by charles ### ########.fr # # # # ############################################################################ # @@ -26,11 +26,11 @@ def suite_end(test): test("; echo", hook=hooks.error_line0) test(" ;echo", hook=hooks.error_line0) test(" ; echo", hook=hooks.error_line0) - test("echo a; echo b; echo c; echo d; echo e; echo f; echo g; echo h; echo i;" + - "echo j; echo k; echo l; echo m; echo c; echo c; echo c; echo c; echo c;" + + test("echo a; echo b; echo c; echo d; echo e; echo f; echo g; echo h; echo i;" + "echo j; echo k; echo l; echo m; echo c; echo c; echo c; echo c; echo c;" "echo c; echo c; echo c; echo v; echo w; echo x; echo y; echo z") - test("echo a ; echo b; echo c ;echo d ; echo e ;echo f; echo g ;echo h; echo i;" + - "echo j ; echo k; echo l; echo m; echo c ; echo c; echo c ; echo c; echo c;" + + test("echo a ; echo b; echo c ;echo d ; echo e ;echo f; echo g ;echo h; echo i;" + "echo j ; echo k; echo l; echo m; echo c ; echo c; echo c ; echo c; echo c;" "echo c; echo c ; echo c; echo v ; echo w; echo x; echo y ; echo z") test("ls doesnotexists ; echo bonjour") test("ls doesnotexists; echo bonjour") @@ -70,11 +70,11 @@ def suite_and(test): test("&&echo", hook=hooks.error_line0) test("&& echo", hook=hooks.error_line0) test(" && echo", hook=hooks.error_line0) - test("echo a&& echo b&& echo c&& echo d&& echo e&& echo f&& echo g&& echo h&& echo i&&" + - "echo j&& echo k&& echo l&& echo m&& echo c&& echo c&& echo c&& echo c&& echo c&&" + + test("echo a&& echo b&& echo c&& echo d&& echo e&& echo f&& echo g&& echo h&& echo i&&" + "echo j&& echo k&& echo l&& echo m&& echo c&& echo c&& echo c&& echo c&& echo c&&" "echo c&& echo c&& echo c&& echo v&& echo w&& echo x&& echo y&& echo z") - test("echo a && echo b&& echo c &&echo d && echo e &&echo f&& echo g &&echo h&& echo i&&" + - "echo j && echo k&& echo l&& echo m&& echo c && echo c&& echo c && echo c&& echo c&&" + + test("echo a && echo b&& echo c &&echo d && echo e &&echo f&& echo g &&echo h&& echo i&&" + "echo j && echo k&& echo l&& echo m&& echo c && echo c&& echo c && echo c&& echo c&&" "echo c&& echo c && echo c&& echo v && echo w&& echo x&& echo y && echo z") test("ls doesnotexists && echo bonjour") test("ls doesnotexists&& echo bonjour") @@ -93,11 +93,11 @@ def suite_or(test): test("||echo", hook=hooks.error_line0) test("|| echo", hook=hooks.error_line0) test(" || echo", hook=hooks.error_line0) - test("echo a|| echo b|| echo c|| echo d|| echo e|| echo f|| echo g|| echo h|| echo i||" + - "echo j|| echo k|| echo l|| echo m|| echo c|| echo c|| echo c|| echo c|| echo c||" + + test("echo a|| echo b|| echo c|| echo d|| echo e|| echo f|| echo g|| echo h|| echo i||" + "echo j|| echo k|| echo l|| echo m|| echo c|| echo c|| echo c|| echo c|| echo c||" "echo c|| echo c|| echo c|| echo v|| echo w|| echo x|| echo y|| echo z") - test("echo a || echo b|| echo c ||echo d || echo e ||echo f|| echo g ||echo h|| echo i||" + - "echo j || echo k|| echo l|| echo m|| echo c || echo c|| echo c || echo c|| echo c||" + + test("echo a || echo b|| echo c ||echo d || echo e ||echo f|| echo g ||echo h|| echo i||" + "echo j || echo k|| echo l|| echo m|| echo c || echo c|| echo c || echo c|| echo c||" "echo c|| echo c || echo c|| echo v || echo w|| echo x|| echo y || echo z") test("ls doesnotexists || echo bonjour") test("ls doesnotexists|| echo bonjour") diff --git a/src/suites/parenthesis.py b/src/suites/parenthesis.py index d2007cb..6a1e7f1 100644 --- a/src/suites/parenthesis.py +++ b/src/suites/parenthesis.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:57 by charles #+# #+# # -# Updated: 2020/09/11 17:43:34 by charles ### ########.fr # +# Updated: 2020/09/11 20:12:27 by charles ### ########.fr # # # # ############################################################################ # @@ -27,23 +27,23 @@ def suite_parenthesis(test): test("(echo bonjour > f1)", files=["f1"]) test("(echo bonjour > f1 > f2 > f3)", files=["f1", "f2", "f3"]) test("(echo bonjour > f1 > f2 > f3 > f4 > f5 > f6 > f7 > f8 > f9)", - files=["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9"]) + files=["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9"]) test("(echo bonjour) > f1", files=["f1"]) test("(echo bonjour) > f1 > f2 > f3", files=["f1", "f2", "f3"]) test("(echo bonjour) > f1 > f2 > f3 > f4 > f5 > f6 > f7 > f8 > f9", - files=["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9"]) + files=["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9"]) test("(cat -e < f1)", setup="echo bonjour > f1") test("(cat -e < f1 < f2 < f3)", setup="touch f1 f2 f3 f4; echo bonjour > f3") test("(cat -e < f1 < f2 < f3 < f4 < f5 < f6 < f7 < f8 < f9)", - setup="touch f1 f2 f3 f4 f5 f6 f7 f8 f9; echo bonjour > f9") + setup="touch f1 f2 f3 f4 f5 f6 f7 f8 f9; echo bonjour > f9") test("(cat -e) < f1", setup="echo bonjour > f1") test("(cat -e) < f1 < f2 < f3", setup="touch f1 f2 f3 f4; echo bonjour > f3") test("(cat -e) < f1 < f2 < f3 < f4 < f5 < f6 < f7 < f8 < f9", - setup="touch f1 f2 f3 f4 f5 f6 f7 f8 f9; echo bonjour > f9") + setup="touch f1 f2 f3 f4 f5 f6 f7 f8 f9; echo bonjour > f9") test("(echo bonjour > f1 > f2 > f3 > f4) > f5 > f6 > f7 > f8 > f9", - files=["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9"]) + files=["f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9"]) test("(cat -e < f1 < f2 < f3 < f4) < f5 < f6 < f7 < f8 < f9", - setup="touch f1 f2 f3 f4 f5 f6 f7 f8 f9; echo bonjour > f4") + setup="touch f1 f2 f3 f4 f5 f6 f7 f8 f9; echo bonjour > f4") test("(echo bonjour > f1) > f2", files=["f1", "f2"]) test("(cat -e > f1) < f2", setup="ls -l / > f2", files=["f1"]) test("(exit); echo bonjour") diff --git a/src/suites/path.py b/src/suites/path.py index bcac98e..0e143dd 100644 --- a/src/suites/path.py +++ b/src/suites/path.py @@ -6,13 +6,13 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/09 15:12:58 by charles #+# #+# # -# Updated: 2020/09/11 17:43:14 by charles ### ########.fr # +# Updated: 2020/09/11 20:13:09 by charles ### ########.fr # # # # ############################################################################ # -import config from suite import suite + @suite() def suite_path(test): test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 000 ./path/a", exports={"PATH": "path"}) diff --git a/src/suites/preprocess.py b/src/suites/preprocess.py index 6761df9..a407809 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/11 19:37:11 by charles ### ########.fr # +# Updated: 2020/09/11 20:15:08 by charles ### ########.fr # # # # **************************************************************************** # @@ -59,21 +59,21 @@ def suite_quote(test): @suite() def suite_interpolation(test): - test("echo $TEST", exports={"TEST": "bonjour"}) - test("echo $TES", exports={"TEST": "bonjour"}) - test("echo $TEST_", exports={"TEST": "bonjour"}) - test('echo "|$TEST|"', exports={"TEST": "bonjour"}) - test('echo "|$TES|"', exports={"TEST": "bonjour"}) - test('echo "|$TEST_|"', exports={"TEST": "bonjour"}) - test("echo '|$TEST|'", exports={"TEST": "bonjour"}) - test("echo '|$TES|'", exports={"TEST": "bonjour"}) - test("echo '|$TEST_|'", exports={"TEST": "bonjour"}) - test("echo $A$B$C", exports={"A": "foo", "B": "bar", "C": "baz"}) - test('echo "$A$B$C"', exports={"A": "foo", "B": "bar", "C": "baz"}) - test("echo '$A$B$C'", exports={"A": "foo", "B": "bar", "C": "baz"}) - test("echo $A,$B,$C", exports={"A": "foo", "B": "bar", "C": "baz"}) - test('echo "$A,$B,$C"', exports={"A": "foo", "B": "bar", "C": "baz"}) - test("echo '$A,$B,$C'", exports={"A": "foo", "B": "bar", "C": "baz"}) + test("echo $TEST", exports={"TEST": "bonjour"}) + test("echo $TES", exports={"TEST": "bonjour"}) + test("echo $TEST_", exports={"TEST": "bonjour"}) + test('echo "|$TEST|"', exports={"TEST": "bonjour"}) + test('echo "|$TES|"', exports={"TEST": "bonjour"}) + test('echo "|$TEST_|"', exports={"TEST": "bonjour"}) + test("echo '|$TEST|'", exports={"TEST": "bonjour"}) + test("echo '|$TES|'", exports={"TEST": "bonjour"}) + test("echo '|$TEST_|'", exports={"TEST": "bonjour"}) + test("echo $A$B$C", exports={"A": "foo", "B": "bar", "C": "baz"}) + test('echo "$A$B$C"', exports={"A": "foo", "B": "bar", "C": "baz"}) + test("echo '$A$B$C'", exports={"A": "foo", "B": "bar", "C": "baz"}) + test("echo $A,$B,$C", exports={"A": "foo", "B": "bar", "C": "baz"}) + test('echo "$A,$B,$C"', exports={"A": "foo", "B": "bar", "C": "baz"}) + test("echo '$A,$B,$C'", exports={"A": "foo", "B": "bar", "C": "baz"}) test('echo $A"$B"$C"A"$B"$C"', exports={"A": "foo", "B": "bar", "C": "baz"}) test("echo $A'$B'$C'A'$B'$C'", exports={"A": "foo", "B": "bar", "C": "baz"}) test('echo $A"$B"$C"A"$B"$C"', exports={"A": "foo ", "B": " bar ", "C": "baz "}) @@ -96,62 +96,62 @@ def suite_interpolation(test): test(r"echo \ \ \ \ \ \ \ $A\ \ \ \ \ \ ", exports={"A": "bonjour"}) test(r"echo \ \ \ \ \ \ \ $A\ \ \ \ \ \ ", exports={"A": "bonjour je suis"}) test(r"echo \ \ \ \ \ \ \ $A\ \ \ \ \ \ ", exports={"A": " bonjour je suis "}) - test('echo $A', exports={"A": "bonjour je suis splited"}) - test('echo $A', exports={"A": "bonjour je suis splited"}) - test('echo $A', exports={"A": " bonjour je suis splited "}) - test('echo [$A]', exports={"A": "bonjour je suis splited"}) - test('echo [$A]', exports={"A": "bonjour je suis splited"}) - test('echo [$A]', exports={"A": " bonjour je suis splited "}) - test('echo "[$A]"', exports={"A": "bonjour je suis splited"}) - test('echo "[$A]"', exports={"A": "bonjour je suis splited"}) - test('echo "[$A]"', exports={"A": " bonjour je suis splited "}) - test('echo \ $A', exports={"A": "bonjour je suis splited"}) - test('echo \ $A', exports={"A": "bonjour je suis splited"}) - test('echo \ $A', exports={"A": " bonjour je suis splited "}) - test('echo $A\ ', exports={"A": "bonjour je suis splited"}) - test('echo $A\ ', exports={"A": "bonjour je suis splited"}) - test('echo $A\ ', exports={"A": " bonjour je suis splited "}) - test('echo $A$A$A', exports={"A": " bonjour je suis splited "}) - test("echo $A", exports={"A": "'" + config.LOREM + "'"}) - test('echo "$A"', exports={"A": "'" + config.LOREM + "'"}) - test("echo '$A'", exports={"A": "'" + config.LOREM + "'"}) - test("$ECHO $ECHO", exports={"ECHO": "echo"}) + test('echo $A', exports={"A": "bonjour je suis splited"}) + test('echo $A', exports={"A": "bonjour je suis splited"}) + test('echo $A', exports={"A": " bonjour je suis splited "}) + test('echo [$A]', exports={"A": "bonjour je suis splited"}) + test('echo [$A]', exports={"A": "bonjour je suis splited"}) + test('echo [$A]', exports={"A": " bonjour je suis splited "}) + test('echo "[$A]"', exports={"A": "bonjour je suis splited"}) + test('echo "[$A]"', exports={"A": "bonjour je suis splited"}) + test('echo "[$A]"', exports={"A": " bonjour je suis splited "}) + test('echo \\ $A', exports={"A": "bonjour je suis splited"}) + test('echo \\ $A', exports={"A": "bonjour je suis splited"}) + test('echo \\ $A', exports={"A": " bonjour je suis splited "}) + test('echo $A\\ ', exports={"A": "bonjour je suis splited"}) + test('echo $A\\ ', exports={"A": "bonjour je suis splited"}) + test('echo $A\\ ', exports={"A": " bonjour je suis splited "}) + test('echo $A$A$A', exports={"A": " bonjour je suis splited "}) + test("echo $A", exports={"A": "'" + config.LOREM + "'"}) + test('echo "$A"', exports={"A": "'" + config.LOREM + "'"}) + test("echo '$A'", exports={"A": "'" + config.LOREM + "'"}) + test("$ECHO $ECHO", exports={"ECHO": "echo"}) test("$A$B bonjour", exports={"A": "ec", "B": "ho"}) - test("$LS", exports={"LS": "ls -l"}, setup="touch a b c") + test("$LS", exports={"LS": "ls -l"}, setup="touch a b c") test("echo $") - test("echo \$") - test("echo \$\$\$\$") - test("echo \$$\$$") - test("echo $\A $\B", exports={"A": "a", "B": "b"}) - test("echo $\A$\B", exports={"A": "a", "B": "b"}) - test("echo $A", exports={"A": " "}) - test("echo $A", exports={"A": " "}) - test("echo $A", exports={"A": " "}) - test("echo $A", exports={"A": " "}) - test("echo $A", exports={"A": " a "}) - test("echo $A", exports={"A": " "}) - test("echo $A", exports={"A": " a "}) - test("echo @$A@", exports={"A": " "}) - test("echo @ $A@", exports={"A": " "}) - test("echo @$A @", exports={"A": " "}) - test("echo @$A@", exports={"A": " "}) - test("echo '@'$A'@'", exports={"A": " "}) - test("echo '@' $A'@'", exports={"A": " "}) - test("echo '@'$A '@'", exports={"A": " "}) - test('echo "@"$A"@"', exports={"A": " "}) - test('echo "@" $A"@"', exports={"A": " "}) - test('echo "@"$A "@"', exports={"A": " "}) - test('echo @"$A"@', exports={"A": " "}) - test('echo @ "$A"@', exports={"A": " "}) - test('echo @"$A" @', exports={"A": " "}) - test('echo @"$A"@', exports={"A": " "}) - test("echo '@'\"$A\"'@'", exports={"A": " "}) + test("echo \\$") + test("echo \\$\\$\\$\\$") + test("echo \\$$\\$$") + test("echo $\\A $\\B", exports={"A": "a", "B": "b"}) + test("echo $\\A$\\B", exports={"A": "a", "B": "b"}) + test("echo $A", exports={"A": " "}) + test("echo $A", exports={"A": " "}) + test("echo $A", exports={"A": " "}) + test("echo $A", exports={"A": " "}) + test("echo $A", exports={"A": " a "}) + test("echo $A", exports={"A": " "}) + test("echo $A", exports={"A": " a "}) + test("echo @$A@", exports={"A": " "}) + test("echo @ $A@", exports={"A": " "}) + test("echo @$A @", exports={"A": " "}) + test("echo @$A@", exports={"A": " "}) + test("echo '@'$A'@'", exports={"A": " "}) + test("echo '@' $A'@'", exports={"A": " "}) + test("echo '@'$A '@'", exports={"A": " "}) + test('echo "@"$A"@"', exports={"A": " "}) + test('echo "@" $A"@"', exports={"A": " "}) + test('echo "@"$A "@"', exports={"A": " "}) + test('echo @"$A"@', exports={"A": " "}) + test('echo @ "$A"@', exports={"A": " "}) + test('echo @"$A" @', exports={"A": " "}) + test('echo @"$A"@', exports={"A": " "}) + test("echo '@'\"$A\"'@'", exports={"A": " "}) test("echo '@' \"$A\"'@'", exports={"A": " "}) test("echo '@'\"$A\" '@'", exports={"A": " "}) - test('echo "@""$A""@"', exports={"A": " "}) - test('echo "@" "$A""@"', exports={"A": " "}) - test('echo "@""$A" "@"', exports={"A": " "}) - test('echo $A$B$C', exports={"A": "", "B": "", "C": ""}) + test('echo "@""$A""@"', exports={"A": " "}) + test('echo "@" "$A""@"', exports={"A": " "}) + test('echo "@""$A" "@"', exports={"A": " "}) + test('echo $A$B$C', exports={"A": "", "B": "", "C": ""}) @suite() diff --git a/src/test/__init__.py b/src/test/__init__.py index 7601878..cf9949f 100644 --- a/src/test/__init__.py +++ b/src/test/__init__.py @@ -6,8 +6,8 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:18:14 by charles #+# #+# # -# Updated: 2020/09/11 12:26:30 by charles ### ########.fr # +# Updated: 2020/09/11 20:18:10 by charles ### ########.fr # # # # ############################################################################ # -from test.test import Test +from test.test import Test # noqa: F401 diff --git a/src/test/captured.py b/src/test/captured.py index e47590b..b42352e 100644 --- a/src/test/captured.py +++ b/src/test/captured.py @@ -6,12 +6,13 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:16:25 by charles #+# #+# # -# Updated: 2020/09/11 12:16:51 by charles ### ########.fr # +# Updated: 2020/09/11 20:08:00 by charles ### ########.fr # # # # ############################################################################ # import config + class Captured: def __init__(self, output: str, status: int, files_content: [str], is_timeout: bool = False): lines = output.split('\n') @@ -27,13 +28,13 @@ class Captured: self.files_content = files_content self.is_timeout = is_timeout - def __eq__(self, other: 'Result') -> bool: + def __eq__(self, other: 'Captured') -> bool: if self.is_timeout: return self.is_timeout == other.is_timeout - 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)])) + 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) + return Captured("", 0, [], is_timeout=True) diff --git a/src/test/result.py b/src/test/result.py index 5e1349d..4f46e52 100644 --- a/src/test/result.py +++ b/src/test/result.py @@ -6,13 +6,16 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:17:34 by charles #+# #+# # -# Updated: 2020/09/11 12:24:57 by charles ### ########.fr # +# Updated: 2020/09/11 20:06:31 by charles ### ########.fr # # # # ############################################################################ # +import sys + import config from test.captured import Captured + class Result: RED_CHARS = "\033[31m" GREEN_CHARS = "\033[32m" @@ -125,8 +128,10 @@ class Result: 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' + 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) @@ -151,9 +156,8 @@ class Result: @property def escaped_cmd(self): return (self.cmd - .replace("\t", "\\t") - .replace("\n", "\\n") - .replace("\v", "\\v") - .replace("\r", "\\r") - .replace("\f", "\\f") - ) + .replace("\t", "\\t") + .replace("\n", "\\n") + .replace("\v", "\\v") + .replace("\r", "\\r") + .replace("\f", "\\f")) diff --git a/src/test/test.py b/src/test/test.py index 04ee354..48f05a0 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/11 17:00:25 by charles ### ########.fr # +# Updated: 2020/09/11 20:00:52 by charles ### ########.fr # # # # ############################################################################ # @@ -28,8 +28,8 @@ class Test: files: [str] = [], exports: {str: str} = {}, timeout: float = config.TIMEOUT, - signal = None, - hook = None): + signal=None, + hook=None): self.cmd = cmd self.setup = setup self.files = files @@ -47,7 +47,7 @@ class Test: s = "[SETUP {}] {}".format(self.setup, s) if len(self.exports) != 0: s = "[EXPORTS {}] {}".format( - ' '.join(["{}='{:.20}'".format(k, v) for k, v in self.exports.items()]), s) + ' '.join(["{}='{:.20}'".format(k, v) for k, v in self.exports.items()]), s) self.result = Result(s, self.files, expected, actual) self.result.put() @@ -61,7 +61,7 @@ class Test: sandbox.create() if self.setup != "": try: - setup_status = subprocess.run( + subprocess.run( self.setup, shell=True, cwd=config.SANDBOX_PATH, @@ -108,7 +108,7 @@ class Test: try: with open(os.path.join(config.SANDBOX_PATH, file_name), "rb") as f: files_content.append(f.read().decode()) - except FileNotFoundError as e: + except FileNotFoundError: files_content.append(None) sandbox.remove() if self.hook is not None: |
