correctif on some stuff + ajout framework for test

This commit is contained in:
wescande 2017-03-03 18:49:39 +01:00
parent bc40339015
commit 4c44407b65
13 changed files with 114 additions and 7 deletions

View file

@ -0,0 +1 @@
echo 'je suis un test'

View file

@ -0,0 +1 @@
ls

View file

@ -0,0 +1 @@
pwd

View file

View file

14
42sh/TESTSHELL/stdin_ref Normal file
View file

@ -0,0 +1,14 @@
42sh
Makefile
TESTSHELL
donovan_segaults_06-02
file1
file2
includes
libft
objs
pdf
sample
src
test_framework.sh
update_makefile.sh

43
42sh/TESTSHELL/stdin_test Normal file
View file

@ -0,0 +1,43 @@
 main.c 107start of shell JOBC is ON
 token_print.c 21 token print
 token_print.c 25 token : TK_WORD data [ls]

 insert_newline.c 19 insert newline
 ft_parse.c 45 

 build_tree.c 83 func TK : 'TK_WORD' TK : 'TK_WORD'
 add_cmd.c 55 add data
 ft_parse.c 45 

 build_tree.c 83 func TK : 'TK_NEWLINE' TK : 'TK_NEWLINE'
 add_sep.c 21 add sep
 ft_parse.c 45 

 ft_parse.c 58 sucessful parsing
 main.c 64 Before execution:
NEW
+----+
CMD
 ft_exec.c 39 
 ft_exec.c 48 match : TK_NEWLINE and TK_NEWLINE
 exec_semi.c 20 
 exec_semi.c 22 
 ft_exec.c 39 
 ft_exec.c 48 match : NON-DEFINED and NON-DEFINED
 exec_command.c 52 op=2118139328
42sh
Makefile
TESTSHELL
donovan_segaults_06-02
file1
file2
includes
libft
objs
pdf
sample
src
test_framework.sh
update_makefile.sh
 exec_semi.c 24 
 ft_exec.c 39 

View file

@ -6,7 +6,7 @@
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/14 17:28:14 by jhalford #+# #+# */
/* Updated: 2017/03/03 17:59:42 by jhalford ### ########.fr */
/* Updated: 2017/03/03 18:44:43 by wescande ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/02 20:44:21 by jhalford #+# #+# */
/* Updated: 2017/03/03 16:47:47 by jhalford ### ########.fr */
/* Updated: 2017/03/03 18:44:42 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -26,7 +26,9 @@ int add_new_job(t_job *job)
if (JOB_IS_FG(job->attrs))
put_job_in_foreground(job, 0);
else
{
job_notify_new(job);
put_job_in_background(job, 0);
}
return (0);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/13 14:58:36 by jhalford #+# #+# */
/* Updated: 2017/03/02 20:59:44 by jhalford ### ########.fr */
/* Updated: 2017/03/03 18:44:44 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -19,7 +19,6 @@ int put_job_in_foreground(t_job *j, int cont)
jobc = &data_singleton()->jobc;
tcsetpgrp(STDIN, j->pgid);
tcsetattr(STDIN, TCSADRAIN, &jobc->shell_tmodes);
if (cont)
{
tcsetattr(STDIN, TCSADRAIN, &j->tmodes);

View file

@ -6,7 +6,7 @@
/* By: gwojda <gwojda@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 14:19:48 by gwojda #+# #+# */
/* Updated: 2017/03/02 12:36:35 by jhalford ### ########.fr */
/* Updated: 2017/03/03 18:29:03 by wescande ### ########.fr */
/* */
/* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jhalford@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/06 18:40:58 by jhalford #+# #+# */
/* Updated: 2017/03/03 18:05:41 by jhalford ### ########.fr */
/* Updated: 2017/03/03 18:33:40 by wescande ### ########.fr */
/* */
/* ************************************************************************** */
@ -63,10 +63,14 @@ int handle_instruction(int fd)
}
DG("Before execution:");
btree_print(STDBUG, ast, &ft_putast);
DG();
if (ft_exec(&ast))
return (1);
DG();
btree_del(&ast, &ast_free);
DG();
ft_add_str_in_history(lexer.str);
DG();
return (0);
}
@ -83,6 +87,7 @@ int get_input_fd()
return (fd);
else if (data->opts & SH_OPTS_LC)
{
DG();
pipe(fds);
fd = fds[PIPE_READ];
file = shell_get_avdata();
@ -105,7 +110,7 @@ int main(int ac, char **av)
shell_init(ac, av);
DG("{inv}{bol}{gre}start of shell{eoc} JOBC is %s",
SH_HAS_JOBC(data_singleton()->opts)?"ON":"OFF");
if ((fd = get_input_fd() < 0))
if ((fd = get_input_fd()) < 0)
{
ft_printf("{red}%s: No such file or directory\n{eoc}", SHELL_NAME);
return (1);

41
42sh/test_framework.sh Executable file
View file

@ -0,0 +1,41 @@
SHELL=$1
TOTAL_TEST=0
NBR_TEST_SUCCESS=0
unset LIST_TEST
LIST_TEST='./TESTSHELL/*'/'*'.test
DIR_TEST=./TESTSHELL
do_test() {
for TEST in $LIST_TEST
do
($SHELL < $TEST 1> ${DIR_TEST}/stdin_test 2> ${DIR_TEST}/stderr_test)
(bash < $TEST 1> ${DIR_TEST}/stdin_ref 2> ${DIR_TEST}/stderr_ref)
if ! diff ${DIR_TEST}/stdin_test ${DIR_TEST}/stdin_ref > /dev/null ||
! diff ${DIR_TEST}/stderr_test ${DIR_TEST}/stderr_test > /dev/null
then
echo "\033[0;31mFAILURE $TEST" >> ${DIR_TEST}/resultat
else
((NBR_TEST_SUCCESS++))
fi
((TOTAL_TEST++))
done
}
do_test
if [ -e ${DIR_TEST}/resultat ]
then
cat ${DIR_TEST}/resultat
fi
echo "\033[0;32mYou succeed $NBR_TEST_SUCCESS tests on $TOTAL_TEST"
rm -f $DIR_TEST/resultat
#add random input sed -n $RANDOM "p" /usr/share/dict/words
#add timeout
#charging phase of test
#real verification of references
#to add extranous comportement