aboutsummaryrefslogtreecommitdiff
path: root/suites
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-17 14:04:56 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-17 14:04:56 +0200
commita5a7a2ae5132b2cc682fe8c2496680bf748bf9b3 (patch)
treef8f546fb3b73886af07a631d20e45e7d767e6095 /suites
parentf36a8ccb91cb71c1e4f15dc12cdecf3167eb1420 (diff)
downloadminishell_test-a5a7a2ae5132b2cc682fe8c2496680bf748bf9b3.tar.gz
minishell_test-a5a7a2ae5132b2cc682fe8c2496680bf748bf9b3.tar.bz2
minishell_test-a5a7a2ae5132b2cc682fe8c2496680bf748bf9b3.zip
Added builtin test (false positive until separator are implemented
Diffstat (limited to 'suites')
-rw-r--r--suites/__init__.py7
-rw-r--r--suites/builtin.py94
-rw-r--r--suites/suites.py223
3 files changed, 324 insertions, 0 deletions
diff --git a/suites/__init__.py b/suites/__init__.py
new file mode 100644
index 0000000..736c3c5
--- /dev/null
+++ b/suites/__init__.py
@@ -0,0 +1,7 @@
+import os
+import glob
+
+modules = glob.glob(os.path.join(os.path.dirname(__file__), "*.py"))
+__all__ = [os.path.basename(f)[:-3] for f in modules if os.path.isfile(f) and not f.endswith("__init__.py")]
+
+print(__all__)
diff --git a/suites/builtin.py b/suites/builtin.py
new file mode 100644
index 0000000..1211363
--- /dev/null
+++ b/suites/builtin.py
@@ -0,0 +1,94 @@
+import config
+from suite import suite
+
+@suite
+def suite_echo(test):
+ test("echo bonjour")
+ test("echo lalalala lalalalal alalalalal alalalala")
+ test("echo lalalala lalalalal alalalalal alalalala")
+ test("echo " + config.LOREM)
+
+ test("echo -n bonjour")
+ test("echo -n lalalala lalalalal alalalalal alalalala")
+ test("echo -n lalalala lalalalal alalalalal alalalala")
+ test("echo -n " + config.LOREM)
+
+@suite
+def suite_export(test):
+ test("export A=a")
+ test("export A=a B=b C=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")
+ test("export BONJOURJESUIS=a")
+ test("export bonjourjesuis=a")
+ test("export bonjour_je_suis=a")
+ test("export BONJOURJESUIS1=a")
+ test("export bO_nJq123o__1ju_je3234sui__a=a")
+ test("export a0123456789=a")
+ test("export abcdefghijklmnopqrstuvwxyz=a")
+ test("export ABCDEFGHIJKLMNOPQRSTUVWXYZ=a")
+ test("export __________________________=a")
+ test("export _bonjour_=a")
+ test("export _=a")
+ test("export 1=a")
+ test("export BONJOURJESUIS =a")
+ test("export BONJOURJESUIS= a")
+ test(r"export BONJOUR\\JESUIS=a")
+ test(r"export BONJOUR\'JESUIS=a")
+ test(r'export BONJOUR\"JESUIS=a')
+ test(r"export BONJOUR\$JESUIS=a")
+ test(r"export BONJOUR\&JESUIS=a")
+ test(r"export BONJOUR\|JESUIS=a")
+ test(r"export BONJOUR\;JESUIS=a")
+ test(r"export BONJOUR\_JESUIS=a")
+ test(r"export BONJOUR\0JESUIS=a")
+ test(r"export \B\O\N\ \ \ \ \ \ \ JOURJESUIS=a")
+ test(r"export A=\B\O\N\ \ \ \ \ \ \ JOURJESUIS")
+ test(r"export A='bonjour je suis charles'")
+ test(r'export A="bonjour je suis charles"')
+ test(r"export A==a")
+ test(r"export A===a")
+ test(r"export A====a")
+ test(r"export A=====a")
+ test(r"export A======a")
+ test(r"export A=a=a=a=a=a")
+
+@suite
+def suite_cd(test):
+ test("cd .");
+ test("cd ..");
+ test("cd ../..");
+ test("cd ../../..");
+ test("cd ../../../..");
+ test("cd ../../../../..");
+ test("cd ../../../../../..");
+ test("cd /");
+ test("cd /etc");
+ test("cd $HOME");
+ test("cd ~");
+
+@suite
+def suite_unset(test):
+ test("unset A", setup="export A=a")
+
+@suite
+def suite_pwd(test):
+ test("pwd")
+ test("pwd", setup="cd ..")
+ test("pwd", setup="cd ../..")
+ test("pwd", setup="cd ../../..")
+ test("pwd", setup="cd /")
+ test("pwd", setup="cd $HOME")
+
+@suite
+def suite_env(test):
+ test("env")
+ test("env", setup="export A=a")
+ test("env", setup="export A=a B=b C=c")
+
+@suite
+def suite_exit(test):
+ test("exit")
+ test("exit 1")
+ test("exit 2")
+ test("exit 3")
diff --git a/suites/suites.py b/suites/suites.py
new file mode 100644
index 0000000..56329e5
--- /dev/null
+++ b/suites/suites.py
@@ -0,0 +1,223 @@
+import config
+from suite import suite
+
+@suite
+def suite_quote(test):
+ test("'echo' 'bonjour'")
+ test("'echo' 'je' 'suis' 'charles'")
+
+ test('"echo" "bonjour"')
+ test('"echo" "je" "suis" "charles"')
+
+ test('echo je\'suis\'"charles"')
+ test('echo "je"suis\'charles\'')
+ test('echo \'je\'"suis"charles')
+
+ test('echo "\\""')
+ test('echo "\\$"')
+ test('echo "\\\\"')
+
+@suite
+def suite_redirection(test):
+ test("echo bonjour > test", setup="", files=["test"])
+ test("echo > test bonjour", setup="", files=["test"])
+ test("> test echo bonjour", setup="", files=["test"])
+ test("echo bonjour >> test", setup="", files=["test"])
+ test("echo >> test bonjour", setup="", files=["test"])
+ test(">> test echo bonjour", setup="", files=["test"])
+ test("cat < test", setup="echo bonjour > test")
+ test("echo bonjour > test", setup="", files=["test"])
+
+ test("echo > test'sticked' bonjour", setup="", files=["teststicked"])
+ test("> test'sticked' echo bonjour", setup="", files=["teststicked"])
+ test("echo bonjour >> test'sticked'", setup="", files=["teststicked"])
+ test("echo >> test'sticked' bonjour", setup="", files=["teststicked"])
+ test(">> test'sticked' echo bonjour", setup="", files=["teststicked"])
+ test("cat < test'sticked'", setup="echo bonjour > test'sticked'")
+ test("< test'sticked' cat", setup="echo bonjour > test'sticked'")
+
+ test("echo > test\"sticked\" bonjour", setup="", files=["teststicked"])
+ test("> test\"sticked\" echo bonjour", setup="", files=["teststicked"])
+ test("echo bonjour >> test\"sticked\"", setup="", files=["teststicked"])
+ test("echo >> test\"sticked\" bonjour", setup="", files=["teststicked"])
+ test(">> test\"sticked\" echo bonjour", setup="", files=["teststicked"])
+ test("cat < test\"sticked\"", setup="echo bonjour > test\"sticked\"")
+ test("< test\"sticked\" cat", setup="echo bonjour > test\"sticked\"")
+
+ test("echo > test'yo'\"sticked\" bonjour", setup="", files=["testyosticked"])
+ test("> test'yo'\"sticked\" echo bonjour", setup="", files=["testyosticked"])
+ test("echo bonjour >> test'yo'\"sticked\"", setup="", files=["testyosticked"])
+ test("echo >> test'yo'\"sticked\" bonjour", setup="", files=["testyosticked"])
+ test(">> test'yo'\"sticked\" echo bonjour", setup="", files=["testyosticked"])
+ test("cat < test'yo'\"sticked\"", setup="echo bonjour > test'yo'\"sticked\"")
+ test("< test'yo'\"sticked\" cat", setup="echo bonjour > test'yo'\"sticked\"")
+
+ test("echo bonjour > test > je > suis", setup="", files=["test", "je", "suis"])
+ test("echo > test > je bonjour > suis", setup="", files=["test", "je", "suis"])
+ test("> test echo bonjour > je > suis", setup="", files=["test", "je", "suis"])
+ test("echo bonjour >> test > je >> suis", setup="", files=["test", "je", "suis"])
+ test("echo >> test bonjour > je > suis", setup="", files=["test", "je", "suis"])
+ test(">> test echo > je bonjour > suis", setup="", files=["test", "je", "suis"])
+ test("cat < test < je", setup="echo bonjour > test; echo salut > je")
+
+ test("echo bonjour>test>je>suis", setup="", files=["test", "je", "suis"])
+ test(">test echo bonjour>je>suis", setup="", files=["test", "je", "suis"])
+ 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"])
+ 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"])
+ 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"])
+
+@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`"\'()|&><']))
+
+@suite
+def suite_cmd_error(test):
+ 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")
+
+@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 $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", 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("echo $")
+
+@suite
+def suite_glob(test):
+ test("echo *")
+ test("echo *", setup="touch a b c")
+ test("echo *.c", setup="touch a b c foo.c bar.c")
+ test("echo src/*.c", setup="mkdir src; touch src/a src/b src/c src/foo.c src/bar.c")
+ test("echo */*.c", setup="mkdir src; touch src/a src/b src/c src/foo.c src/bar.c")
+ test("echo */*.c",
+ 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("echo */*.h",
+ 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.h inc/bar.h")
+ test("echo l1/*/l3/*/*",
+ setup="mkdir -p l1/l2_1/l3; mkdir -p l1/l2_2; cd l1/l2_1/l3;\
+ 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.h inc/bar.h;\
+ cd ../../..; cd l1/l2_2; touch bonjour je suis")
+
+ test("echo */*/*/*/*.c",
+ setup="mkdir -p l1/l2/l3; cd l1/l2/l3;\
+ 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.h inc/bar.h")
+ test("echo */*/*/*/*.h",
+ setup="mkdir -p l1/l2/l3; cd l1/l2/l3;\
+ 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.h inc/bar.h")
+
+ test("echo */*/*/*.c",
+ setup="mkdir -p l1/l2/l3; cd l1/l2/l3;\
+ 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.h inc/bar.h")
+ test("echo */*/*/*.h",
+ setup="mkdir -p l1/l2/l3; cd l1/l2/l3;\
+ 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.h inc/bar.h")
+
+ test("echo */*/*/*/*/*.c",
+ setup="mkdir -p l1/l2/l3; cd l1/l2/l3;\
+ 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.h inc/bar.h")
+ test("echo */*/*/*/*/*.h",
+ setup="mkdir -p l1/l2/l3; cd l1/l2/l3;\
+ 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.h inc/bar.h")
+
+ test("echo /etc/*")
+ test("echo /usr/include/*.h")
+ test("echo /*/*")
+
+ test("echo *nothing")
+ test("echo nothing*")
+ test("echo *nothing*")
+
+ test("echo **")
+ test("echo **", setup="touch a b c")
+ test("echo **", setup="mkdir d; touch d/a d/b d/c")
+ test("echo */*", setup="mkdir d; touch d/a d/b d/c")
+ test("echo */a", setup="mkdir d; touch d/a d/b d/c")
+ test("echo d/*", setup="mkdir d; touch d/a d/b d/c")
+
+@suite
+def suite_escape(test):
+ test(r"echo \a")
+ test(r"\e\c\h\o bonjour")
+ test(r"echo charles\ ")
+ test(r"echo \ \ jesuis\ \ charles")
+ test(r"echo \ \ \ \ \ \ \ \ ")
+ test(r"echo \ \ \ \ \ \ \ \ \ \ \ \ \ \ ")
+ test(r"echo \$PATH")
+ test(r"echo \$\P\A\T\H")
+ test(r"echo\ bonjour")
+
+@suite
+def suite_preprocess(test):
+ test(r"echo \*", setup="touch a b c")
+ test(r"echo \*\*", setup="touch a b c")
+ test(r"echo \ *", setup="touch a b c")
+ test(r"echo *\.c", setup="touch a.c b.c c.c")
+ test(r"echo *.\c", setup="touch a.c b.c c.c")
+ test(r"echo *.c\ ", setup="touch a.c b.c c.c")
+ test("echo $A$B",
+ 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",
+ exports={"A": "*", "B": "/*.c"})
+ test("echo $A$B",
+ 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",
+ exports={"A": "*/.", "B": "*.c"})