Skip to main content

minishell test Build Status PyPI - Python Version

Test for the minishell project of school 42.

preview

Installation

pip

$ pip3 install minishell-test

Manual

$ git clone https://github.com/cacharle/minishell_test
$ cd minishell_test
$ pip3 install -e minishell_test

Usage

The default path to your project is ../minishell but you can change it the the configuration.

$ ./run  # run all tests

$ ./run --help
usage: run [-h] [-k] [-r BEGIN END] [--show-range] [-x] [-v] [-b] [-n] [-l] [-m] [-g] [suite ...]

Test for the minishell project of school 42.

positional arguments:
  suite                 Test suites/group to run.
                        It tries to be smart and autocomplete the suite name
                        (e.g ./run int -> ./run preprocess/interpolation)

optional arguments:
  -h, --help            show this help message and exit
  -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)
  --show-range          Show test index (useful with --range)
  -x, --exit-first      Exit on first fail
  -v, --verbose         Increase verbosity level (e.g -vv == 2)
  -b, --bonus           Enable bonus tests
  -n, --no-bonus        Disable bonus tests
  -l, --list            Print available test suites
  -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://github.com/cacharle
https://cacharle.xyz

Test compatibility

Your executable must support the -c option which allow to pass command as string.

$ bash -c 'echo bonjour je suis'
bonjour je suis
$ ./minishell -c 'echo bonjour je suis'
bonjour je suis

$ bash -c 'ls'
README.md test.sh
$ ./minishell -c 'ls'
README.md test.sh

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.

This test works with Python3.6 or higher.

Environement variables

My test only gives the PATH=minishell_test/bin and TERM=xterm-256color 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 script (e.g ./try 'echo bonjour | cat -e').

Bonus

Their is 3 different method to enable the bonus tests:

  • Force the bonus tests with ./run -b
  • Change the BONUS variable in config.py to True
  • Set the environment variable MINISHELL_TEST_BONUS to yes
    (e.g echo 'export MINISHELL_TEST_BONUS=yes' >> ~/.zshrc)

Memory leaks

./run -k, checkout the --show-range, --range and -x options to help 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.
It will still test your exit status code but will discard any output on error tests.

Linux

The tester will try to convert to output/status code of bash on Linux to the one on Mac.


Add new tests

You can find the suites in the src/suites directory.

Add individual test

In your suite function you can use the test function. With the following arguments:

  1. Command to be tested (output and status will be compared to bash)
  2. A command to setup the sandbox directory where the tested command will be run
  3. List of files to watch (the content of each file will be compared)
test("echo bonjour je suis")                                  # simple command
test("cat < somefile", setup="echo file content > somefile")  # setup
test("ls > somefile", setup="", files=["somefile"])           # watch a file
test("echo $A", exports={"A": "a"})                           # export variables
                                                              # in the environment
test("echo bonjour", hook=lambda s: s.replace("o", "a"))      # pass the shell output
                                                              # through a hook function

test("cat < somefile > otherfile",
     setup="echo file content > somefile",
     files=["otherfile"])

Add Suite

A test suite is a group of related tests.

@suite()  # @suite(bonus=True) if it's a bonus suite
def suite_yoursuitename(test):
    """ a description of the suite """
    test(...)
    test(...)
    test(...)

Wildcard (or glob)

There is a commented glob suite in src/suites/preprocess.py. Good luck handling *'.*'.

Metadata

Release files for minishell-test 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for minishell-test 1.0.0
File Size Uploaded
minishell_test-1.0.0.tar.gz 35.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for minishell-test 1.0.0
File Interpreter ABI Platform
minishell_test-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 75.8 kB

Release files / minishell_test-1.0.0.tar.gz

Download URL minishell_test-1.0.0.tar.gz
Size 35.7 kB
Tags Source
SHA-256 checksum
How to use checksums
7915372a9df0768e9e69127a42ce8549f4b22124afefcea328d7c505c46640d2
BLAKE2b-256 checksum
How to use checksums
33160ca2efce98833a52021b8d32b65d649086d924e50eca31a15c0a32f1f12a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release files / minishell_test-1.0.0-py3-none-any.whl

Download URL minishell_test-1.0.0-py3-none-any.whl
Size 40.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6716676b452ab7352ead6a78b95b1ed6b4a20ba2477f9470e43d9262f0461cf
BLAKE2b-256 checksum
How to use checksums
8ed564424072b425849efd6b89e9e635741f8785e61533f63ecf0ba29af76271
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

Release history Release notifications | RSS feed

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.1

2 release files

This release

1.0.0 This release

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page