aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-09-11 12:33:34 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-09-11 12:33:34 +0200
commit46ba2708f83bf46186c33bf84975d39e87f467c1 (patch)
tree8275c80bba98d63e81e3af9a1df8be62e0419003 /src
parentc0b1a90cf9c52a0c9b1623ac695516031d5ccdba (diff)
downloadminishell_test-46ba2708f83bf46186c33bf84975d39e87f467c1.tar.gz
minishell_test-46ba2708f83bf46186c33bf84975d39e87f467c1.tar.bz2
minishell_test-46ba2708f83bf46186c33bf84975d39e87f467c1.zip
Refactoring files, splited test.py and suite.py in packages
Diffstat (limited to 'src')
-rw-r--r--src/args.py40
-rw-r--r--src/config.py84
-rwxr-xr-xsrc/main.py67
-rw-r--r--src/suite/__init__.py2
-rw-r--r--src/suite/decorator.py27
-rw-r--r--src/suite/suite.py94
-rw-r--r--src/suites/__init__.py19
-rw-r--r--src/suites/builtin.py314
-rw-r--r--src/suites/cmd.py321
-rw-r--r--src/suites/operation.py105
-rw-r--r--src/suites/parenthesis.py57
-rw-r--r--src/suites/path.py71
-rw-r--r--src/suites/preprocess.py406
-rw-r--r--src/suites/status.py30
-rw-r--r--src/test/__init__.py13
-rw-r--r--src/test/captured.py39
-rw-r--r--src/test/result.py159
-rw-r--r--src/test/test.py113
18 files changed, 1961 insertions, 0 deletions
diff --git a/src/args.py b/src/args.py
new file mode 100644
index 0000000..2d0d57a
--- /dev/null
+++ b/src/args.py
@@ -0,0 +1,40 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# args.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:32 by charles #+# #+# #
+# Updated: 2020/09/10 13:52:37 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import argparse
+
+
+def parse_args():
+ parser = argparse.ArgumentParser(
+ description="Minishell test",
+ epilog="Make sure read README.md"
+ )
+ parser.add_argument(
+ "-v", "--verbose", action="count",
+ help="increase verbosity level (e.g -vv == 2)"
+ )
+ parser.add_argument(
+ "-b", "--build", action="store_true",
+ help="build minishell and exit"
+ )
+ parser.add_argument(
+ "-l", "--list", action="store_true",
+ help="print available test suites"
+ )
+ parser.add_argument(
+ "suites", nargs='*', metavar="suite",
+ help="test suites to run (-h for more information)"
+ )
+ tmp = parser.parse_args()
+ if tmp.verbose is None:
+ tmp.verbose = 1
+ return tmp
diff --git a/src/config.py b/src/config.py
new file mode 100644
index 0000000..ca697f5
--- /dev/null
+++ b/src/config.py
@@ -0,0 +1,84 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# config.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:19 by charles #+# #+# #
+# Updated: 2020/09/11 12:21:14 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+
+################################################################################
+# Minishell configuration file #
+################################################################################
+
+import os
+
+# run the bonus tests
+BONUS = False
+
+# minishell dir path
+MINISHELL_DIR = ".."
+
+# minishell executable
+MINISHELL_EXEC = "minishell"
+
+# build minishell before executing the test if set to True
+MINISHELL_BUILD = True
+
+# path to reference shell (shell which will be compared minishell)
+# has to support the -c option (sh, bash and zsh support it)
+REFERENCE_PATH = "/bin/bash"
+
+# log file path
+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 = ["rmdir", "env", "cat", "touch", "ls", "grep", "sh"]
+
+# $PATH environment variable passed to the shell
+PATH_VARIABLE = os.path.abspath(EXECUTABLES_PATH)
+
+# default test timeout
+TIMEOUT = 1
+
+LOREM = """
+Mollitia asperiores assumenda excepturi et ipsa. Nihil corporis facere aut a rem consequatur.
+Quas molestiae corporis et quibusdam maiores. Molestiae sed unde aut at sed.
+Deserunt quidem quidem aspernatur pariatur vel illum voluptatum. Culpa unde dolor aspernatur sit.
+Mollitia tenetur sed eaque autem placeat a aut in. Ipsam ea consequuntur omnis.
+Non et qui vel corrupti similique eum aut voluptatibus. Iste consequatur voluptatum et omnis debitis.
+Sit quia neque nihil consequatur sint. Velit libero ut aut et et rerum.
+Placeat cumque incidunt non repellat sunt perspiciatis ullam.
+Repellendus repudiandae nostrum quia quis corrupti.
+Rerum veniam earum cumque pariatur accusantium voluptatum omnis.
+Alias ut et et adipisci. Tempore omnis numquam ullam et animi et eveniet.
+Dolor itaque distinctio in. Magnam rerum quia est laboriosam repellat perspiciatis eos.
+Consequuntur quae corrupti atque. Numquam enim ut ut.
+Perspiciatis ut maxime et libero quo voluptas consequatur illum. Pariatur porro dolor cumque molestiae harum.
+"""
+LOREM = ' '.join(LOREM.split('\n'))
+
+###############################################################################
+# do not edit
+###############################################################################
+
+MINISHELL_PATH = os.path.abspath(
+ os.path.join(MINISHELL_DIR, MINISHELL_EXEC)
+)
+
+# 0, 1, 2
+VERBOSE_LEVEL = 1
+
+MINISHELL_ERROR_BEGIN = os.path.basename(MINISHELL_PATH) + ": "
+REFERENCE_ERROR_BEGIN = REFERENCE_PATH + ": line 0: "
diff --git a/src/main.py b/src/main.py
new file mode 100755
index 0000000..a71a485
--- /dev/null
+++ b/src/main.py
@@ -0,0 +1,67 @@
+#!/usr/bin/python3
+
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# main.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 15:11:52 by charles #+# #+# #
+# Updated: 2020/07/15 15:11:52 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import os
+import sys
+import shutil
+import distutils.spawn
+import subprocess
+
+import config
+from args import parse_args
+from suite import Suite
+import suites.builtin
+import suites.cmd
+import suites.preprocess
+import suites.operation
+import suites.parenthesis
+import suites.status
+import suites.path
+
+def main():
+ args = parse_args()
+ if args.list:
+ print("The available suites are:")
+ print('\n'.join([" - " + s.name for s in Suite.available]))
+ sys.exit(0)
+
+ if config.MINISHELL_BUILD or args.build:
+ try:
+ subprocess.run(["make", "-C", config.MINISHELL_DIR], check=True)
+ except subprocess.CalledProcessError:
+ sys.exit(1)
+ if args.build:
+ sys.exit(0)
+ if os.path.exists(config.EXECUTABLES_PATH):
+ shutil.rmtree(config.EXECUTABLES_PATH)
+ os.mkdir(config.EXECUTABLES_PATH)
+ for cmd in config.AVAILABLE_COMMANDS:
+ shutil.copy(distutils.spawn.find_executable(cmd), # FIXME search whole PATH
+ os.path.join(config.EXECUTABLES_PATH, cmd))
+
+
+ config.VERBOSE_LEVEL = args.verbose
+ Suite.setup(args.suites)
+ try:
+ Suite.run_all()
+ except KeyboardInterrupt:
+ shutil.rmtree(config.SANDBOX_PATH)
+
+ Suite.summarize()
+ Suite.save_log()
+ print("See", config.LOG_PATH, "for more information")
+
+
+if __name__ == "__main__":
+ main()
diff --git a/src/suite/__init__.py b/src/suite/__init__.py
new file mode 100644
index 0000000..55beb35
--- /dev/null
+++ b/src/suite/__init__.py
@@ -0,0 +1,2 @@
+from suite.suite import Suite
+from suite.decorator import suite
diff --git a/src/suite/decorator.py b/src/suite/decorator.py
new file mode 100644
index 0000000..55c9de6
--- /dev/null
+++ b/src/suite/decorator.py
@@ -0,0 +1,27 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# decorator.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/09/11 12:28:00 by charles #+# #+# #
+# Updated: 2020/09/11 12:28:14 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+from suite import Suite
+from test import Test
+
+def suite(origin):
+ """ decorator for a suite function (fmt: suite_[name]) """
+
+ name = origin.__name__[len("suite_"):]
+ s = Suite(name)
+ def test_generator():
+ def test(*args, **kwargs):
+ s.add(Test(*args, **kwargs))
+ origin(test)
+ s.add_generator(test_generator)
+ Suite.available.append(s)
+ return test_generator
diff --git a/src/suite/suite.py b/src/suite/suite.py
new file mode 100644
index 0000000..fee4aa9
--- /dev/null
+++ b/src/suite/suite.py
@@ -0,0 +1,94 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# suite.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:29 by charles #+# #+# #
+# Updated: 2020/09/11 12:27:47 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import config
+from test import Test
+
+
+class Suite:
+ available = []
+
+ @classmethod
+ def run_all(cls):
+ for s in cls.available:
+ s.run()
+
+ @classmethod
+ def setup(cls, asked_names: [str]):
+ if len(asked_names) == 0:
+ asked_names = [s.name for s in cls.available]
+ cls.available = [s for s in cls.available if s.name in asked_names]
+ for s in cls.available:
+ s.generate()
+
+ @classmethod
+ def available_names(cls) -> [str]:
+ return [s.name for s in cls.available]
+
+ def __init__(self, name: str):
+ self.name = name
+ self.generator_func = None
+ self.tests = []
+
+ def add(self, test):
+ self.tests.append(test)
+
+ def add_generator(self, generator):
+ self.generator_func = generator
+
+ def run(self):
+ if config.VERBOSE_LEVEL == 0:
+ print(self.name + ": ", end="")
+ else:
+ print("{} {:#<41}".format("#" * 39, self.name + " "))
+ for t in self.tests:
+ t.run()
+ if config.VERBOSE_LEVEL == 0:
+ print()
+
+ def generate(self):
+ self.generator_func()
+
+ def total(self) -> (int, int):
+ passed_total = 0
+ for t in self.tests:
+ if t.result is None:
+ return (-1, -1)
+ if t.result.passed:
+ passed_total += 1
+ return (passed_total, len(self.tests) - passed_total)
+
+ @classmethod
+ def summarize(cls):
+ pass_sum = 0
+ fail_sum = 0
+ print("\nSummary:")
+ for s in cls.available:
+ (pass_total, fail_total) = s.total()
+ if pass_total == -1:
+ continue
+ pass_sum += pass_total
+ fail_sum += fail_total
+ print("{:<15} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m"
+ .format(s.name, pass_total, fail_total))
+ print("{:<15} \033[32m{:3} [PASS]\033[0m \033[31m{:3} [FAIL]\033[0m"
+ .format("TOTAL", pass_sum, fail_sum))
+
+ @classmethod
+ def save_log(cls):
+ with open(config.LOG_PATH, "w") as log_file:
+ for s in cls.available:
+ for t in s.tests:
+ if t.result is not None and t.result.failed:
+ t.result.colored = False
+ t.result.set_colors()
+ log_file.write(t.result.full_diff() + '\n')
diff --git a/src/suites/__init__.py b/src/suites/__init__.py
new file mode 100644
index 0000000..68bad1f
--- /dev/null
+++ b/src/suites/__init__.py
@@ -0,0 +1,19 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# __init__.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:48 by charles #+# #+# #
+# Updated: 2020/09/09 15:20:22 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+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/src/suites/builtin.py b/src/suites/builtin.py
new file mode 100644
index 0000000..30297e0
--- /dev/null
+++ b/src/suites/builtin.py
@@ -0,0 +1,314 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# builtin.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:43 by charles #+# #+# #
+# Updated: 2020/09/09 13:28:02 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import os
+
+import config
+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")
+
+ test("echo a '' b '' c '' d")
+ 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):
+ test("export")
+ # test("export A=; env | grep A=; echo $A")
+ # test("export A; env | grep A; echo $A")
+ 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" +
+ "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" +
+ "; echo $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")
+ test("export BONJOURJESUIS=a; echo $BONJOURJESUIS")
+ test("export bonjourjesuis=a; echo $bonjourjesuis")
+ test("export bonjour_je_suis=a; echo $bonjour_je_suis")
+ test("export BONJOURJESUIS1=a; echo $BONJOURJESUIS1")
+ test("export bO_nJq123o__1ju_je3234sui__a=a; echo $bO_nJq123o__1ju_je3234sui__a")
+ test("export a0123456789=a; echo $a0123456789")
+ test("export abcdefghijklmnopqrstuvwxyz=a; echo $abcdefghijklmnopqrstuvwxyz")
+ test("export ABCDEFGHIJKLMNOPQRSTUVWXYZ=a; echo $ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+ test("export __________________________=a; echo $__________________________")
+ test("export _bonjour_=a; echo $_bonjour_")
+ test("export _=a; echo $_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; echo $A")
+ test(r"export A='bonjour je suis charles'; echo $A")
+ test(r'export A="bonjour je suis charles"; echo $A')
+ test(r"export A==a; echo $A")
+ test(r"export A===a; echo $A")
+ test(r"export A====a; echo $A")
+ test(r"export A=====a; echo $A")
+ test(r"export A======a; echo $A")
+ test(r"export A=a=a=a=a=a; echo $A")
+ test("export A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C")
+ test("export 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C")
+ test("export A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf '; echo $A$B$C")
+ test("export A B C; echo $A$B$C")
+
+ test("export $TEST", exports={"TEST": "A=a"})
+
+@suite
+def suite_cd(test):
+ 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 ''; 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 $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 ' /'; 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 //home; pwd; echo $PWD")
+ test("cd ' //home'; pwd; echo $PWD")
+ test("cd ' //home '; pwd; echo $PWD")
+
+ 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")
+ 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 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C",
+ setup="export A=a B=b C=c")
+ test("unset 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C; echo $A$B$C",
+ setup="export A=a B=b C=c")
+ test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf '; 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")
+
+ test("unset A B C", setup="export A=a B=b C=c")
+ test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C",
+ setup="export A=a B=b C=c")
+ test("unset 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf ' C",
+ setup="export A=a B=b C=c")
+ test("unset A 'asdf ' B ' asdf asdf asd f' ' asdf ' '' 'asdf '",
+ setup="export A=a B=b C=c")
+ test("unset A", setup="export A=a B=b C=c")
+
+@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")
+ test("pwd | cat -e")
+ test("cd lnk; rmdir ../d; pwd", setup="mkdir d; ln -s d lnk")
+
+@suite
+def suite_env(test):
+ 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")
+
+@suite
+def suite_exit(test):
+ test("exit")
+ test("exit 1")
+ test("exit 2")
+ test("exit 3")
+ test("exit ' 3'")
+ test("exit '\t3'")
+ test("exit '\t\f\r 3'")
+ test("exit '3 '")
+ test("exit '3\t'")
+ test("exit '3\r'")
+ test("exit '3\t\f\r '")
+ test("exit '3 a'")
+ test("exit '3\t\t\ta'")
+ 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/src/suites/cmd.py b/src/suites/cmd.py
new file mode 100644
index 0000000..1302ae3
--- /dev/null
+++ b/src/suites/cmd.py
@@ -0,0 +1,321 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# cmd.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 15:11:46 by charles #+# #+# #
+# Updated: 2020/09/10 14:25:40 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import distutils
+
+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")
+
+ 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("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")
+
+@suite
+def suite_cmd_variable(test):
+ test("A=a sh -c 'echo $A'")
+ test("A=a B=b sh -c 'echo $A$B'")
+ test("A=a B=b C=c D=d E=e F=f G=g H=h sh -c 'echo $A$B$C$D$E$F$G$H'")
+ test("A=a A=bonjour sh -c 'echo $A'")
+ test("A=aA=bonjour sh -c 'echo $A'")
+ test("BONJOURJESUIS=a sh -c 'echo $BONJOURJESUIS'")
+ test("bonjourjesuis=a sh -c 'echo $bonjourjesuis'")
+ test("bonjour_je_suis=a sh -c 'echo $bonjour_je_suis'")
+ test("BONJOURJESUIS1=a sh -c 'echo $BONJOURJESUIS1'")
+ test("bO_nJq123o__1ju_je3234sui__a=a sh -c 'echo $bO_nJq123o__1ju_je3234sui__a'")
+ test("a0123456789=a sh -c 'echo $a0123456789'")
+ test("abcdefghijklmnopqrstuvwxyz=a sh -c 'echo $abcdefghijklmnopqrstuvwxyz'")
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZ=a sh -c 'echo $ABCDEFGHIJKLMNOPQRSTUVWXYZ'")
+ test("__________________________=a sh -c 'echo $__________________________'")
+ test("_bonjour_=a sh -c 'echo $_bonjour_'")
+ test("_=a sh -c 'echo $_a'")
+ test("1=a")
+ test("BONJOURJESUIS =a sh -c 'echo $BONJOURJESUIS '")
+ test("BONJOURJESUIS= a sh -c 'echo $BONJOURJESUIS'")
+ test(r"BONJOUR\\JESUIS=a sh -c 'echo $BONJOUR\\JESUIS'")
+ test(r'BONJOUR\'JESUIS=a sh -c "echo $BONJOUR\'JESUIS"')
+ test(r'BONJOUR\"JESUIS=a sh -c "echo $BONJOUR\"JESUIS"')
+ test(r"BONJOUR\$JESUIS=a sh -c 'echo $BONJOUR\$JESUIS'")
+ test(r"BONJOUR\&JESUIS=a sh -c 'echo $BONJOUR\&JESUIS'")
+ test(r"BONJOUR\|JESUIS=a sh -c 'echo $BONJOUR\|JESUIS'")
+ test(r"BONJOUR\;JESUIS=a sh -c 'echo $BONJOUR\;JESUIS'")
+ test(r"BONJOUR\_JESUIS=a sh -c 'echo $BONJOUR\_JESUIS'")
+ test(r"BONJOUR\0JESUIS=a sh -c 'echo $BONJOUR\0JESUIS'")
+ test(r"\B\O\N\ \ \ \ \ \ \ JOURJESUIS=a sh -c 'echo $\B\O\N\ \ \ \ \ \ \ JOURJESUIS'")
+ test(r"A=\B\O\N\ \ \ \ \ \ \ JOURJESUIS sh -c 'echo $A'")
+ test(r"A='bonjour je suis charles' sh -c 'echo $A'")
+ test(r'A="bonjour je suis charles" sh -c "echo $A"')
+ test(r"A==a sh -c 'echo $A'")
+ test(r"A===a sh -c 'echo $A'")
+ test(r"A====a sh -c 'echo $A'")
+ test(r"A=====a sh -c 'echo $A'")
+ test(r"A======a sh -c 'echo $A'")
+ test(r"A=a=a=a=a=a sh -c 'echo $A'")
+
+ test("A=a; echo $A")
+ test("A=a B=b; echo $A$B")
+ test("A=a B=b C=c D=d E=e F=f G=g H=h; echo $A$B$C$D$E$F$G$H")
+ test("A=a A=bonjour; echo $A")
+ test("A=aA=bonjour; echo $A")
+ test("BONJOURJESUIS=a; echo $BONJOURJESUIS")
+ test("bonjourjesuis=a; echo $bonjourjesuis")
+ test("bonjour_je_suis=a; echo $bonjour_je_suis")
+ test("BONJOURJESUIS1=a; echo $BONJOURJESUIS1")
+ test("bO_nJq123o__1ju_je3234sui__a=a; echo $bO_nJq123o__1ju_je3234sui__a")
+ test("a0123456789=a; echo $a0123456789")
+ test("abcdefghijklmnopqrstuvwxyz=a; echo $abcdefghijklmnopqrstuvwxyz")
+ test("ABCDEFGHIJKLMNOPQRSTUVWXYZ=a; echo $ABCDEFGHIJKLMNOPQRSTUVWXYZ")
+ test("__________________________=a; echo $__________________________")
+ test("_bonjour_=a; echo $_bonjour_")
+ test("_=a; echo $_a")
+ test("BONJOURJESUIS =a; echo $BONJOURJESUIS ")
+ test("BONJOURJESUIS= a; echo $BONJOURJESUIS")
+ test(r"BONJOUR\\JESUIS=a; echo $BONJOUR\\JESUIS")
+ test(r"BONJOUR\'JESUIS=a; echo $BONJOUR\'JESUIS")
+ test(r'BONJOUR\"JESUIS=a; echo $BONJOUR\"JESUIS')
+ test(r"BONJOUR\$JESUIS=a; echo $BONJOUR\$JESUIS")
+ test(r"BONJOUR\&JESUIS=a; echo $BONJOUR\&JESUIS")
+ test(r"BONJOUR\|JESUIS=a; echo $BONJOUR\|JESUIS")
+ test(r"BONJOUR\;JESUIS=a; echo $BONJOUR\;JESUIS")
+ test(r"BONJOUR\_JESUIS=a; echo $BONJOUR\_JESUIS")
+ test(r"BONJOUR\0JESUIS=a; echo $BONJOUR\0JESUIS")
+ test(r"\B\O\N\ \ \ \ \ \ \ JOURJESUIS=a; echo $\B\O\N\ \ \ \ \ \ \ JOURJESUIS")
+ test(r"A=\B\O\N\ \ \ \ \ \ \ JOURJESUIS; echo $A")
+ test(r"A='bonjour je suis charles'; echo $A")
+ test(r'A="bonjour je suis charles"; echo $A')
+ test(r"A==a; echo $A")
+ test(r"A===a; echo $A")
+ test(r"A====a; echo $A")
+ test(r"A=====a; echo $A")
+ test(r"A======a; echo $A")
+ test(r"A=a=a=a=a=a; echo $A")
+
+ test("PATH=a ls")
+ test("PATH=a echo aa")
+ test("A=a echo $A")
+ test("A=a B=b echo $A$B")
+ test("A=a B=b C=c D=d E=e F=f G=g H=h echo $A$B$C$D$E$F$G$H")
+ test("A=$PATH sh -c 'echo $A'")
+ test("A=\"$PATH je suis\" sh -c 'echo $A'")
+ test("A='$PATH je suis' sh -c 'echo $A'")
+ test("$TEST sh -c 'echo $A'", setup="export TEST='A=a'")
+ test("'BONJOURJESUIS''=''a' sh -c 'echo $BONJOURJESUIS'")
+ test('"BONJOURJESUIS""=""a" sh -c "echo $BONJOURJESUIS"')
+
+@suite
+def suite_cmd_path(test):
+ ls_path = distutils.spawn.find_executable("ls")
+ cat_path = distutils.spawn.find_executable("cat")
+
+ test(ls_path, setup="touch a b c")
+ test(ls_path + " -l", setup="touch a b c")
+ test("./bonjour", setup="touch a b c; cp {} bonjour".format(ls_path))
+ test("./bonjour -l", setup="touch a b c; cp {} bonjour".format(ls_path))
+ test("./somedir/bonjour -l",
+ setup="mkdir somedir; touch a b c; touch somedir/d somedir/e;" +
+ "cp {} somedir/bonjour".format(ls_path))
+
+ test("./ls . a b c",
+ 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/src/suites/operation.py b/src/suites/operation.py
new file mode 100644
index 0000000..3c89589
--- /dev/null
+++ b/src/suites/operation.py
@@ -0,0 +1,105 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# operation.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:52 by charles #+# #+# #
+# Updated: 2020/07/19 10:23:22 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+from suite import suite
+
+@suite
+def suite_end(test):
+ test("echo bonjour; echo je")
+ 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 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")
+ 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")
+
+ test("ls doesnotexists ; echo bonjour")
+ test("ls doesnotexists; echo bonjour")
+ test("echo bonjour; ls doesnotexists")
+
+@suite
+def suite_and(test):
+ test("echo bonjour&& echo je")
+ 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 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")
+ 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")
+
+ test("ls doesnotexists && echo bonjour")
+ test("ls doesnotexists&& echo bonjour")
+ test("echo bonjour&& ls doesnotexists")
+
+@suite
+def suite_or(test):
+ test("echo bonjour|| echo je")
+ 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 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")
+ 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")
+
+ test("ls doesnotexists || echo bonjour")
+ test("ls doesnotexists|| echo bonjour")
+ test("echo bonjour|| ls doesnotexists")
+
+@suite
+def suite_pipe(test):
+ test("echo bonjour | cat")
+ test("echo bonjour | cat -e")
+ test("ls | cat -e", setup="touch a b c d; mkdir m1 m2 m3")
+ test("ls -l | cat -e", setup="touch a b c d; mkdir m1 m2 m3")
+ 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")
+
+ # 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/src/suites/parenthesis.py b/src/suites/parenthesis.py
new file mode 100644
index 0000000..a06fdda
--- /dev/null
+++ b/src/suites/parenthesis.py
@@ -0,0 +1,57 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# parenthesis.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:57 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:57 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+from suite import suite
+
+@suite
+def suite_parenthesis(test):
+ test("(echo bonjour)")
+ test("(echo bonjour )")
+ test("( echo bonjour )")
+
+ test("(echo a && echo b) && echo c")
+ test("(echo a || echo b) || echo c")
+ test("(ls doesnotexist || echo b) || echo c")
+ test("(echo a || ls doesnotexist) || echo c")
+ test("echo aa && (echo b && echo c)")
+ 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/src/suites/path.py b/src/suites/path.py
new file mode 100644
index 0000000..b30215f
--- /dev/null
+++ b/src/suites/path.py
@@ -0,0 +1,71 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# path.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/09/09 15:12:58 by charles #+# #+# #
+# Updated: 2020/09/09 15:39:17 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import config
+from suite import suite
+
+@suite
+def suite_path(test):
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 000 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 001 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 002 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 003 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 004 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 005 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 006 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 007 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 010 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 020 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 030 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 040 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 050 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 060 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 070 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 100 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 200 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 300 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 400 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 500 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 600 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 700 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 755 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 644 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 311 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 111 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 222 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 333 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 0777 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 1000 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 2000 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 3000 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 4000 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 5000 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 6000 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 7000 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 1777 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 2777 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 3777 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 4777 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 5777 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 6777 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 7777 ./path/a", exports={"PATH": "path"})
+ test("a", setup="mkdir path && cp /bin/ls ./path/a && chmod 0000 ./path/a", exports={"PATH": "path"})
+
+ test("b", setup="mkdir path && cp /bin/ls ./path/a && ln -s ./path/a ./path/b", exports={"PATH": "path"})
+
+ test("ls", exports={"PATH": "doesnotexits"})
+ test("ls", exports={"PATH": "doesnotexits:asdfasdfas"})
+ test("ls", exports={"PATH": "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"})
+ test("ls", exports={"PATH": "________"})
+ test("ls", exports={"PATH": " "})
+ test("ls", exports={"PATH": " : "})
+ test("ls", exports={"PATH": " /bin "})
diff --git a/src/suites/preprocess.py b/src/suites/preprocess.py
new file mode 100644
index 0000000..a34e18d
--- /dev/null
+++ b/src/suites/preprocess.py
@@ -0,0 +1,406 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# preprocess.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:25:00 by charles #+# #+# #
+# Updated: 2020/09/09 12:50:34 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+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 "\\\\"')
+
+ test('ls ""')
+ test("ls ''")
+
+ 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"})
+ 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"$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")
+ test("echo $A$B")
+ test("echo $A$B$C")
+ test("echo $A$B$C$D")
+
+ test("echo [$A]", exports={"A": r"bonjour\je"})
+ test("echo [$A]", exports={"A": r"\b\\o\\\nj\\\\\\\our\\je\\\\"})
+ test("echo [$A]", exports={"A": r" \b\\o\\\nj\\\\\\\our\\je\\\\"})
+ test("echo [$A]", exports={"A": r"\b\\o\\\nj\\\\\\\our\\je\\\\ "})
+ test("echo [$A]", exports={"A": r" \b\\o\\\nj\\\\\\\our\\je\\\\ "})
+ test("echo [$A]", exports={"A": r"a \b\\o\\\nj\\\\\\\our\\je\\\\ b"})
+ test("echo [$A]", exports={"A": r" a \b\\o\\\nj\\\\\\\our\\je\\\\ b "})
+ test("echo [$A]", exports={"A": r" "})
+ test("echo [$A]", exports={"A": r" "})
+ test("echo [$A]", exports={"A": r"\ "})
+ test("echo [$A]", exports={"A": r" \ "})
+
+ test(r"echo \ \ \ \ \ \ \ $A\ \ \ \ \ \ ", exports={"A": "bonjour"})
+ test(r"echo \ \ \ \ \ \ \ $A\ \ \ \ \ \ ", exports={"A": "bonjour je suis"})
+ test(r"echo \ \ \ \ \ \ \ $A\ \ \ \ \ \ ", exports={"A": " bonjour je suis "})
+
+ test('echo $A', exports={"A": "bonjour je suis splited"})
+ test('echo $A', exports={"A": "bonjour je suis splited"})
+ test('echo $A', exports={"A": " bonjour je suis splited "})
+ test('echo [$A]', exports={"A": "bonjour je suis splited"})
+ test('echo [$A]', exports={"A": "bonjour je suis splited"})
+ test('echo [$A]', exports={"A": " bonjour je suis splited "})
+ test('echo "[$A]"', exports={"A": "bonjour je suis splited"})
+ test('echo "[$A]"', exports={"A": "bonjour je suis splited"})
+ test('echo "[$A]"', exports={"A": " bonjour je suis splited "})
+ test('echo \ $A', exports={"A": "bonjour je suis splited"})
+ test('echo \ $A', exports={"A": "bonjour je suis splited"})
+ test('echo \ $A', exports={"A": " bonjour je suis splited "})
+ test('echo $A\ ', exports={"A": "bonjour je suis splited"})
+ test('echo $A\ ', exports={"A": "bonjour je suis splited"})
+ test('echo $A\ ', exports={"A": " bonjour je suis splited "})
+ test('echo $A$A$A', exports={"A": " bonjour je suis splited "})
+ 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("$LS", exports={"LS": "ls -l"}, setup="touch a b c")
+
+ test("echo $")
+ test("echo \$")
+ test("echo \$\$\$\$")
+ test("echo \$$\$$")
+
+ test("echo $\A $\B", exports={"A": "a", "B": "b"})
+ test("echo $\A$\B", exports={"A": "a", "B": "b"})
+
+ test("echo $A", exports={"A": " "})
+ test("echo $A", exports={"A": " "})
+ test("echo $A", exports={"A": " "})
+ test("echo $A", exports={"A": " "})
+ test("echo $A", exports={"A": " a "})
+ test("echo $A", exports={"A": " "})
+ test("echo $A", exports={"A": " a "})
+
+ test("echo @$A@", exports={"A": " "})
+ test("echo @ $A@", exports={"A": " "})
+ test("echo @$A @", exports={"A": " "})
+ test("echo @$A@", exports={"A": " "})
+ test("echo '@'$A'@'", exports={"A": " "})
+ test("echo '@' $A'@'", exports={"A": " "})
+ test("echo '@'$A '@'", exports={"A": " "})
+ test('echo "@"$A"@"', exports={"A": " "})
+ test('echo "@" $A"@"', exports={"A": " "})
+ test('echo "@"$A "@"', exports={"A": " "})
+
+ test('echo @"$A"@', exports={"A": " "})
+ test('echo @ "$A"@', exports={"A": " "})
+ test('echo @"$A" @', exports={"A": " "})
+ test('echo @"$A"@', exports={"A": " "})
+ test("echo '@'\"$A\"'@'", exports={"A": " "})
+ test("echo '@' \"$A\"'@'", exports={"A": " "})
+ test("echo '@'\"$A\" '@'", exports={"A": " "})
+ test('echo "@""$A""@"', exports={"A": " "})
+ test('echo "@" "$A""@"', exports={"A": " "})
+ test('echo "@""$A" "@"', exports={"A": " "})
+
+ test('echo $A$B$C', exports={"A": "", "B": "", "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 \ \ jesuis\; \ charles")
+ test(r"echo \ \ jesuis\&\& \ charles")
+ test(r"echo \ \ jesuis\|\| \ charles")
+ test(r"echo \ \ jesuis \|\| \ 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")
+ 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):
+# 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"})
+
+# @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 /*")
+# test("echo /etc/*")
+# test("echo /usr/include/*.h")
+# # 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*")
+# test("echo *nothing*")
+#
+# test("echo a*b", setup="touch ab aab aaaaab aaaaaaaab acccccb acb abbbb")
+# test("echo a**b", setup="touch ab aab aaaaab aaaaaaaab acccccb acb abbbb")
+# test("echo a***b", setup="touch ab aab aaaaab aaaaaaaab acccccb acb abbbb")
+# test("echo a****b", setup="touch ab aab aaaaab aaaaaaaab acccccb acb abbbb")
+#
+# 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")
+#
+# test("*")
+# test("*", setup="touch a b c")
+# test("*.c", setup="touch a b c foo.c bar.c")
+# test("src/*.c", setup="mkdir src; touch src/a src/b src/c src/foo.c src/bar.c")
+# test("*/*.c", setup="mkdir src; touch src/a src/b src/c src/foo.c src/bar.c")
+# test("*/*.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("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")
diff --git a/src/suites/status.py b/src/suites/status.py
new file mode 100644
index 0000000..62c076e
--- /dev/null
+++ b/src/suites/status.py
@@ -0,0 +1,30 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# status.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/07/15 18:24:40 by charles #+# #+# #
+# Updated: 2020/07/15 18:24:40 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+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/src/test/__init__.py b/src/test/__init__.py
new file mode 100644
index 0000000..7601878
--- /dev/null
+++ b/src/test/__init__.py
@@ -0,0 +1,13 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# __init__.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/09/11 12:18:14 by charles #+# #+# #
+# Updated: 2020/09/11 12:26:30 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+from test.test import Test
diff --git a/src/test/captured.py b/src/test/captured.py
new file mode 100644
index 0000000..e47590b
--- /dev/null
+++ b/src/test/captured.py
@@ -0,0 +1,39 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# captured.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/09/11 12:16:25 by charles #+# #+# #
+# Updated: 2020/09/11 12:16:51 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import config
+
+class Captured:
+ def __init__(self, output: str, status: int, files_content: [str], is_timeout: bool = False):
+ lines = output.split('\n')
+ for i, l in enumerate(lines):
+ if l.find(config.REFERENCE_ERROR_BEGIN) == 0:
+ lines[i] = l.replace(config.REFERENCE_ERROR_BEGIN, config.MINISHELL_ERROR_BEGIN, 1)
+ elif l.find(config.REFERENCE_PATH + ": ") == 0:
+ lines[i] = l.replace(config.REFERENCE_PATH + ": ", config.MINISHELL_ERROR_BEGIN, 1)
+
+ self.output = '\n'.join(lines)
+
+ self.status = status
+ self.files_content = files_content
+ self.is_timeout = is_timeout
+
+ def __eq__(self, other: 'Result') -> bool:
+ if self.is_timeout:
+ return self.is_timeout == other.is_timeout
+ 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)]))
+
+ @staticmethod
+ def timeout():
+ return Captured("", 0, [], is_timeout = True)
diff --git a/src/test/result.py b/src/test/result.py
new file mode 100644
index 0000000..5e1349d
--- /dev/null
+++ b/src/test/result.py
@@ -0,0 +1,159 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# result.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/09/11 12:17:34 by charles #+# #+# #
+# Updated: 2020/09/11 12:24:57 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import config
+from test.captured import Captured
+
+class Result:
+ RED_CHARS = "\033[31m"
+ GREEN_CHARS = "\033[32m"
+ BLUE_CHARS = "\033[34m"
+ BOLD_CHARS = "\033[1m"
+ CLOSE_CHARS = "\033[0m"
+
+ def __init__(self, cmd: str, file_names: [str], expected: Captured, actual: Captured):
+ self.cmd = cmd
+ self.file_names = file_names
+ self.expected = expected
+ self.actual = actual
+ self.colored = True
+ self.set_colors()
+
+ def toggle_colors(self):
+ self.colored = not self.colored
+
+ def set_colors(self):
+ if self.colored:
+ self.color_red = self.RED_CHARS
+ self.color_green = self.GREEN_CHARS
+ self.color_blue = self.BLUE_CHARS
+ self.color_bold = self.BOLD_CHARS
+ self.color_close = self.CLOSE_CHARS
+ else:
+ self.color_red = ""
+ self.color_green = ""
+ self.color_blue = ""
+ self.color_bold = ""
+ self.color_close = ""
+
+ def green(self, s):
+ return self.color_green + s + self.color_close
+
+ def red(self, s):
+ return self.color_red + s + self.color_close
+
+ def blue(self, s):
+ return self.color_blue + s + self.color_close
+
+ def bold(self, s):
+ return self.color_bold + s + self.color_close
+
+ @property
+ def passed(self):
+ return self.actual == self.expected
+
+ @property
+ def failed(self):
+ return not self.passed
+
+ def __repr__(self):
+ if config.VERBOSE_LEVEL == 0:
+ return self.green('.') if self.passed else self.red('!')
+ elif config.VERBOSE_LEVEL == 1:
+ printed = self.escaped_cmd[:]
+ if len(printed) > 70:
+ printed = printed[:67] + "..."
+ fmt = self.green("{:74} [PASS]") if self.passed else self.red("{:74} [FAIL]")
+ return fmt.format(printed)
+ elif config.VERBOSE_LEVEL == 2:
+ return self.full_diff()
+ else:
+ raise RuntimeError
+
+ def put(self):
+ if config.VERBOSE_LEVEL == 2 and self.passed:
+ return
+ print(self, end="")
+ if config.VERBOSE_LEVEL == 0:
+ sys.stdout.flush()
+ else:
+ print()
+
+ def header(self, title: str) -> str:
+ return self.bold("|---------------------------------------{:-<40}".format(title))
+
+ @property
+ def expected_header(self) -> str:
+ return self.green(self.header("EXPECTED"))
+
+ @property
+ def actual_header(self) -> str:
+ return self.red(self.header("ACTUAL"))
+
+ def indicator(self, title: str, prefix: str) -> str:
+ return self.bold(self.blue(prefix + " " + title))
+
+ def file_diff(self, file_name: str, expected: str, actual: str) -> str:
+ if expected == actual:
+ return ""
+ return (
+ self.indicator("FILE {}".format(file_name), "|#") + '\n'
+ + self.expected_header + '\n'
+ + ("FROM TEST: File not created\n" if expected is None else self.cat_e(expected))
+ + self.actual_header + '\n'
+ + ("FROM TEST: File not created\n" if actual is None else self.cat_e(actual))
+ )
+
+ def files_diff(self):
+ return '\n'.join([self.file_diff(n, e, a) for n, e, a in
+ zip(self.file_names,
+ self.expected.files_content,
+ self.actual.files_content)
+ if e != a])
+
+ def output_diff(self) -> str:
+ out = ""
+ if self.actual.is_timeout:
+ return "TIMEOUT\n"
+ if self.expected.status != self.actual.status:
+ out += self.indicator("STATUS: expected {} actual {}"
+ .format(self.expected.status, self.actual.status), "| ") + '\n'
+ if self.expected.output != self.actual.output:
+ out += (self.expected_header + '\n'
+ + self.cat_e(self.expected.output)
+ + self.actual_header + '\n'
+ + self.cat_e(self.actual.output))
+ return out
+
+ def full_diff(self) -> str:
+ return (self.indicator("WITH {}".format(self.escaped_cmd), "|>") + '\n'
+ + self.output_diff()
+ + self.files_diff()
+ + "=" * 80 + '\n')
+
+ def cat_e(self, s: str) -> str:
+ s = s.replace("\n", "$\n")
+ if len(s) < 2:
+ return s
+ if s[-1] != '\n':
+ s += '\n'
+ return s
+
+ @property
+ def escaped_cmd(self):
+ return (self.cmd
+ .replace("\t", "\\t")
+ .replace("\n", "\\n")
+ .replace("\v", "\\v")
+ .replace("\r", "\\r")
+ .replace("\f", "\\f")
+ )
diff --git a/src/test/test.py b/src/test/test.py
new file mode 100644
index 0000000..9674240
--- /dev/null
+++ b/src/test/test.py
@@ -0,0 +1,113 @@
+# ############################################################################ #
+# #
+# ::: :::::::: #
+# test.py :+: :+: :+: #
+# +:+ +:+ +:+ #
+# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
+# +#+#+#+#+#+ +#+ #
+# Created: 2020/06/16 21:48:50 by charles #+# #+# #
+# Updated: 2020/09/11 12:24:33 by charles ### ########.fr #
+# #
+# ############################################################################ #
+
+import os
+import sys
+import subprocess
+import shutil
+import glob
+
+import config
+from test.captured import Captured
+from test.result import Result
+
+
+class Test:
+ 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")
+ s = self.cmd
+ if self.setup != "":
+ s = "[SETUP {}] {}".format(self.setup, s)
+ if len(self.exports) != 0:
+ s = "[EXPORTS {}] {}".format(
+ ' '.join(["{}='{:.20}'".format(k, v) for k, v in self.exports.items()]), s)
+ self.result = Result(s, self.files, expected, actual)
+ self.result.put()
+
+ def _run_sandboxed(self, shell_path: str, shell_option: str) -> Captured:
+ """ run the command in a sandbox environment
+
+ capture the output (stdout and stderr)
+ capture the content of the watched files after the command is run
+ """
+
+ try:
+ os.mkdir(config.SANDBOX_PATH)
+ except OSError:
+ pass
+ if self.setup != "":
+ try:
+ setup_status = subprocess.run(
+ 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(self.setup,
+ self.cmd,
+ "no stderr" if e.stdout is None else e.stdout.decode().strip()))
+ sys.exit(1)
+
+ process = subprocess.Popen(
+ [shell_path, shell_option, self.cmd],
+ stderr=subprocess.STDOUT,
+ stdout=subprocess.PIPE,
+ cwd=config.SANDBOX_PATH,
+ env={
+ 'PATH': config.PATH_VARIABLE,
+ 'TERM': 'xterm-256color',
+ **self.exports,
+ },
+ )
+ try:
+ process.wait(timeout=self.timeout)
+ except subprocess.TimeoutExpired:
+ return Captured.timeout()
+
+ try:
+ stdout, _ = process.communicate()
+ output = stdout.decode()
+ except UnicodeDecodeError:
+ output = "UNICODE ERROR: {}".format(process.stdout)
+
+ # capture watched files content
+ files_content = []
+ for file_name in self.files:
+ try:
+ with open(os.path.join(config.SANDBOX_PATH, file_name), "rb") as f:
+ files_content.append(f.read().decode())
+ except FileNotFoundError as e:
+ files_content.append(None)
+ try:
+ shutil.rmtree(config.SANDBOX_PATH)
+ except:
+ subprocess.run(["chmod", "777", *glob.glob(config.SANDBOX_PATH + "/*")], check=True)
+ subprocess.run(["rm", "-rf", config.SANDBOX_PATH], check=True)
+ return Captured(output, process.returncode, files_content)