From c0b1a90cf9c52a0c9b1623ac695516031d5ccdba Mon Sep 17 00:00:00 2001 From: Charles Cabergs Date: Thu, 10 Sep 2020 15:07:30 +0200 Subject: Updated README, Added auto build --- README.md | 22 ++++++++++--------- args.py | 6 +++--- config.py | 5 ++++- main.py | 58 -------------------------------------------------- minishell_test | 3 --- run | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ suites/cmd.py | 4 ++-- 7 files changed, 88 insertions(+), 77 deletions(-) delete mode 100755 main.py delete mode 100755 minishell_test create mode 100755 run diff --git a/README.md b/README.md index 5c07be3..bacd967 100644 --- a/README.md +++ b/README.md @@ -4,12 +4,12 @@ Test for the minishell project of school 42. ![screenshot](./screenshot.png) -# Usage +## Usage The default path to your project is `..` but you can change it the the [configuration](config.py). -* `> ./main.py --help` -* `> ./main.py` +* `> ./run --help` +* `> ./run` ## Test compatibility @@ -27,17 +27,19 @@ README.md test.sh README.md test.sh ``` -The reasons for this: -1. You're free to set the prompt to whatever you want -2. Termcaps would be a nightmare to test +This allows you to set the prompt to whatever you want. -# Configuration +## Python Version + +This test works with python >= 3.4. The timeout detection only works with python >= 3.8. + +## Configuration The default configuration can be changed in [config.py](config.py) -# Add new tests +## Add new tests -## Add individual test +### Add individual test In your suite function you can use the `test` function. With the following arguments: @@ -55,7 +57,7 @@ test("cat < somefile > otherfile", files=["otherfile"]) ``` -## Add Suite +### Add Suite A test suite is a group of related tests. diff --git a/args.py b/args.py index 358077c..2d0d57a 100644 --- a/args.py +++ b/args.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:32 by charles #+# #+# # -# Updated: 2020/09/09 15:17:58 by charles ### ########.fr # +# Updated: 2020/09/10 13:52:37 by charles ### ########.fr # # # # ############################################################################ # @@ -23,8 +23,8 @@ def parse_args(): help="increase verbosity level (e.g -vv == 2)" ) parser.add_argument( - "-g", "--generate", metavar="NUMBER", type=int, - help="number of new random test to generate" + "-b", "--build", action="store_true", + help="build minishell and exit" ) parser.add_argument( "-l", "--list", action="store_true", diff --git a/config.py b/config.py index f7b169b..e05c36b 100644 --- a/config.py +++ b/config.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 18:24:19 by charles #+# #+# # -# Updated: 2020/07/19 20:29:52 by charles ### ########.fr # +# Updated: 2020/09/10 13:54:27 by charles ### ########.fr # # # # ############################################################################ # @@ -19,6 +19,9 @@ 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" diff --git a/main.py b/main.py deleted file mode 100755 index f1d4c10..0000000 --- a/main.py +++ /dev/null @@ -1,58 +0,0 @@ -#!/usr/bin/python3 - -# ############################################################################ # -# # -# ::: :::::::: # -# main.py :+: :+: :+: # -# +:+ +:+ +:+ # -# By: charles +#+ +:+ +#+ # -# +#+#+#+#+#+ +#+ # -# 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 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(): - 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)) - - args = parse_args() - if args.list: - print("The available suites are:") - print('\n'.join([" - " + s.name for s in Suite.available])) - sys.exit(0) - - 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/minishell_test b/minishell_test deleted file mode 100755 index 8a418ed..0000000 --- a/minishell_test +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -python3 ./main.py $@ diff --git a/run b/run new file mode 100755 index 0000000..a71a485 --- /dev/null +++ b/run @@ -0,0 +1,67 @@ +#!/usr/bin/python3 + +# ############################################################################ # +# # +# ::: :::::::: # +# main.py :+: :+: :+: # +# +:+ +:+ +:+ # +# By: charles +#+ +:+ +#+ # +# +#+#+#+#+#+ +#+ # +# 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/suites/cmd.py b/suites/cmd.py index a2738b5..1302ae3 100644 --- a/suites/cmd.py +++ b/suites/cmd.py @@ -6,7 +6,7 @@ # By: charles +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/07/15 15:11:46 by charles #+# #+# # -# Updated: 2020/07/19 18:55:52 by charles ### ########.fr # +# Updated: 2020/09/10 14:25:40 by charles ### ########.fr # # # # ############################################################################ # @@ -89,7 +89,7 @@ def suite_redirection(test): 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 <<<<< bar", setup="echo bonjour > bar") -- cgit