Giter Club home page Giter Club logo

mpanic's Introduction

MINISHELL PANIC

An epic tester to make you panic when testing your minishell


Description

The mpanic tester has been developed to help you throught the process of testing your minishell. There are some other test, but mpanic is quite special for two important features:

  • You dont need to modify your minishell to work with -C flag. Mpanic is able to catch your minishell exit and test against bash.
  • We have develop kind of pseoudo-code to give you the ability to add your own test without going deep in the code, just modifying the txt files of the test.

Potential Issues

One thing to keep in mind is that if you have the standard input file descriptors redirected to a non-terminal file, the exit command should not be printed. You can check whether a file descriptor is a terminal or not using the isatty() function.

Here's an example of how you can use isatty() to check whether standard output is being redirected:

line = readline("minishell $");
if (!line)
{
    if (isatty(STDIN_FILENO))
	write(2, "exit\n", 6);
    exit (exit_code);
}

{ >>> WARNIG <<<< } IF YOUR MINISHELL does not have this implementation, THE TESTER WILL FAIL COMPLETLY.


How to use

Clone this repo inside your minishell folder

git clone [email protected]:ChewyToast/mpanic.git

Execute the script. First time you execute MPANIC, you get all the options you have to execute the test

bash mpanic.sh



Make your own test

This tester has developed kind of meta-lenguaje to make easy to add new test to the blocks that already exist (parser, echo, export... ) or to your own block.

Testing some commands is not easy because you need to prepare some files or variables, or you need to delete some files after the test. MPANIC is ready to manage all this situations due his own lenguaje.

Mainly, each line that you write in the .txt of the tests files will be executed in minishell and in bash. Then the stdout, the error status and the errout will be compared and must be the same to get an OK.


Basic testing

We will execute this sequence of lines in minishell and bash and compare the results.

echo hola
echo hola | cat -e
echo hola > file1
cat file1

Preparing testing

In some test you will neeed to prepare some files to check the correct behaviour of your minishell. For example you will nedd to create a file without permissions to check that a redirect fails if you don't have rights.

For this situation we haved developed the '#' statement. Each line you write before '#' will be executed in the terminal but without compare nothig. Just like yo do that in the terminal.

For example this secuence will create a testfile file without rights and then will execute all this tests. At the end is good practice to delete the file in the same way. We also recomend to redirects all the fd of the comnmand (&> /dev/null) after '#' statement to avoid random messages.

In this lines, the '#' statements will executed quietly. You will see nothing about this lines in the testing.

# chmod 000 testfile &> /dev/null
echo hi > testfile
echo hi >> testfile
echo hi 2> testfile
echo hi 2>> testfile
# (chmod 666 testfile && rm testfile) &> /dev/null

Batch testing

Is there some situations you can not resolve easily, for example if you execute this secuence, the echo will print nothing. This is because each line is executed in new minishell & bash. So the second minishell & bash have no variable called A.

export A="mpanic"
echo $A

To solve this sititions you can do batch testing and send a secuence of commands to the same instance of minishell & bash. You only have to put the commands in arow separated by ';'

In this secuence the result will be mpanic in stdout.

export A="mpanic"; echo $A

Remember that you don't need to have the ';' operator implemented in your minishell !


Comments

The tester will be print last command of the ';' separated secuence to recognice the test. But in some situations this last line is not representative of the test. For example

echo hi > testfolder; rm testfolder

To solve this you can add the text you want to show the tester adding at the end an '@' followe by the line yoy want.

echo hi > testfolder; rm testfolder @This is the line the tester will print to identify this test

mpanic's People

Contributors

ailopez-o avatar anagmrebelo avatar chewytoast avatar emartinez-dev avatar gemartin99 avatar sebamiro avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mpanic's Issues

Unset tests

The operation of the unset command may seem simple, but it must, among other things, validate the variables you want to remove from the environment stack, so you could add the unset tests section.

  • To do this, you must create the file(s) with the tests.
  • It should be added in the argument parser and in the test run.
  • And the unset test call should be added.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.