diff options
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | .travis.yml | 6 | ||||
| -rw-r--r-- | README.md | 12 | ||||
| -rw-r--r-- | docs/conf.py | 88 | ||||
| -rw-r--r-- | docs/config.rst | 133 | ||||
| -rw-r--r-- | docs/developers.rst | 51 | ||||
| -rw-r--r-- | docs/index.rst | 96 | ||||
| -rw-r--r-- | docs/options.rst | 71 | ||||
| -rw-r--r-- | minishell_test/config.py | 4 | ||||
| -rw-r--r-- | minishell_test/test/captured.py | 4 | ||||
| -rw-r--r-- | requirements-dev.txt (renamed from requirements.txt) | 4 | ||||
| -rw-r--r-- | tests/conftest.py | 1 | ||||
| -rw-r--r-- | tox.ini | 1 |
13 files changed, 460 insertions, 14 deletions
@@ -4,6 +4,7 @@ bin/ tags dist/ *.egg-info -build/ .tox/ +build/ +docs/_build/ bash3.2.57 diff --git a/.travis.yml b/.travis.yml index ae3fa12..2e93a07 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,12 +18,12 @@ addons: - valgrind # before_install: -# - [ "$TRAVIS_OS_NAME" = "osx" ] && brew update -# - [ "$TRAVIS_OS_NAME" = "osx" ] && brew install valgrind +# - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew update; fi +# - if [ "$TRAVIS_OS_NAME" = "osx" ]; then brew install valgrind; fi install: - pip install -e . - - pip install -r requirements.txt + - pip install -r requirements-dev.txt - git clone --recurse-submodule https://github.com/ouaisbrefbams/minishell /tmp/minishell - sed -i 's/-Werror//' /tmp/minishell/Makefile /tmp/minishell/libft/Makefile @@ -1,4 +1,4 @@ -# minishell test [](https://travis-ci.com/cacharle/minishell_test) [](https://pypi.org/project/minishell-test/) +# minishell test [](https://travis-ci.com/cacharle/minishell_test) [](https://pypi.org/project/minishell-test/) [](https://minishell-test.readthedocs.io) Test for the minishell project of school 42. @@ -75,20 +75,20 @@ $ ./minishell -c 'ls' README.md test.sh ``` -With this setup `argv[2]` is what you would usually get in `line` from `get_next_line`. +With this setup `argv[2]` is what you would usually get in `line` from `get_next_line`. This allows you to set the prompt to whatever you want. ### Environement variables -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**. +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 `-t` option (e.g `minishell_test -t 'echo bonjour`). ## Bonus * Force the bonus tests with `$ minishell_test -b` * Change the `BONUS` variable in [config.py](minishell_test/config.py) to True -* Set the environment variable `MINISHELL_TEST_BONUS` to `yes` +* Set the environment variable `MINISHELL_TEST_BONUS` to `yes` (e.g `echo 'export MINISHELL_TEST_BONUS=yes' >> ~/.zshrc`) ## Memory leaks @@ -99,7 +99,7 @@ to select the tests to run since valgrind is really slow. ## Don't check error messages If you don't want to copy bash syntax error message, -you can set the environment variable `MINISHELL_TEST_DONT_CHECK_ERROR_MESSAGE` to `yes`. +you can set the environment variable `MINISHELL_TEST_DONT_CHECK_ERROR_MESSAGE` to `yes`. It will still test your exit status code but will discard any output on error tests. ## Linux diff --git a/docs/conf.py b/docs/conf.py new file mode 100644 index 0000000..cc274d9 --- /dev/null +++ b/docs/conf.py @@ -0,0 +1,88 @@ +# Configuration file for the Sphinx documentation builder. +# +# This file only contains a selection of the most common options. For a full +# list see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +# -- Path setup -------------------------------------------------------------- + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +# +# import os +# import sys +# sys.path.insert(0, os.path.abspath('.')) + +from docutils import nodes +from sphinx import addnodes + +# -- Project information ----------------------------------------------------- + +project = 'minishell_test' +copyright = '2021, Charles Cabergs' +author = 'Charles Cabergs' + +# The full version, including alpha/beta/rc tags +release = '1.0.1' + + +# -- General configuration --------------------------------------------------- + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + "sphinx.ext.extlinks", +] + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +# This pattern also affects html_static_path and html_extra_path. +exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] + + +# -- Options for HTML output ------------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +# +html_theme = 'sphinx_rtd_theme' + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +html_static_path = ['_static'] + +def setup(app): + from sphinx.util.docfields import Field + app.add_object_type( + directivename="conf", + rolename="conf", + objname="configuration value", + indextemplate="pair: %s; configuration value", + doc_field_types=[ + Field( + 'type', + label='Type', + has_arg=False, + names=('type',), + bodyrolename='class' + ), + Field( + 'default', + label='Default', + has_arg=False, + names=('default',), + ), + ] + ) + +extlinks = { + "issue": ("https://github.com/cacharle/minishell_test/issues/%s", "#"), + "pull": ("https://github.com/cacharle/minishell_test/pull/%s", "p"), + "user": ("https://github.com/%s", "@"), +} diff --git a/docs/config.rst b/docs/config.rst new file mode 100644 index 0000000..edd88d5 --- /dev/null +++ b/docs/config.rst @@ -0,0 +1,133 @@ +.. bt in -*- rst -*- mode! + +Configuration +============= + +Configuration file +------------------ + +It looks for a ``minishell_test.cfg`` file in your project directory. + +Global +------ + +Global settings are defined under the ``minishell_test`` section: + +.. code-block:: cfg + + [minishell_test] + bonus = true + +.. conf:: bonus + + :type: true|false + :default: false + + Run the bonus tests + +.. conf:: exec_name + + :type: PATH + :default: minishell + + Minishell executable name + +.. conf:: make + + :type: true|false + :default: true + + Run ``make`` in your project directory before the test + +.. conf:: pager + + :type: NAME + :default: less + + Pager to use when viewing your results + +.. conf:: log_path + + :type: PATH + :default: minishell_test.log + + File where to put the test results + +.. conf:: cache_path + + :type: PATH + :default: $XDG_CACHE_HOME/minishell_test ^ ~/.cache/minishell_test + + +Shell +----- + +Shell settings are defined under the ``shell`` section: + +.. code-block:: cfg + + [shell] + available_commands = ls,cat + +.. conf:: available_commands + + :type: LIST + :default: rmdir env cat touch ls grep sh head + + Commands available in test + +.. conf:: path_variable + + :type: LIST + :default: {cache:executables_path} + + ``$PATH`` environment variable passed to the shell + +Reference ++++++++++ + +Reference shell settings are defined under the ``shell:reference`` section: + +.. code-block:: cfg + + [shell:reference] + path = /bin/sh + +.. conf:: path + + :type: PATH + :default: /bin/bash + + Path to reference shell (shell which will be compared minishell) + has to support the ``-c`` option (``sh``, ``bash`` and ``zsh`` support it) + +.. conf:: args + + :type: ARGV + + Supplementary arguments to the reference shell + (e.g ``--posix`` can be used with bash for a more posix complient behavior) + +Timeout +------- + +Timeout settings are defined under the ``timeout`` section: + +.. code-block:: cfg + + [timeout] + leaks = 60 + +.. conf:: test + + :type: FLOAT + :default: 0.5 + + Time before a timeout occurs on a regular test (in seconds) + +.. conf:: leaks + + :type: FLOAT + :default: 10 + + Time before a timeout occurs on a leak test (with valgrind) (in seconds) diff --git a/docs/developers.rst b/docs/developers.rst new file mode 100644 index 0000000..17307cd --- /dev/null +++ b/docs/developers.rst @@ -0,0 +1,51 @@ +Developers +========== + +Install requirements +-------------------- + +.. include:: ../requirements-dev.txt + :literal: + +.. code-block:: + + $ pip3 instal -r requirements-dev.txt + +Install in *editable* mode +-------------------------- + +.. code-block:: + + $ git clone https://github.com/cacharle/minishell_test + $ cd minishell_test + $ pip3 install -e . + +This make it possible to modify the source and see the changes live. + +Linting +------- + +.. code-block:: + + $ flake8 minishell_test + +Type checking +------------- + +.. code-block:: + + $ mypy minishell_test + +Unit Test +--------- + +.. code-block:: + + $ pytest + +Cross environment testing +------------------------- + +.. code-block:: + + $ tox diff --git a/docs/index.rst b/docs/index.rst new file mode 100644 index 0000000..7726f0a --- /dev/null +++ b/docs/index.rst @@ -0,0 +1,96 @@ +.. program:: minishell_test + +minishell_test +============== + +Test for 42 school's minishell project. + +.. .. image:: https://i.imgur.com/98xh2xY.gif + +Getting Started +--------------- + +Installation +++++++++++++ + +.. code-block:: + + $ pip3 install minishell-test + $ pip3 install --user minishell-test # if you don't have root access + +Compatibility ++++++++++++++ + +Your executable **must** support the ``-c`` option which allow to pass command as string. + +.. code-block:: + + $ bash -c 'echo bonjour je suis | cat -e' + bonjour je suis$ + $ ./minishell -c 'echo bonjour je suis | cat -e' + bonjour je suis$ + + +.. note:: + With this setup ``argv[2]`` is what you would usually get in ``line`` from ``get_next_line``. + +Usage ++++++ + +Run all the predefined tests: + +.. code-block:: + + $ cd <MINISHELL> + $ minishell_test + +.. warning:: + If you get ``command not found``, do either of those things: + + * ``~/.local/bin`` to your ``PATH`` environment variable. + * run ``$ python3 -m minishell_test`` instead of ``$ minishell_test`` + + +Documentation +------------- + +.. toctree:: + :maxdepth: 2 + + config + options + developers + + +.. code-block:: + + $ minishell_test --help + +The options are explained in more details in :ref:`options <options>`. + + +Environement variables +---------------------- + +This test only gives the ``PATH`` and ``TERM`` environment variables to your minishell by default (see :ref:`config env`). + +You can test this quickly with :option:`--try`. + +.. warning:: + Please check that your project still work with this environment before creating an issue or messaging me on Slack. + +Bonus +----- + +See :ref:`config bonus` +See :ref:`options bonus` + +Memory leaks +------------ + +See :ref:`options leaks` + +Linux +----- + +It will try to convert to output/status code of ``bash`` on Linux to the one on Mac. diff --git a/docs/options.rst b/docs/options.rst new file mode 100644 index 0000000..7c29529 --- /dev/null +++ b/docs/options.rst @@ -0,0 +1,71 @@ +Command line Options +==================== + +.. code-block:: txt + + usage: minishell_test [-h] [-p PATH] [-l] [-t COMMAND] [-k] [-r BEGIN END] + [--show-range] [-x] [-v] [-b] [-n] [-m] [-g] + [suite ...] + +.. program:: minishell_test + +.. option:: suite + + Test suites/group to run. + It tries to be smart and autocomplete the suite name + (e.g ./run int -> ./run preprocess/interpolation) + + +.. option:: -h, --help + + show this help message and exit + +.. option:: -p <PATH>, --path <PATH> + + Path to minishell directory + +.. option:: -l, --list + + Print available test suites + +.. option:: -t <COMMAND>, --try <COMMAND> + + Run a custom command like this test would + (the only environment variable passed to your executable are TERM and PATH) + +.. option:: -k, --check-leaks + + Run valgrind on tests (disable usual comparison with bash) + +.. option:: -r <BEGIN> <END>, --range <BEGIN> <END> + + Range of test index to run (imply --show-index) + +.. option:: --show-range + + Show test index (useful with --range) + +.. option:: -x, --exit-first + + Exit on first fail + +.. option:: -v, --verbose + + Increase verbosity level (e.g -vv == 2) + +.. option:: -b, --bonus + + Enable bonus tests + +.. option:: -n, --no-bonus + + Disable bonus tests + +.. option:: -m, --make + + Make minishell and exit + +.. option:: -g, --pager + + After running the test, display the result in a pager of your choice + diff --git a/minishell_test/config.py b/minishell_test/config.py index 1368740..2cc96b7 100644 --- a/minishell_test/config.py +++ b/minishell_test/config.py @@ -6,7 +6,7 @@ # By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2021/02/26 09:40:36 by cacharle #+# #+# # -# Updated: 2021/02/27 16:11:46 by cacharle ### ########.fr # +# Updated: 2021/02/27 16:16:07 by cacharle ### ########.fr # # # # ############################################################################ # @@ -29,7 +29,7 @@ class ConfigParser(configparser.ConfigParser): BOOLEAN_STATES = {'true': True, 'false': False} def __init__(self): - super().__init__(self) + super().__init__() def getpath(self, section, options): return Path(self.get(section, options)).resolve() diff --git a/minishell_test/test/captured.py b/minishell_test/test/captured.py index d2fda8b..6ba861b 100644 --- a/minishell_test/test/captured.py +++ b/minishell_test/test/captured.py @@ -6,7 +6,7 @@ # By: charles <me@cacharle.xyz> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2020/09/11 12:16:25 by charles #+# #+# # -# Updated: 2021/02/27 15:48:30 by cacharle ### ########.fr # +# Updated: 2021/02/27 16:15:13 by cacharle ### ########.fr # # # # ############################################################################ # @@ -33,7 +33,7 @@ class Captured: lines = output.split('\n') for i, line in enumerate(lines): - lines[i] = line = re.sub(f"line [01]: ", "", lines[i], 1) + lines[i] = line = re.sub("line [01]: ", "", lines[i], 1) if line.startswith(config.SHELL_REFERENCE_PREFIX): lines[i] = config.MINISHELL_PREFIX + line[len(config.SHELL_REFERENCE_PREFIX):] self.output = '\n'.join(lines) diff --git a/requirements.txt b/requirements-dev.txt index bf40793..5e211a6 100644 --- a/requirements.txt +++ b/requirements-dev.txt @@ -1,4 +1,8 @@ +tox mypy==0.800 flake8==3.8.4 flake8_comprehensions==3.3.1 pep8_naming==0.11.1 +pytest +sphinx +sphinx-rtd-theme diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..5e64fd1 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1 @@ +# do not remove, used by pytest @@ -1,5 +1,6 @@ [tox] envlist = py36,py37,py38,py39 +distshare = {homedir}/.cache/tox/distshare [testenv] passenv = |
