Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to shell_goodman #141

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 25 additions & 93 deletions shell_goodman.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/bash
#!/bin/bash --posix

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
NC='\033[0m'

MINISHELL_PATH="./minishell"
TEST_COMMANDS="test_commands.txt"
Expand All @@ -25,7 +25,7 @@ if [ ! -f "$TEST_COMMANDS" ]; then
# Lines starting with # are comments and will be ignored. Empty lines will be ignored.

# The file is named test_commands.txt, the script checks for its name so do not rename it.
# Adding 'remove' as the last line will make the script remove it after it is done running.
# Adding 'remove' as the last line will make the script remove it after it is done running.
# Otherwise, the file will remain in the working directory and can be editted at will between runs.

# The script will NOT remove any files your minishell has created unless specified in the cleanup() function. By default, it will try to rm output1.txt up to output4.txt.
Expand All @@ -48,7 +48,7 @@ cleanup() {
kill $MINISHELL_PID
# Add any additional files created by the commands here
rm -rf output.txt output2.txt output3.txt output4.txt

rm -rf .test_commands.txt.swp
rm -rf "$TEMP_DIR"
exit
}
Expand All @@ -66,95 +66,19 @@ trap interrupted SIGINT
echo -e " ${YELLOW}


_____ _ _ _____ _ _ _ _____ _
|_ _| | ( ) / ____| | | | | / ____| | |
| | | |_|/ ___ | (___ | |__ ___| | | | | __ ___ ___ __| |_ __ ___ __ _ _ __
| | | __| / __| \___ \| '_ \ / _ \ | | | | |_ |/ _ \ / _ \ / _| | |_ | _ \ / _| | \_ \
_____ _ _ _____ _ _ _ _____ _
|_ _| | ( ) / ____| | | | | / ____| | |
| | | |_|/ ___ | (___ | |__ ___| | | | | __ ___ ___ __| |_ __ ___ __ _ _ __
| | | __| / __| \___ \| '_ \ / _ \ | | | | |_ |/ _ \ / _ \ / _| | |_ | _ \ / _| | \_ \
_| |_| |_ \__ \ ____) | | | | __/ | | | |__| | (_) | (_) | (_| | | | | | | (_| | | | |
|_____|\__| |___/ |_____/|_| |_|\___|_|_| \_____|\___/ \___/ \__,_|_| |_| |_|\__,_|_| |_|
|_____|\__| |___/ |_____/|_| |_|\___|_|_| \_____|\___/ \___/ \__,_|_| |_| |_|\__,_|_| |_|



${NC}"

echo -e "${YELLOW}
echo -e "${YELLOW}
________________________________________________________________________________________________________________________________________________________

....... ............................... ..........................',;,,,'.................'''''',,,,,,;;;;;;::::ccccclllloo
............................... .......................................,;;;;:;,'...........''''''',,,,,,;;;;;:::::cccclllllooo
......................... ............................................',;;;cll:,'.......'''''',,,,,,;;;;;::::ccccccllloooood
........... ........ .................................................'',,;codxdc'....'''''',,,,,,;;;;;::::cccccllllooooddd
................. ..... ....''..............................................';codk00o,''''''',,,,,,,;;;;;:::cccccllllloooddddd
............ ... ...,;;::;;;;,,,,',,,,'''''.........................''',;codkKXXk:'''''',,,,,;;;;;::::cccccllllooooddddxx
............ .... ..',;:::::::::::::::;;;,,,,,'''''....................'',:ccldkOXN0o:;,'',,,,;;;;;:::::cccclllloooooddddxxx
............ ...... .',;:::::::ccc:::::::::;;;,,,'''''''..................'',:odxxkO0K0xoc;',,,,;;;;;:::cccccllllloooooddddxxxk
....... ............ ........ .';::::::::::::::::::::::;;;;,,,''''''''...............',,cdOKK0Okkkkdc,,,,,,,;;;:::cccccllllloooodddddxxxkk
....... ........... ........ .';:;:::::::::::::::::::::::;;,,,,,,,,'''''''...........';:cokXNX0kxkkdc;,,,,,,;;;:::ccccclllooooodddddxxxxkk
.......................... ...... ..;::;::::::::::::::::::::::::;;,,,,,,,,,,'''''..........';:cox0NNKkdxO0Od;,,,;;;;:::ccccccllloooodddddxxxxkkk
....................... ......... ..,;:::::::ccccc::::::::::::::::;;;;;;;;,,,,'''''..........';cod0NWXkolxKXXx:,;;;;::::ccccllllooooodddddxxxkkkk
...................... ........ ..';:::::ccccccccccccc:ccccc:::c::;;;;;;;;;,,,,''''..........,:lx0NWXxlccxKNXk:;;;;:::ccccllllloooodddddxxxxkkkO
...................... ........ ...,:::cccccccccclccccc:ccccccccc::;;;;;;;;;;,,,,,'''.........',:xKNWXkoc:cxKNNk:;:::::ccccclllloooodddddxxxkkkkO
...................... ......... ...';:ccccclllllllcccccccccccccccc:::::::;;;;;;,,,,,'''.........',o0NWNOoc::lkXWNkc::::ccccclllooooodddddxxxxkkkOO
....... .......... ....,:cccccllllllllllllcccccccccc::::cc:::;;;;;;;,,,,'''''........'cOXWN0dc::cd0NWNkc:::cccclllooooodddddxxxxkkkkOO
......................... ....,:ccclllllloolloolllccccccccc:::cccc::;;;;;;;,,,,'''''.........:xKWWKkoc:clkXNMXdc::ccccllloooooddddxxxxxkkkOOO
...................................,:clllllllooollllllcccccccccc::::cc:::;;;;;;;,,,,''''''........,oKWWXOdlclox0NWWKo::ccccllloooooddddxxxxkkkOOOO
...................................''',:cllllllooolllolllccccccccccc::::::::;;;;;;;;,,'''''''........':kNWN0koloxkOXNWXxccccccllloooooddddxxxkkkkOOO0
................. ..................''',;cllllooooooollolllccccccccccc:::c:::::;;;;;;,,''''''..........,dXWWKOxddxOKXNWWOlccccclllooooodddxxxxkkkkOOOO
............... .................'',,;clllooooooollllllccccc:::cccc:::::::::;;;,,,,,''''''..........':ONWNKkxxdkKXNWWKoccccclllooooddddxxxxkkkkOOO0
................ ................','',;;:cllllloollllllllcccccc::cccccccc::::::;;;;,,,'''''...........';kNWNKOkkkOKNNWWXxc:ccclllooooddddxxxkkkkOOOO0
.................................',;;;;;::clllloollllooollllcccc:::ccccccccccc::::;;,,,'''''...........':kNWWXOkOO0KNWWWXxcccccllloooodddxxxxkkkkOOOO0
................... .............,;;:::::ccllloolloooooooollcccc::::cccccccccc:::::;,,,,''''..........',cONWWXkxO0KXNWWWKoccccclllooodddddxxxkkkkOOOO0
................... .............,;;:::cccllloooooodooddddolllccccc:ccccccccccc::::;;,,,''......'.....,;l0NWWXkdkKXNNWWWKdcllcllllooodddddxxxkkkkOOOO0
.................. ............,;::::ccccllloooodoooddddoooollcc::cccccllllccc:::;;,,,,''.''''.....',ckXNWMNkox0XWWWWN0dclllllllooodddddxxxkkkkOOO00
.......... ... .. .....,;::::cccclllloooooooodoooooooollccclccclollccc:::;;,,,,,'''''''...'';lONWWMW0dx0NWWWWKxlllclllllooodddddxxxkkkOOOO00
.. ....... ... .. .....,;;:::::ccc:cccllloooooooooooloolccllc:cloolccc:::;;,,,,''''''''..'',:oOXWMWWXkk0NWWWNOdlllclllloooooddddxxxkkkOOOO00
.................. . . ....',;;::::;;;,'''',,,,;:ccclloollllcccllc::looolccc::;;,'''..........'',:lk0XWMWXkkKNWWNXkocllllllloooooddddxxxxkkkOOO00
.................. . ..',;;;;:;,,'''..'......''',;:::ccc::colc:;;loocc::;,,''...............',cxOKNWMNOkKNNNXKxlcccllllllooooddddxxxxkkkOOO00
.............. ..,,;;;;,;;;::::;;,,,,''.....'',,;;;:lolc:,':cc:;;,'.........'''''''''..';cx0NWMN0k0XKKN0occccclllllooooddddxxxxkkkOOOO0
................ ..,,;;,,,;:clllllllllllc:;,,''',,,;;coooc;,.'',,'........',;;;::;;,,,'''',;cd0NMW0xkK00NOoccccclllllooooddddxxxxkkkOOOO0
.................. .',,;;,,;:cllooolllc:;;,,'''',;;::cloodol:,...............',,'',,''''''',;;,:oKWWKxxO0kOOoccccccllllloooodddxxxxkkkOOO00
................... ..',;;;;;:cccc:;,,'.,'.......',,;cllooddol:,'...............',...........',,'':OWWXxdkOdxOo:ccccclllllooooddddxxxxkkkOOO0
..................... ..',;;::ccc:,'..',,','...''''';::clloooool:,'............',,,,''''''''......'':ONWNkdkOxdko:ccccccllllooooodddxxxxkkkkOOO
................. ..',;;::cc:::::::c::;;;,,,,,,,;:cllllooolc:;'...........'',,;;;;;,,''''....''',dXWNkdxkOxxo::ccccclllloooooddddxxxxkkkOOO
.............. ...',;:::cccclllllooolcc::;;;;;;:cllloooolc:;'............'',;;;;;,,'.......''',oKNN0xkO0Oxl::cccccclllooooooddddxxxkkkkOO
.............. ...',;;:ccccllooooooooolllllc:::ccllloooll:;;'.............'',,,,,,,''''..'''',;o0NWKkkOO0kl::ccccccllllloooooddddxxxkkkOO
.............. ..',,;:cclllloooddddddddoolccclloolooolll::;'..............''',,,,,,,'''''''',;o0NNOddkxkOo:::ccccccllllloooodddddxxxkkkk
. ................ ..'',;:cclllllooddddddoolcccloooooooollllc:;'...............''',,,,,,'''''''',:dKWXxloxlckx::::cccccclllllooooddddxxxxkkk
................... .....',;:ccllollooooooooollllodddoooooollllc:;'................'''',,,,,,,,''''';dKWKocdd:;dxc::::cccccclllllloooddddxxxxkk
................... .....',;::cllloooodddddoooooodddoooooooollll:,'................'''''',,,,''''''';xXWOlcxxc;cdl:::::ccccccclllllooooddddxxxk
................... ....',;;:ccllloodddddooooooddddooooooolllll:,'.................''''''''''''''.';xXNOoxOdolldc;:::::::cccccclllloooddddxxxx
................... ....',;:ccclloooddooooooooddddooooollllllc:;,...................'''''''''....',dKWX0XO:lodd:;;:::::::ccccccllllooooddddxx
.................... .. ....',;::ccllllooddddoooooddddooollllllolc:;,'...................'''''''....'',oKWNWWO:;:oo;;;;;::::::ccccccllllloooodddx
.................... ...........',;:::cccllooddddoooooddddoolllllloddlc:;''...................''''.......',oKWWNWO;,co:;;;;;;;;:::::::ccccllllooooddd
..................... ..........',;::cccclooododdddooooollllllllodxdlcc:,'...........................''.',oKWWWWk;;c:,;;;;;;;;;;::::::cccclllllooodd
..................................',;::cccclloooooddddoolllllllllllooolcc:;,'.........................'''.',oKNWWWk:;;,,,,,,;;;;;;;;;:::::cccclllllooo
..................................',;::ccccclloodddooollllloolc:::cllllcc:,,'.........................','.';dKNNWNd,,,,,,,,,,,;;;;;;;;;:::::cccclllloo
..................................',;:::cccclloooddoollllooolllccccccc:::;'................'''........,,,'';dKXXNXl,,,,,,,,,,,,,,;;;;;;;;:::::ccccllll
..................................',,;::cccclllloddoolloooolllllllccc:;,,,'................'''........','.';oO0KN0:',',,',,,,,,,,,,,;;;;;;;:::::ccccll
..................................',,;::ccccllllooolllolllllllllllllc;'';c:;,................''.......','',:oxk0Kx;','','',,,,,,,,,,,,;;;;;;;::::ccccc
.................................'',;;:cccccllllollllllllllccccclllc;',clc:;'.......................'''',:cccoOkc'''''''''''',,,,,,,,,,,;;;;;;:::::cc
.................................'',,;::cccclllllccccccccccccccclll:,,;clcc:,,'.....................''.',::::ldl,''''''''''''''',,,,,,,,,,;;;;;::::::
..................................',,;;::cccclllccccccccccccllllllc:;,;;:::;,,''''..................''..,:;;;:c,''..''''''''''''''',,,,,,,,,,;;;;;:::
...................................'',,;::ccccllccccccccclllllllllllc:::;;;;;,,''....................,,..,;;,;;,''.....'.''''''''''''',,,,,,,,,;;;;;;;
....................................',,;:::cclllc:cc:::;::::::::::::;;;;,''..........................',..,;,',,'.............'''''''''''',,,,,,,,,;;;;
.....................................',,;::cclllc:::::;::::::;;;;;;;,,,''.......................''...',..',',,..................'''''''''''',,,,,,,,,;
......................................',;;:::clllc::cccccccllcccccccc:::;;,,,,''...............''....''..',,,'..'...................''''''''',,,,,,,,,
.....................................',;;;::cclc::cccccccccccc::::;;;;;,,,,''''........................';:;.........................'''''''''''',,,,
....................................'',;;;::::::cc::cccccccc::;;,,,,,,''',,''........................',;l;............................''''''''''',,
.....................................',,;;;:::::cccccc::::::::;;,,,,,,,',,,'''......................',';o;..............................'''''''''''
.......................................',,,;;:::cccccccc::c::::::;;;::;;;;;,,'''.....................,'';l:'..................................''''''
.....................................',,;;::::cccccccccccccclllccccc::::;;,,''...................''..,oo''...................................''''
................................ ....'',;;;;;;::cccccllccccclllcccc::::;;,,,''.......................'dk;.,'.....................................
............................... ....''',;;;;;;;::cccclllccclcllccc::::;;,,''........................'o0o..,,....................................
............................ ......',,;;;;;;;:::cccccccllcc:::;;;;;,,,''........................'l0O,..::'..................................
.. ..................... .....'''',,,,,,;;::::::::cc:::;,,,,,,,,,,''........................,lOO:..':c:,'...............................
. ........ ......'''''',,,,,,;;::::;;;;;;;,'''''''''''.........................,lkk;...,cl:;,,''...........................
... ...'''''',,,,,,,,,;;;;;;;;,,,,,'''''................................,cxd,....;cc:,..''''''......................
...''''''',,,,,,;,,,,,,,,''''''''...................................':l:.....,:c:;'.........',,,,'..............
...''',,,,',,,,,;;;;,,,,,,,,,''''''..................................,;'......;cc:,'...........',;;;;;,'........
..''',,,;,,,,;;;;;;;,,,,,,,,''''''...................................... .....,::,'................';:c::;,....
..''',,;;;;;;;;;;;;;;;;;,,,,'''''''.................................... ......,;;'...................',;clll:;

______________________________________________________________________________________________________________________________________________________
_____________________________________________________________________________________________________________________________________________________
${NC}"


Expand All @@ -172,9 +96,17 @@ do
if [[ -z "$cmd" || "$cmd" == \#* || "$cmd" == "remove" ]]; then
continue
fi

echo -e "${YELLOW}Testing command: $cmd${NC}"

bash -c "$cmd" > "$TEMP_DIR/bash_output" 2> "$TEMP_DIR/bash_error"
if [[ "$cmd" == export* || "$cmd" == unset* ]]; then
eval "$cmd"
send_command "$cmd"
echo -e "${YELLOW}Command executed in script shell session, call 'env | grep ...' after this command to control the results."
continue
fi

bash --posix -c "$cmd" > "$TEMP_DIR/bash_output" 2> "$TEMP_DIR/bash_error"

truncate -s 0 "$TEMP_DIR/minishell_output"

Expand All @@ -185,14 +117,14 @@ do
sed '1d;/minishell>/d' "$TEMP_DIR/minishell_output" > "$TEMP_DIR/minishell_processed"

if ! diff -q "$TEMP_DIR/bash_output" "$TEMP_DIR/minishell_processed" >/dev/null
then
then
echo -e "${RED}Diff KO :(${NC}"
echo "Diff:"
diff --color=always "$TEMP_DIR/bash_output" "$TEMP_DIR/minishell_processed"
echo
echo
else
echo -e "${GREEN}Diff ok! :)${NC}"
fi
fi

done < "$TEST_COMMANDS"

Expand All @@ -202,4 +134,4 @@ if [[ "$last_line" == "remove" ]]; then
rm "$TEST_COMMANDS"
fi

cleanup
cleanup
Loading