Closed andreaulicna closed 9 months ago
Works only if the HOME has been unset before running the tester, no idea why though.
Next-up: put printfs for exit_status everywhere
The problem here is that:
The tester uses the prompt of the minishell (defined as $PROMPT
in minishell_tester/tester
) to identify the rows that are not part of the output
It does so, by running minishell
and then inputing \n
and exit
as commands and afterwards extrating (the part head -n 1
) the first line from the terminal output that just the prompt itself with no command
In the (very simplified) example below, the line starting "/home/andrea/..." and "exit" would be understood as the output of the minishell (unless removed in a different command, as, for example, exit is in $REMOVE_EXIT
)
When run in all other tests, our prompt is and also stays after running the test command to be aulicna@DESKTOP-7ESJEVQ:~/coding/42cursus_home/42_minishell
Therefore, it can be used to identify whether or not a particular line is an ouput of the minishell (that should be compared against the output of bash) or not
However, when the test unset HOME
is run, the prompt of our minishell changes (as it should, because that's what bash does).
Yet, the tester still keeps using the original prompt for comparison between minishell and bash outputs causing the line with the new prompt to be treated as an ouput line from our minishell even if it is not
Basically, it seems like the tester didn't expect people to go as far as recreating the bash prompt to a degree, where it changes if the HOME
is unset even though it should
And so what is needed to make the tester understand that there is a line with the new prompt in the terminal output that should not be treated as the output of minishell is to:
$PROMPT_NEW
variable: PROMPT_NEW=$(echo -e "unset HOME\n\nexit\n" | $MINISHELL_PATH | head -n 2 | tail -n 1 | sed "s/\x1B\[[0-9;]\{1,\}[A-Za-z]//g" )
unset HOME
, \n
, \n
, exit
and keeping first 2 lines (head -n 2
) and then the last line out of those two (tail -n 1
)
Then this new prompt needs to be added to where the original prompt is getting extracted from the terminal output to identify just the minishell output (the lines left)
$MINI_OUPUT
and $MINI_EXIT_CODE
:MINI_OUTPUT=$(echo -e "$teste" | $MINISHELL_PATH 2> /dev/null | $REMOVE_COLORS | grep -vF "$PROMPT" | grep -vF "$PROMPT_NEW" | $REMOVE_EXIT )
MINI_EXIT_CODE=$(echo -e "$MINISHELL_PATH\n$teste\necho \$?\nexit\n" | bash 2> /dev/null | $REMOVE_COLORS | grep -vF "$PROMPT" | grep -vF "$PROMPT_NEW" | $REMOVE_EXIT | tail -n 1)
Minishell tester returns an error even though it works when tested manually.