aboutsummaryrefslogtreecommitdiff
path: root/minishell_test
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2021-02-24 08:59:25 +0100
committerCharles Cabergs <me@cacharle.xyz>2021-02-24 09:09:52 +0100
commitad7233a4a5f45be6f991ed38a7351a6ef826356b (patch)
tree7557829a45109e5ac6d83ffd8e40bcf331749f4c /minishell_test
parent1399a01dc09ed1477b740bd320580ce3dacfe3cf (diff)
downloadminishell_test-ad7233a4a5f45be6f991ed38a7351a6ef826356b.tar.gz
minishell_test-ad7233a4a5f45be6f991ed38a7351a6ef826356b.tar.bz2
minishell_test-ad7233a4a5f45be6f991ed38a7351a6ef826356b.zip
Fixing #17 - Incorporate the try script in the command arguments
Diffstat (limited to 'minishell_test')
-rwxr-xr-xminishell_test/__main__.py8
-rw-r--r--minishell_test/args.py13
-rw-r--r--minishell_test/test/result.py2
-rw-r--r--minishell_test/test/test.py16
4 files changed, 31 insertions, 8 deletions
diff --git a/minishell_test/__main__.py b/minishell_test/__main__.py
index 7d7b619..3ae1648 100755
--- a/minishell_test/__main__.py
+++ b/minishell_test/__main__.py
@@ -23,6 +23,7 @@ import minishell_test.sandbox as sandbox
from minishell_test.args import parse_args
from minishell_test.suite.suite import Suite, SuiteException
from minishell_test.suites import * # noqa: F403,F401
+from minishell_test.test import Test
def main(argv=None):
@@ -58,6 +59,11 @@ def main(argv=None):
shutil.copy(cmd_path,
os.path.join(config.EXECUTABLES_PATH, cmd))
+ if args.try_cmd is not None:
+ print("Output")
+ print(Test.try_run(args.try_cmd))
+ sys.exit(0)
+
reference_args = os.environ.get("MINISHELL_TEST_ARGS")
if reference_args is not None:
config.REFERENCE_ARGS.extend(reference_args.split(','))
@@ -95,7 +101,7 @@ def main(argv=None):
print("See", config.LOG_PATH, "for more information")
if config.CHECK_LEAKS:
print("HELP: Valgrind is really slow the -x and --range options could be useful"
- " (./run -h for more details)")
+ " ({} -h for more details)".format(sys.argv[0]))
if args.pager:
subprocess.run([config.PAGER, config.LOG_PATH])
diff --git a/minishell_test/args.py b/minishell_test/args.py
index e88ae7f..ef47081 100644
--- a/minishell_test/args.py
+++ b/minishell_test/args.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:32 by charles #+# #+# #
-# Updated: 2021/02/24 08:03:17 by cacharle ### ########.fr #
+# Updated: 2021/02/24 08:48:15 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -22,9 +22,7 @@ def parse_args():
parser = argparse.ArgumentParser(
description="Test for the minishell project of school 42.",
formatter_class=argparse.RawTextHelpFormatter,
- epilog=textwrap.dedent("""
- Made by cacharle - https://cacharle.xyz
- """)
+ epilog="Made by cacharle - https://cacharle.xyz"
)
parser.add_argument(
"-p", "--path", default=config.MINISHELL_DIR,
@@ -35,6 +33,13 @@ def parse_args():
help="Print available test suites"
)
parser.add_argument(
+ "-t", "--try-cmd", metavar="COMMAND",
+ help=textwrap.dedent("""\
+ Run a custom command like this test would
+ (the only environment variable passed to your executable are TERM and PATH)
+ """)
+ )
+ parser.add_argument(
"-k", "--check-leaks", action="store_true",
help="Run valgrind on tests (disable usual comparison with bash)"
)
diff --git a/minishell_test/test/result.py b/minishell_test/test/result.py
index 9769527..fe465e5 100644
--- a/minishell_test/test/result.py
+++ b/minishell_test/test/result.py
@@ -6,7 +6,7 @@
# By: charles <me@cacharle.xyz> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/09/11 12:17:34 by charles #+# #+# #
-# Updated: 2021/02/05 17:46:30 by charles ### ########.fr #
+# Updated: 2021/02/24 08:56:03 by cacharle ### ########.fr #
# #
# ############################################################################ #
diff --git a/minishell_test/test/test.py b/minishell_test/test/test.py
index ff1f389..ff60522 100644
--- a/minishell_test/test/test.py
+++ b/minishell_test/test/test.py
@@ -6,7 +6,7 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/06/16 21:48:50 by charles #+# #+# #
-# Updated: 2021/02/05 18:35:12 by charles ### ########.fr #
+# Updated: 2021/02/24 09:09:39 by cacharle ### ########.fr #
# #
# ############################################################################ #
@@ -144,7 +144,7 @@ class Test:
return Captured(output, process.returncode, files_content)
@property
- def full_cmd(self):
+ def full_cmd(self) -> str:
""" Return the command prefixed by the setup and exports """
s = self.cmd
if len(self.exports) != 0:
@@ -153,3 +153,15 @@ class Test:
if self.setup != "":
s = "[SETUP {}] {}".format(self.setup, s)
return s
+
+ @classmethod
+ def try_run(cls, cmd: str) -> str:
+ config.VERBOSE_LEVEL = 2
+ test = Test(cmd)
+ test.run(0)
+ if isinstance(test.result, LeakResult):
+ return test.result.captured.output
+ elif isinstance(test.result, Result):
+ return test.result.actual.output
+ else:
+ return "No output"