blob: 68e3a5a9916aba0b3d49024f2be07979cdd628c0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
#!/usr/bin/python3
import os
import sys
import subprocess
import shutil
import config
def green(s):
return "\033[32m{}\033[0m".format(s)
def red(s):
return "\033[31m{}\033[0m".format(s)
def run_sandboxed(program: str, cmd: str) -> str:
try:
os.mkdir(config.SANDBOX_PATH)
except OSError:
pass
# os.system(self.setup_cmd)
current_dir = os.getcwd()
os.chdir(config.SANDBOX_PATH)
output = ""
try:
output = subprocess.check_output([program, "-c", cmd], stderr=subprocess.STDOUT)
except:
pass
os.chdir(current_dir)
shutil.rmtree(config.SANDBOX_PATH)
return output
status = 0
ignored_suites = []
suites = {}
current_suite = "default"
def test(cmd, setup = None, *files):
global status
if current_suite in ignored_suites:
return
expected = run_sandboxed(config.REFERENCE_SHELL_PATH, cmd)
actual = run_sandboxed(os.path.abspath(os.path.join(config.MINISHELL_DIR, config.MINISHELL_EXEC)), cmd)
if actual != expected:
sys.stdout.write(red(config.FAIL_MARKER))
status = 1
else:
sys.stdout.write(green(config.PASS_MARKER))
sys.stdout.flush()
if suites.get(current_suite) is None:
suites[current_suite] = []
suites[current_suite].append((expected, actual))
def test_echo():
test("echo bonjour")
test("echo je suis charles")
test("echo je suis charles")
test("'echo' 'bonjour'")
test("'echo' 'je' 'suis' 'charles'")
test("'echo' 'je' 'suis' 'charles'")
test('"echo" "bonjour"')
test('"echo" "je" "suis" "charles"')
test('"echo" "je" "suis" "charles"')
def main():
test_echo()
if __name__ == "__main__":
main()
sys.exit(status)
|