diff options
| -rw-r--r-- | config.py | 9 | ||||
| -rw-r--r-- | suite.py | 6 | ||||
| -rw-r--r-- | suites/builtin.py | 74 | ||||
| -rw-r--r-- | suites/cmd.py | 128 | ||||
| -rw-r--r-- | suites/operation.py | 26 | ||||
| -rw-r--r-- | suites/preprocess.py | 152 | ||||
| -rw-r--r-- | test.py | 39 |
7 files changed, 393 insertions, 41 deletions
@@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:19 by charles #+# #+# # -# Updated: 2020/07/16 08:55:04 by charles ### ########.fr # +# Updated: 2020/07/19 20:29:52 by charles ### ########.fr # # # # ############################################################################ # @@ -27,13 +27,14 @@ REFERENCE_PATH = "/bin/bash" LOG_PATH = "result.log" # path to the sandbox directory +# WARNING: will be rm -rf so be careful SANDBOX_PATH = "sandbox" # where the availables commands are stored EXECUTABLES_PATH = "./bin" # commands available in test" -AVAILABLE_COMMANDS = ["cat", "touch", "env", "ls", "grep", "sh"] +AVAILABLE_COMMANDS = ["rmdir", "env", "cat", "touch", "ls", "grep", "sh"] # $PATH environment variable passed to the shell PATH_VARIABLE = os.path.abspath(EXECUTABLES_PATH) @@ -55,7 +56,11 @@ Perspiciatis ut maxime et libero quo voluptas consequatur illum. Pariatur porro """ LOREM = ' '.join(LOREM.split('\n')) +TIMEOUT = 1 + +############################################################################### # do not edit +############################################################################### MINISHELL_PATH = os.path.abspath( os.path.join(MINISHELL_DIR, MINISHELL_EXEC) @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:29 by charles #+# #+# # -# Updated: 2020/07/15 18:24:29 by charles ### ########.fr # +# Updated: 2020/07/19 15:29:36 by charles ### ########.fr # # # # ############################################################################ # @@ -99,8 +99,8 @@ def suite(origin): name = origin.__name__[len("suite_"):] s = Suite(name) def test_generator(): - def test(cmd: str, setup: str = "", files: [str] = [], exports: {str, str} = {}): - s.add(Test(cmd, setup, files, exports)) + def test(*args, **kwargs): + s.add(Test(*args, **kwargs)) origin(test) s.add_generator(test_generator) Suite.available.append(s) diff --git a/suites/builtin.py b/suites/builtin.py index 6828200..548d8aa 100644 --- a/suites/builtin.py +++ b/suites/builtin.py @@ -6,10 +6,12 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:43 by charles #+# #+# # -# Updated: 2020/07/17 13:42:15 by charles ### ########.fr # +# Updated: 2020/07/19 20:35:45 by charles ### ########.fr # # # # ############################################################################ # +import os + import config from suite import suite @@ -36,6 +38,7 @@ def suite_echo(test): test('echo a "" b "" c "" d') test("echo -n a '' b '' c '' d") test('echo -n a "" b "" c "" d') + test("echo '' '' ''") @suite def suite_export(test): @@ -97,17 +100,77 @@ def suite_cd(test): 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 '\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") test("cd $HOME; pwd; echo $PWD"); - test("cd ~; pwd; echo $PWD"); - test("cd ~/..; pwd; echo $PWD"); - test("cd ~/../..; pwd; echo $PWD"); + test("cd $HOME; pwd; echo $PWD", exports={"HOME": os.getenv("HOME")}); + # test("cd ~; pwd; echo $PWD"); # do we have to handle ~ ? + # 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") + test("cd d", setup="mkdir -m=000 d") + test("cd d", setup="mkdir -m=001 d") + test("cd d", setup="mkdir -m=002 d") + test("cd d", setup="mkdir -m=003 d") + test("cd d", setup="mkdir -m=004 d") + test("cd d", setup="mkdir -m=005 d") + test("cd d", setup="mkdir -m=006 d") + test("cd d", setup="mkdir -m=007 d") + test("cd d", setup="mkdir -m=010 d") + test("cd d", setup="mkdir -m=020 d") + test("cd d", setup="mkdir -m=030 d") + test("cd d", setup="mkdir -m=040 d") + test("cd d", setup="mkdir -m=050 d") + test("cd d", setup="mkdir -m=060 d") + test("cd d", setup="mkdir -m=070 d") + test("cd d", setup="mkdir -m=100 d") + test("cd d", setup="mkdir -m=200 d") + test("cd d", setup="mkdir -m=300 d") + test("cd d", setup="mkdir -m=400 d") + test("cd d", setup="mkdir -m=500 d") + test("cd d", setup="mkdir -m=600 d") + test("cd d", setup="mkdir -m=700 d") + + test("cd d", setup="mkdir -m=755 d") + test("cd d", setup="mkdir -m=644 d") + test("cd d", setup="mkdir -m=311 d") + test("cd d", setup="mkdir -m=111 d") + test("cd d", setup="mkdir -m=222 d") + test("cd d", setup="mkdir -m=333 d") + + test("cd d", setup="mkdir -m=0777 d") + test("cd d", setup="mkdir -m=1000 d") + test("cd d", setup="mkdir -m=2000 d") + test("cd d", setup="mkdir -m=3000 d") + test("cd d", setup="mkdir -m=4000 d") + test("cd d", setup="mkdir -m=5000 d") + test("cd d", setup="mkdir -m=6000 d") + test("cd d", setup="mkdir -m=7000 d") + test("cd d", setup="mkdir -m=1777 d") + test("cd d", setup="mkdir -m=2777 d") + test("cd d", setup="mkdir -m=3777 d") + test("cd d", setup="mkdir -m=4777 d") + test("cd d", setup="mkdir -m=5777 d") + test("cd d", setup="mkdir -m=6777 d") + test("cd d", setup="mkdir -m=7777 d") + test("cd d", setup="mkdir -m=0000 d") + @suite def suite_unset(test): test("unset") @@ -142,10 +205,11 @@ def suite_pwd(test): test("pwd", setup="cd /") test("pwd", setup="cd $HOME") test("pwd | cat -e") + test("cd lnk; rmdir ../d; pwd", setup="mkdir d; ln -s d lnk") @suite def suite_env(test): - test("env") + 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") diff --git a/suites/cmd.py b/suites/cmd.py index 45941a8..a2738b5 100644 --- a/suites/cmd.py +++ b/suites/cmd.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 15:11:46 by charles #+# #+# # -# Updated: 2020/07/16 09:06:19 by charles ### ########.fr # +# Updated: 2020/07/19 18:55:52 by charles ### ########.fr # # # # ############################################################################ # @@ -74,17 +74,6 @@ def suite_redirection(test): test("> file", files=["file"]) test("< file", setup="echo bonjour > file") -@suite -def suite_edgecases(test): - test('echo "\\"" >>a"b""c" ', files=["abc"]) - test("echo " + ''.join([chr(i) for i in range(1, 127) if chr(i) not in '\n`"\'()|&><'])) - test("echo foo>bar", files=["bar"]) - test("echo foo >bar", files=["bar"]) - test("echo foo> bar", files=["bar"]) - test("echo foo > bar", files=["bar"]) - -@suite -def suite_cmd_error(test): test(">") test(">>") test("<") @@ -104,6 +93,21 @@ def suite_cmd_error(test): test("cat <<<< bar", setup="echo bonjour > bar") test("cat <<<<< bar", setup="echo bonjour > bar") + test("cat < doesnotexist") + + + +@suite +def suite_edgecases(test): + test('echo "\\"" >>a"b""c" ', files=["abc"]) + test("echo " + ''.join([chr(i) for i in range(1, 127) if chr(i) not in '\n`"\'()|&><'])) + test("echo foo>bar", files=["bar"]) + test("echo foo >bar", files=["bar"]) + test("echo foo> bar", files=["bar"]) + test("echo foo > bar", files=["bar"]) + +@suite +def suite_cmd(test): test("notfound") test("notfound a b c") @@ -215,3 +219,103 @@ def suite_cmd_path(test): 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)) + + test("./somefile", setup="touch somefile; chmod 000 somefile") + test("./somefile", setup="touch somefile; chmod 001 somefile") + test("./somefile", setup="touch somefile; chmod 002 somefile") + test("./somefile", setup="touch somefile; chmod 003 somefile") + test("./somefile", setup="touch somefile; chmod 004 somefile") + test("./somefile", setup="touch somefile; chmod 005 somefile") + test("./somefile", setup="touch somefile; chmod 006 somefile") + test("./somefile", setup="touch somefile; chmod 007 somefile") + test("./somefile", setup="touch somefile; chmod 010 somefile") + test("./somefile", setup="touch somefile; chmod 020 somefile") + test("./somefile", setup="touch somefile; chmod 030 somefile") + test("./somefile", setup="touch somefile; chmod 040 somefile") + test("./somefile", setup="touch somefile; chmod 050 somefile") + test("./somefile", setup="touch somefile; chmod 060 somefile") + test("./somefile", setup="touch somefile; chmod 070 somefile") + test("./somefile", setup="touch somefile; chmod 100 somefile") + test("./somefile", setup="touch somefile; chmod 200 somefile") + test("./somefile", setup="touch somefile; chmod 300 somefile") + test("./somefile", setup="touch somefile; chmod 400 somefile") + test("./somefile", setup="touch somefile; chmod 500 somefile") + test("./somefile", setup="touch somefile; chmod 600 somefile") + test("./somefile", setup="touch somefile; chmod 700 somefile") + + test("./somefile", setup="touch somefile; chmod 755 somefile") + test("./somefile", setup="touch somefile; chmod 644 somefile") + test("./somefile", setup="touch somefile; chmod 311 somefile") + test("./somefile", setup="touch somefile; chmod 111 somefile") + test("./somefile", setup="touch somefile; chmod 222 somefile") + test("./somefile", setup="touch somefile; chmod 333 somefile") + + test("somedir/", setup="mkdir somedir") + test("./somedir/", setup="mkdir somedir") + test("somedir", setup="mkdir somedir") + test("./somedir", setup="mkdir somedir") + test("somedir", setup="mkdir somedir") + + test("somedirsoftlink/", setup="mkdir somedir; ln -s somedir somedirsoftlink") + test("./somedirsoftlink/", setup="mkdir somedir; ln -s somedir somedirsoftlink") + test("somedirsoftlink", setup="mkdir somedir; ln -s somedir somedirsoftlink") + test("./somedirsoftlink", setup="mkdir somedir; ln -s somedir somedirsoftlink") + 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;" + + "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;" + + "ln -s somelink2 somelink3; ln -s somelink3 somelink4") + + test("_", setup="touch _") + test("'-'", setup="touch -") + test("./_", setup="touch _") + test("./-", setup="touch -") + test("./.", setup="touch .") + test("./..", setup="touch ..") + + test("./somefile", setup='touch somefile && chmod 0777 somefile') + test("./somefile", setup='touch somefile && chmod 1000 somefile') + test("./somefile", setup='touch somefile && chmod 2000 somefile') + test("./somefile", setup='touch somefile && chmod 3000 somefile') + test("./somefile", setup='touch somefile && chmod 4000 somefile') + test("./somefile", setup='touch somefile && chmod 5000 somefile') + test("./somefile", setup='touch somefile && chmod 6000 somefile') + test("./somefile", setup='touch somefile && chmod 7000 somefile') + test("./somefile", setup='touch somefile && chmod 1777 somefile') + test("./somefile", setup='touch somefile && chmod 2777 somefile') + test("./somefile", setup='touch somefile && chmod 3777 somefile') + test("./somefile", setup='touch somefile && chmod 4777 somefile') + test("./somefile", setup='touch somefile && chmod 5777 somefile') + test("./somefile", setup='touch somefile && chmod 6777 somefile') + test("./somefile", setup='touch somefile && chmod 7777 somefile') + test("./somefile", setup='touch somefile && chmod 0000 somefile') + + test("./somedir", setup='mkdir somedir && chmod 0777 somedir') + test("./somedir", setup='mkdir somedir && chmod 1000 somedir') + test("./somedir", setup='mkdir somedir && chmod 2000 somedir') + test("./somedir", setup='mkdir somedir && chmod 3000 somedir') + test("./somedir", setup='mkdir somedir && chmod 4000 somedir') + test("./somedir", setup='mkdir somedir && chmod 5000 somedir') + test("./somedir", setup='mkdir somedir && chmod 6000 somedir') + test("./somedir", setup='mkdir somedir && chmod 7000 somedir') + test("./somedir", setup='mkdir somedir && chmod 1777 somedir') + test("./somedir", setup='mkdir somedir && chmod 2777 somedir') + test("./somedir", setup='mkdir somedir && chmod 3777 somedir') + test("./somedir", setup='mkdir somedir && chmod 4777 somedir') + test("./somedir", setup='mkdir somedir && chmod 5777 somedir') + test("./somedir", setup='mkdir somedir && chmod 6777 somedir') + test("./somedir", setup='mkdir somedir && chmod 0000 somedir') + test("./somedir", setup='mkdir somedir && chmod 0000 somedir') diff --git a/suites/operation.py b/suites/operation.py index fd54f00..3c89589 100644 --- a/suites/operation.py +++ b/suites/operation.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:52 by charles #+# #+# # -# Updated: 2020/07/15 18:24:53 by charles ### ########.fr # +# Updated: 2020/07/19 10:23:22 by charles ### ########.fr # # # # ############################################################################ # @@ -41,9 +41,9 @@ def suite_and(test): test("echo bonjour &&echo je") test("echo bonjour && echo je") test("echo bonjour&&") - test("echo&& ") - test("echo && ") - test("echo &&") + # test("echo&& ") + # test("echo && ") + # test("echo &&") test("&&echo") test("&& echo") test(" && echo") @@ -64,9 +64,9 @@ def suite_or(test): test("echo bonjour ||echo je") test("echo bonjour || echo je") test("echo bonjour||") - test("echo|| ") - test("echo || ") - test("echo ||") + # test("echo|| ") + # test("echo || ") + # test("echo ||") test("||echo") test("|| echo") test(" || echo") @@ -91,9 +91,15 @@ def suite_pipe(test): test("ls -l | cat -e | cat -e | cat -e | cat -e", setup="touch a b c d; mkdir m1 m2 m3") test("ls -l | cat -e < a", setup="touch a b c d; mkdir m1 m2 m3; echo bonjour > a") - test("echo|") - test("echo |") - test("echo | ") + # TODO special test for potential segfault + # test("echo|") + # test("echo |") + # test("echo | ") test("|cat") test("| cat") test(" | cat") + + test("echo a | export A=a; echo $A") + test("export A=a | cat; echo $A") + test("echo a | A=a; echo $A") + test("A=a | cat; echo $A") diff --git a/suites/preprocess.py b/suites/preprocess.py index 503f3be..10417e5 100644 --- a/suites/preprocess.py +++ b/suites/preprocess.py @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:25:00 by charles #+# #+# # -# Updated: 2020/07/17 10:53:43 by charles ### ########.fr # +# Updated: 2020/07/19 16:01:07 by charles ### ########.fr # # # # ############################################################################ # @@ -35,6 +35,27 @@ def suite_quote(test): test('ls "" "" "" \'\' """"') test("ls '' '' '''' ''") + test("' echo' bonjour") + test("'echo ' bonjour") + test('" echo" bonjour') + test('"echo " bonjour') + + test("''echo bonjour") + test('""echo bonjour') + test("''''''''''''''''''''''''''''''''''''''''''''''''''''''''''echo bonjour") + test('""""""""""""""""""""""""""""""""""""""""""""""""""""""""""echo bonjour') + test("echo'' bonjour") + test('echo"" bonjour') + test("echo'''''''''''''''''''''''''''''''''''''''''''''''''''''''''' bonjour") + test('echo"""""""""""""""""""""""""""""""""""""""""""""""""""""""""" bonjour') + test("ec''ho bonjour") + test('ec""ho bonjour') + test("ec''''''''''''''''''''''''''''''''''''''''''''''''''''''''''ho bonjour") + test('ec""""""""""""""""""""""""""""""""""""""""""""""""""""""""""ho bonjour') + + test("'''''''e''''''''''c''''''''''''h''''''''o''''''''''''''''''''' bonjour") + test('"""""""e""""""""""c""""""""""""h""""""""o""""""""""""""""""""" bonjour') + @suite def suite_interpolation(test): test("echo $TEST", exports={"TEST": "bonjour"}) @@ -71,6 +92,9 @@ def suite_interpolation(test): test("echo $") + test("echo $\A $\B", exports={"A": "a", "B": "b"}) + test("echo $\A$\B", exports={"A": "a", "B": "b"}) + @suite def suite_glob(test): test("echo *") @@ -120,7 +144,16 @@ def suite_glob(test): test("echo /*") test("echo /etc/*") test("echo /usr/include/*.h") - test("echo /*/*") + test("echo /*/*", timeout=10) + test("echo /usr/*/*", timeout=10) + test("echo /usr/*") + test("echo /dev/*") + test("echo /etc/*") + test("echo /root/*") + test("echo /usr*") + test("echo /dev*") + test("echo /etc*") + test("echo /root*") test("echo *nothing") test("echo nothing*") @@ -142,6 +175,116 @@ def suite_glob(test): setup="mkdir src; touch src/a src/b src/c src/foo.c src/bar.c;\ mkdir inc; touch inc/a inc/b inc/c inc/foo.c inc/bar.c") + test("export A=*; echo $A") + test("A=*; echo $A") + + test("echo *", setup="mkdir d1; touch d1/a d1/b d1/c; ln -s d1 d1link") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; ln -s d1 d1link") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; ln -s d1 .d1link") + test("echo */*", setup="mkdir .d1; touch .d1/a .d1/b .d1/c; ln -s .d1 d1link") + test("echo .*/*", setup="mkdir d1; touch d1/a d1/b d1/c; ln -s d1 .d1link") + test("echo .*/*", setup="mkdir .d1; touch .d1/a .d1/b .d1/c; ln -s .d1 d1link") + + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 000 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 001 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 002 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 003 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 004 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 005 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 006 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 007 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 010 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 020 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 030 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 040 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 050 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 060 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 070 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 100 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 200 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 300 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 400 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 500 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 600 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 700 d1/a") + + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 755 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 644 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 311 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 111 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 222 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 333 d1/a") + + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 000 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 001 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 002 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 003 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 004 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 005 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 006 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 007 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 010 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 020 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 030 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 040 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 050 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 060 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 070 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 100 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 200 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 300 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 400 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 500 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 600 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 700 d1") + + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 755 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 644 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 311 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 111 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 222 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 333 d1") + + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 0777 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 1000 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 2000 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 3000 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 4000 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 5000 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 6000 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 7000 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 1777 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 2777 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 3777 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 4777 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 5777 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 6777 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 7777 d1/a") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 0000 d1/a") + + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 0777 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 1000 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 2000 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 3000 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 4000 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 5000 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 6000 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 7000 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 1777 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 2777 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 3777 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 4777 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 5777 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 6777 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 7777 d1") + test("echo */*", setup="mkdir d1; touch d1/a d1/b d1/c; chmod 0000 d1") + + test("echo *", setup="touch a; ln -s a b") + test("echo *", setup="touch a; ln -s a b; ln -s b c") + test("echo *", setup="touch a; ln -s a b; ln -s b c; ln -s c d") + test("echo d/*", setup="mkdir d; touch a b c d/d d/e d/f") + test("echo d/*", setup="mkdir d; touch a b c d/d d/e d/f; chmod 000 d") + @suite def suite_escape(test): test(r"echo \a") @@ -158,6 +301,11 @@ def suite_escape(test): test(r"echo \$PATH") test(r"echo \$\P\A\T\H") test(r"echo\ bonjour") + test(r"\ echo bonjour") + test(r" \ echo bonjour") + test(r" \ echo bonjour") + test(r" \ echo bonjour") + test(r" \ echo bonjour") @suite def suite_preprocess(test): @@ -6,7 +6,7 @@ # By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/06/16 21:48:50 by charles #+# #+# # -# Updated: 2020/07/15 18:14:28 by charles ### ########.fr # +# Updated: 2020/07/19 15:27:54 by charles ### ########.fr # # # # ############################################################################ # @@ -14,6 +14,8 @@ import os import sys import subprocess import shutil +import glob + import config class Captured: @@ -179,17 +181,28 @@ class Result: class Test: - def __init__(self, cmd: str, setup: str = "", files: [str] = [], exports: {str: str} = {}): + def __init__(self, + cmd: str, + setup: str = "", + files: [str] = [], + exports: {str: str} = {}, + timeout: float = config.TIMEOUT): self.cmd = cmd self.setup = setup self.files = files self.exports = exports self.result = None + self.timeout = timeout def run(self): expected = self._run_sandboxed(config.REFERENCE_PATH, "-c") actual = self._run_sandboxed(config.MINISHELL_PATH, "-c") - self.result = Result(self.cmd, self.files, expected, actual) + s = "" + if self.setup == "": + s = self.cmd + else: + s = "[{}] {}".format(self.setup, self.cmd) + self.result = Result(s, self.files, expected, actual) self.result.put() def _run_sandboxed(self, shell_path: str, shell_option: str) -> Captured: @@ -206,10 +219,18 @@ class Test: if self.setup != "": try: setup_status = subprocess.run( - self.setup, shell=True, cwd=config.SANDBOX_PATH, check=True) + self.setup, + shell=True, + cwd=config.SANDBOX_PATH, + stderr=subprocess.STDOUT, + stdout=subprocess.PIPE, + check=True + ) except subprocess.CalledProcessError as e: print("Error: `{}` setup command failed for `{}`\n\twith '{}'" - .format(setup, cmd, e.stderr.decode().strip())) + .format(self.setup, + self.cmd, + "no stderr" if e.stdout is None else e.stdout.decode().strip())) sys.exit(1) try: @@ -223,7 +244,7 @@ class Test: 'TERM': 'xterm-256color', **self.exports }, - timeout=0.5 + timeout=self.timeout ) except subprocess.TimeoutExpired: return Captured.timeout() @@ -238,5 +259,9 @@ class Test: files_content.append(f.read().decode()) except FileNotFoundError as e: files_content.append(None) - shutil.rmtree(config.SANDBOX_PATH) + try: + shutil.rmtree(config.SANDBOX_PATH) + except: + subprocess.check_output(["chmod", "777", *glob.glob(config.SANDBOX_PATH + "/*")]) + subprocess.check_output(["rm", "-rf", config.SANDBOX_PATH]) return Captured(output, process_status.returncode, files_content) |
