aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-23 09:08:16 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-23 10:31:05 +0200
commit3f2db95d5563c9c2b92a0531ddee28f79f438706 (patch)
treeee353ad4a0fcca9d59758f2e98efa3d9907096fc
parentb463bfa34471c1d3e65dfd4e22a99f4c84d7c5c6 (diff)
downloadminishell_test-3f2db95d5563c9c2b92a0531ddee28f79f438706.tar.gz
minishell_test-3f2db95d5563c9c2b92a0531ddee28f79f438706.tar.bz2
minishell_test-3f2db95d5563c9c2b92a0531ddee28f79f438706.zip
Added a few builtin/parenthesis tests
-rwxr-xr-xmain.py4
-rw-r--r--random_status.py7
-rw-r--r--suites/builtin.py118
-rw-r--r--suites/cmd.py93
-rw-r--r--suites/operation.py16
-rw-r--r--suites/parenthesis.py27
-rw-r--r--suites/preprocess.py (renamed from suites/suites.py)85
-rw-r--r--suites/status.py18
-rw-r--r--test.py32
9 files changed, 285 insertions, 115 deletions
diff --git a/main.py b/main.py
index 9674c03..9a407c0 100755
--- a/main.py
+++ b/main.py
@@ -8,9 +8,11 @@ import config
from args import parse_args
from suite import Suite
import suites.builtin
-import suites.suites
+import suites.cmd
+import suites.preprocess
import suites.operation
import suites.parenthesis
+import suites.status
def main():
if not os.path.exists(config.EXECUTABLES_PATH):
diff --git a/random_status.py b/random_status.py
new file mode 100644
index 0000000..171467f
--- /dev/null
+++ b/random_status.py
@@ -0,0 +1,7 @@
+import sys
+import random
+
+if __name__ == "__main__":
+ status = random.randrange(-2_000_000, 2_000_000)
+ print(status)
+ sys.exit(status)
diff --git a/suites/builtin.py b/suites/builtin.py
index 93e9db7..aba70a1 100644
--- a/suites/builtin.py
+++ b/suites/builtin.py
@@ -3,18 +3,26 @@ from suite import suite
@suite
def suite_echo(test):
+ test("echo")
test("echo bonjour")
test("echo lalalala lalalalal alalalalal alalalala")
test("echo lalalala lalalalal alalalalal alalalala")
test("echo " + config.LOREM)
+ test("echo -n")
test("echo -n bonjour")
test("echo -n lalalala lalalalal alalalalal alalalala")
test("echo -n lalalala lalalalal alalalalal alalalala")
test("echo -n " + config.LOREM)
+ test("echo bonjour -n")
+ test("echo -n bonjour -n")
+ test(" echo bonjour je")
+ test(" echo -n bonjour je")
+
@suite
def suite_export(test):
+ test("export")
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" +
@@ -56,21 +64,35 @@ def suite_export(test):
@suite
def suite_cd(test):
- test("cd .; pwd");
- test("cd ..; pwd");
- test("cd ../..; pwd");
- test("cd ../../..; pwd");
- test("cd ../../../..; pwd");
- test("cd ../../../../..; pwd");
- test("cd ../../../../../..; pwd");
- test("cd /; pwd");
- test("cd /etc; pwd");
- test("cd $HOME; pwd");
- test("cd ~; 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 $HOME; 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")
@suite
def suite_unset(test):
+ test("unset")
test("unset A; echo $A", setup="export A=a")
+ test("unset 'A '; echo $A", setup="export A=a")
+ test("unset 'A='; echo $A", setup="export A=a")
+ test("unset A B C; echo $A$B$C", setup="export A=a B=b C=c")
+ test("unset A; echo $A$B$C", setup="export A=a B=b C=c")
+ test("unset C; echo $A$B$C", setup="export A=a B=b C=c")
@suite
def suite_pwd(test):
@@ -80,12 +102,14 @@ def suite_pwd(test):
test("pwd", setup="cd ../../..")
test("pwd", setup="cd /")
test("pwd", setup="cd $HOME")
+ test("pwd | cat -e")
@suite
def suite_env(test):
test("env")
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")
@suite
def suite_exit(test):
@@ -93,3 +117,75 @@ def suite_exit(test):
test("exit 1")
test("exit 2")
test("exit 3")
+ test("exit 0")
+ test("exit -0")
+ test("exit -1")
+ test("exit 255")
+ test("exit 256")
+ test("exit 2000000")
+ test("exit -2000000")
+ test("exit 2147483647")
+ test("exit -2147483648")
+ test("exit 2147483648")
+ test("exit -2147483649")
+ test("exit 3147483648")
+ test("exit -3147483649")
+ test("exit 4294967295")
+ test("exit 4294967296")
+ test("exit -9223372036854775808")
+ test("exit 9223372036854775807")
+ test("exit -9223372036854775809")
+ test("exit 9223372036854775808")
+ test("exit 18446744073709551615")
+ test("exit 18446744073709551616")
+
+ test("exit +1")
+ test("exit +2")
+ test("exit +3")
+ test("exit +0")
+ test("exit +255")
+ test("exit +256")
+ test("exit +2000000")
+ test("exit +2147483647")
+
+ test("exit ++1")
+ test("exit ++2")
+ test("exit ++3")
+ test("exit ++0")
+ test("exit ++255")
+ test("exit ++256")
+ test("exit ++2000000")
+ test("exit ++2147483647")
+
+ test("exit --1")
+ test("exit --2")
+ test("exit --3")
+ test("exit --0")
+ test("exit --255")
+ test("exit --256")
+ test("exit --2000000")
+ test("exit --2147483647")
+
+ test("exit bonjour")
+ test("exit 0_")
+ test("exit _0")
+ 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 0 bonjour")
+ test("exit bonjour 0")
+ test("exit 0 1")
+ test("exit 0 1 2 3 4 5 6 7 8 9")
+
+ test("exit " + config.LOREM)
diff --git a/suites/cmd.py b/suites/cmd.py
new file mode 100644
index 0000000..018bd1a
--- /dev/null
+++ b/suites/cmd.py
@@ -0,0 +1,93 @@
+import config
+from suite import suite
+
+@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"])
+
+ 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("<")
+ 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")
+
+ test("notfound")
+ test("notfound a b c")
diff --git a/suites/operation.py b/suites/operation.py
index 7bed096..8d912d3 100644
--- a/suites/operation.py
+++ b/suites/operation.py
@@ -9,6 +9,9 @@ def suite_end(test):
test("echo; ")
test("echo ; ")
test("echo ;")
+ test("; echo")
+ test(" ;echo")
+ test(" ; echo")
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")
@@ -29,6 +32,9 @@ def suite_and(test):
test("echo&& ")
test("echo && ")
test("echo &&")
+ test("&&echo")
+ test("&& echo")
+ test(" && echo")
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")
@@ -49,6 +55,9 @@ def suite_or(test):
test("echo|| ")
test("echo || ")
test("echo ||")
+ test("||echo")
+ test("|| echo")
+ test(" || echo")
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")
@@ -69,3 +78,10 @@ def suite_pipe(test):
test("ls -l | cat -e | cat | cat | cat", setup="touch a b c d; mkdir m1 m2 m3")
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 | ")
+ test("|cat")
+ test("| cat")
+ test(" | cat")
diff --git a/suites/parenthesis.py b/suites/parenthesis.py
index c1df83b..30f1cce 100644
--- a/suites/parenthesis.py
+++ b/suites/parenthesis.py
@@ -14,5 +14,32 @@ def suite_parenthesis(test):
test("ls doesnotexist || (echo b && echo c)")
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"])
+
+ 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"])
+
+ 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")
+
+ 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")
+
+ test("(echo bonjour > 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")
+
test("(echo bonjour > f1) > f2", files=["f1", "f2"])
test("(cat -e > f1) < f2", setup="ls -l / > f2", files=["f1"])
+
+ test("(exit); echo bonjour")
+ test("(echo bonjour; exit; echo aurevoir)")
diff --git a/suites/suites.py b/suites/preprocess.py
index 9f6ce86..62588b7 100644
--- a/suites/suites.py
+++ b/suites/preprocess.py
@@ -18,91 +18,6 @@ def suite_quote(test):
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`"\'()|&><']))
- 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("<")
- 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"})
diff --git a/suites/status.py b/suites/status.py
new file mode 100644
index 0000000..f116ec1
--- /dev/null
+++ b/suites/status.py
@@ -0,0 +1,18 @@
+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/test.py b/test.py
index c076cd9..690e6a9 100644
--- a/test.py
+++ b/test.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/06/16 21:48:50 by charles #+# #+# #
-# Updated: 2020/06/17 14:36:17 by charles ### ########.fr #
+# Updated: 2020/06/23 09:18:29 by charles ### ########.fr #
# #
# ############################################################################ #
@@ -17,12 +17,14 @@ import shutil
import config
class Captured:
- def __init__(self, output: str, files_content: [str]):
+ def __init__(self, output: str, status: int, files_content: [str]):
self.output = output
+ self.status = status
self.files_content = files_content
def __eq__(self, other: 'Result') -> bool:
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)]))
class Result:
@@ -131,7 +133,9 @@ class Result:
def output_diff(self) -> str:
return (
- self.indicator("STATUS: TODO", "| ") + '\n'
+ self.indicator("STATUS: expected {} actual {}"
+ .format(self.expected.status, self.actual.status), "| ")
+ + '\n'
+ self.expected_header + '\n'
+ self.cat_e(self.expected.output)
+ self.actual_header + '\n'
@@ -145,20 +149,12 @@ class Result:
+ "=" * 80 + '\n')
def cat_e(self, s: str) -> str:
- ret = "$\n".join(s.split('\n'))
- if len(ret) < 2:
- return ret
- if ret[-1] != '\n':
- ret += '\n'
-
- if len(ret) > 80:
- breaks = []
- while len(ret) > 80:
- breaks.append(ret[:80])
- ret = ret[80:]
- ret = "\\\n".join(breaks)
-
- return ret
+ s = s.replace("\n", "$\n")
+ if len(s) < 2:
+ return s
+ if s[-1] != '\n':
+ s += '\n'
+ return s
class Test:
@@ -212,4 +208,4 @@ class Test:
except FileNotFoundError as e:
files_content.append(None)
shutil.rmtree(config.SANDBOX_PATH)
- return Captured(output, files_content)
+ return Captured(output, process_status.returncode, files_content)