Browse Source

[enh] unit tests: add make rule which compile, use variables for shell names and output files, add script test, enable hardcore test.

Moul 4 years ago
parent
commit
30797b261d
2 changed files with 19 additions and 6 deletions
  1. 5 1
      Makefile
  2. 14 5
      tests.sh

+ 5 - 1
Makefile

@@ -60,9 +60,13 @@ norm:
 	@make -C ../libft norm
 	@norminette $(SRC) src/*.h |  grep -v "42 header" | grep -B 1 "Error"
 
+test: all
+	@clear
+	@./tests.sh
+
 git:
 	@clear
 	@git status
 	@git diff
 
-.PHONY: all, clean, fclean, re, run, norm, git
+.PHONY: all, clean, fclean, re, run, norm, test, git

+ 14 - 5
tests.sh

@@ -97,17 +97,26 @@ tests=(
 ## Mix
 "rm $tmpf ; ls ; pwd; ls -a | cat -e | wc > $tmpf ; cat $tmpf ; rm $tmpf" # point-virgules, pipes et redirection
 "ls -a | cat -e | wc >> $tmpf ; cat $tmpf ; rm $tmpf" # pipes et double redirection
-#"mkdir test ; cd test ; ls -a ; ls | cat | wc -c > fifi ; cat fifi ; rm fifi"
+"mkdir test ; cd test ; ls -a ; ls | cat | wc -c > fifi ; cat fifi ; rm fifi ; cd .. ; rm -rf test"
 )
 
-folder=/tmp
+TSH="21sh"
+SH="zsh"
+TSHO="/tmp/"$TSH"_output"
+SHO="/tmp/"$SH"_output"
+
 clear
 echo "\033[0;35m##### TESTS UNITAIRES DU SHELL #####\033[0m"
+
 for tu in $tests
 do
 	echo "\033[0;32m>>>> Test \"$tu\" <<<<\033[0m"
-	./21sh -c $tu > $folder/21sh
-	zsh -c $tu > $folder/sh
-	diff $folder/21sh $folder/sh
+	./$TSH -c $tu > $TSHO
+	$SH -c $tu > $SHO
+	diff $TSHO $SHO
 	echo ""
 done
+echo "\033[0;32m>>>> Test \"sh shell_script.sh\" <<<<\033[0m"
+./$TSH shell_script.sh > $TSHO
+$SH shell_script.sh > $SHO
+diff $TSHO $SHO