aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
authorCharles <sircharlesaze@gmail.com>2020-06-15 18:08:00 +0200
committerCharles <sircharlesaze@gmail.com>2020-06-15 18:08:00 +0200
commitb298afeb9da27038cbd54802a2d70504909427a3 (patch)
tree8754f0eb1c0fe198e3f8163558818fece8ae94fa /main.py
parent540d9a795ee6a12b4dfdebb72543d272d564d3b7 (diff)
downloadminishell_test-b298afeb9da27038cbd54802a2d70504909427a3.tar.gz
minishell_test-b298afeb9da27038cbd54802a2d70504909427a3.tar.bz2
minishell_test-b298afeb9da27038cbd54802a2d70504909427a3.zip
Rewrite in python
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/main.py b/main.py
new file mode 100755
index 0000000..addebf6
--- /dev/null
+++ b/main.py
@@ -0,0 +1,78 @@
+#!/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
+
+
+ignored_suites = []
+suites = {}
+current_suite = "default"
+
+def test(cmd, setup = None, *files):
+ if current_suite in ignored_suites:
+ return
+ expected = run_sandboxed(config.REFERENCE_SHELL_PATH, cmd)
+ actual = run_sandboxed(os.path.join(config.MINISHELL_DIR, config.MINISHELL_EXEC), cmd)
+
+ if actual != expected:
+ sys.stdout.write(red(config.FAIL_MARKER))
+ 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()