aboutsummaryrefslogtreecommitdiff
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
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
-rw-r--r--README.md13
-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
l---------run1
-rwxr-xr-xtry21
7 files changed, 40 insertions, 34 deletions
diff --git a/README.md b/README.md
index 7d9212f..4732b84 100644
--- a/README.md
+++ b/README.md
@@ -27,8 +27,8 @@ $ minishell_test # In your project directory
$ python3 -m minishell_test # If you don't have ~/.brew/bin or ~/.local/bin in your PATH
$ minishell_test --help
-usage: minishell_test [-h] [-p PATH] [-l] [-k] [-r BEGIN END] [--show-range]
- [-x] [-v] [-b] [-n] [-m] [-g]
+usage: minishell_test [-h] [-p PATH] [-l] [-t COMMAND] [-k] [-r BEGIN END]
+ [--show-range] [-x] [-v] [-b] [-n] [-m] [-g]
[suite [suite ...]]
Test for the minishell project of school 42.
@@ -42,6 +42,9 @@ optional arguments:
-h, --help show this help message and exit
-p PATH, --path PATH Path to minishell directory
-l, --list Print available test suites
+ -t COMMAND, --try-cmd COMMAND
+ Run a custom command like this test would
+ (the only environment variable passed to your executable are TERM and PATH)
-k, --check-leaks Run valgrind on tests (disable usual comparison with bash)
-r BEGIN END, --range BEGIN END
Range of test index to run (imply --show-index)
@@ -52,6 +55,8 @@ optional arguments:
-n, --no-bonus Disable bonus tests
-m, --make Make minishell and exit
-g, --pager After running the test, display the result in a pager of your choice
+
+Made by cacharle - https://cacharle.xyz
```
## Test compatibility
@@ -75,9 +80,9 @@ This allows you to set the prompt to whatever you want.
### Environement variables
-My test only gives the `PATH=minishell_test/bin` and `TERM=xterm-256color` environment variables to your minishell.
+My test only gives the `PATH` and `TERM` environment variables to your minishell.
**Please check that your project still work with those settings before messaging me on Slack or creating an issue**.
-You can test this quickly with the [try](try) script (e.g `./try 'echo bonjour | cat -e'`).
+You can test this quickly with the `-t` option (e.g `minishell_test -t 'echo bonjour`).
## Bonus
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"
diff --git a/run b/run
deleted file mode 120000
index d3916d1..0000000
--- a/run
+++ /dev/null
@@ -1 +0,0 @@
-minishell_test/__main__.py \ No newline at end of file
diff --git a/try b/try
deleted file mode 100755
index 1d96563..0000000
--- a/try
+++ /dev/null
@@ -1,21 +0,0 @@
-#!/usr/bin/env python3
-
-import os
-import subprocess
-import sys
-
-from src.config import EXECUTABLES_PATH, MINISHELL_DIR, MINISHELL_EXEC
-
-if __name__ == "__main__":
- if len(sys.argv) != 2:
- print("Usage {} command".format(sys.argv[0]))
- sys.exit(1)
- print("=================== RUNNING " + sys.argv[1])
- process = subprocess.Popen(
- [os.path.join(MINISHELL_DIR, MINISHELL_EXEC), "-c", sys.argv[1]],
- stdout=subprocess.PIPE,
- stderr=subprocess.STDOUT,
- env={"PATH": EXECUTABLES_PATH, "TERM": "xterm-256color"}
- )
- out, _ = process.communicate()
- print(out.decode())