feat: testsuite summary and enhanced tests look

This commit is contained in:
Gu://em_ 2026-01-21 22:59:33 +01:00
parent 402b1614b5
commit ed6e761f9c

112
tests/functional/run-tests.sh Normal file → Executable file
View file

@ -1,20 +1,20 @@
#!/bin/bash #!/bin/bash
echo WIP: vous pourriez regretter de lancer ce script
exit 2
################### ###################
# Variables # # Variables #
################### ###################
executable="../../src/42sh" executable="../../src/42sh"
errors_count=0 ref_executable="dash"
total_tests=0
tmp_script="/tmp/test_script.sh" tmp_script="/tmp/test_script.sh"
output="/tmp/42sh_tests.output" output="/tmp/42sh_tests.output"
ref_output="/tmp/42sh_tests_ref.output" ref_output="/tmp/42sh_tests_ref.output"
total_tests=0
errors_count=0
timeouts_count=0
################## ##################
@ -113,19 +113,25 @@ check_result() {
test_failed=0 test_failed=0
# Check return code # Check return code
if [[ "$actual_code" -ne "$ref_code" ]]; then if [[ "$actual_code" -eq 124 ]]; then
echo $BRed "FAILED" $Color_off echo -e $BRed "TIMEOUT" $Color_Off
echo $Blue ' ' "on '$2'" $Color_off echo -e ' ' "on '$command'"
echo ' ' "Expected code $ref_code but got $actual_code" echo -e ' ' "Expected code $ref_code but got $actual_code"
((timeouts_count++))
test_failed=1
elif [[ "$actual_code" -ne "$ref_code" ]]; then
echo -e $BRed "FAILED" $Color_Off
echo -e ' ' "on '$command'"
echo -e ' ' "Expected code $ref_code but got $actual_code"
test_failed=1 test_failed=1
# Check output # Check output
elif [ diff $output $ref_output > /dev/null ]; then elif diff $output $ref_output > /dev/null; then
echo $BRed "FAILED" $Color_off echo -e $BRed "FAILED" $Color_Off
echo $Blue ' ' "on '$2'" $Color_off echo -e ' ' "on '$command'"
echo ' ' "Output is not the one expected" echo -e ' ' "Output is not the one expected"
test_failed=1 test_failed=1
else else
echo $Blue OK $Colors_off echo -e $BGreen OK $Color_Off
fi fi
if [[ "$test_failed" -eq 1 ]]; then if [[ "$test_failed" -eq 1 ]]; then
@ -141,17 +147,17 @@ test_str() {
# Check input # Check input
if [[ -z "$1" || -z "$2" ]]; then if [[ -z "$1" || -z "$2" ]]; then
echo $BRed "\n\n" "Issue in the testsuite: test_str: One or more argument is empty" $Color_off echo -e $BRed "\n\n" "Issue in the testsuite: test_str: One or more argument is empty" $Color_Off
exit 2 exit 2
fi fi
echo $BBlue "=== $1 ===" $Color_off echo -e $BBlue "================== $1 ==================" $Color_Off
echo "$2" > $tmp_script echo -e "$2" > $tmp_script
# Arg # Arg
echo -n "\n= [ARG] " echo -e -n $Blue "= [ARG] " $Color_Off
$executable -c "$2" &> $output timeout 2 $executable -c "$2" &> $output
actual_code=$? actual_code=$?
$ref_executable -c "$2" &> $ref_output $ref_executable -c "$2" &> $ref_output
ref_code=$? ref_code=$?
@ -159,8 +165,8 @@ test_str() {
check_result "$2" "$actual_code" "$ref_code" check_result "$2" "$actual_code" "$ref_code"
# Script # Script
echo -n "\n= [SCRIPT] " echo -e -n $Blue "= [SCRIPT]" $Color_Off
$executable "$tmp_script" &> $output timeout 2 $executable "$tmp_script" &> $output
actual_code=$? actual_code=$?
$ref_executable "$tmp_script" &> $ref_output $ref_executable "$tmp_script" &> $ref_output
ref_code=$? ref_code=$?
@ -168,15 +174,16 @@ test_str() {
check_result "$2" "$actual_code" "$ref_code" check_result "$2" "$actual_code" "$ref_code"
# Stdin # Stdin
echo -n "\n= [STDIN] " echo -e -n $Blue "= [STDIN] " $Color_Off
$executable < "$tmp_script" &> $output timeout 2 $executable < "$tmp_script" &> $output
actual_code=$? actual_code=$?
$ref_executable < "$2" &> $ref_output $ref_executable < "$tmp_script" &> $ref_output
ref_code=$? ref_code=$?
((total_tests++)) ((total_tests++))
check_result "$tmp_script" "$actual_code" "$ref_code" check_result "$2" "$actual_code" "$ref_code"
echo $BBlue "===================" $Color_off "\n" echo -e "\n"
# echo -e $BBlue "===========================================" $Color_Off "\n"
} }
# @arg test name # @arg test name
@ -185,19 +192,19 @@ test_script() {
# Check input # Check input
if [[ -z "$1" || -z "$2" ]]; then if [[ -z "$1" || -z "$2" ]]; then
echo $BRed "\n\n" "Issue in the testsuite: test_script: One or more argument is empty" $Color_off echo -e $BRed "\n\n" "Issue in the testsuite: test_script: One or more argument is empty" $Color_Off
exit 2 exit 2
fi fi
if [[ ! -f "$2" ]]; then if [[ ! -f "$2" ]]; then
echo $BRed "\n\n" "Issue in the testsuite: test_script: Second argument is not a file" $Color_off echo -e $BRed "\n\n" "Issue in the testsuite: test_script: Second argument is not a file" $Color_Off
exit 2 exit 2
fi fi
echo $BBlue "=== $1 ===" $Color_off echo -e $BBlue "================== $1 ==================" $Color_Off
# Script # Script
echo -n "\n= [SCRIPT] " echo -e -n "= [SCRIPT] "
$executable "$tmp_script" &> $output timeout 2 $executable "$tmp_script" &> $output
actual_code=$? actual_code=$?
$ref_executable "$tmp_script" &> $ref_output $ref_executable "$tmp_script" &> $ref_output
ref_code=$? ref_code=$?
@ -205,15 +212,38 @@ test_script() {
check_result "$2" "$actual_code" "$ref_code" check_result "$2" "$actual_code" "$ref_code"
# Stdin # Stdin
echo -n "\n= [STDIN] " echo -e -n "= [STDIN] "
$executable < "$tmp_script" &> $output timeout 2 $executable < "$tmp_script" &> $output
actual_code=$? actual_code=$?
$ref_executable < "$2" &> $ref_output $ref_executable < "$2" &> $ref_output
ref_code=$? ref_code=$?
((total_tests++)) ((total_tests++))
check_result "$tmp_script" "$actual_code" "$ref_code" check_result "$tmp_script" "$actual_code" "$ref_code"
echo $BBlue "===================" $Color_off "\n" echo -e "\n"
# echo -e $BBlue "===========================================" $Color_Off "\n"
}
summarize() {
(( passed_tests = $total_tests - $errors_count ))
(( tests_percentage = 100 * $passed_tests / $total_tests ))
if [[ tests_percentage -gt 80 ]]; then
coverage_color=$BGreen
elif [[ tests_percentage -gt 50 ]]; then
coverage_color=$BYellow
elif [[ tests_percentage -gt 30 ]]; then
coverage_color=$BOrange
else
coverage_color=$BRed
fi
echo -e $BWhite "\n\n""===========" $UWhite"Summary"$Color_Off "\n"
echo -e " Passed $coverage_color$passed_tests/$total_tests$Color_Off tests ($coverage_color$tests_percentage$Color_Off%)"
echo -e " Got $BRed$timeouts_count timeout(s)$Color_Off"
echo
} }
# *********************************************************** # ***********************************************************
@ -221,4 +251,18 @@ test_script() {
# Tests # # Tests #
################# #################
echo -e "\n\n""===$BGreen TestsuitatorX Ultra Pro Max+ 365 Premium Gris Sidéral" "\n\n"$Color_Off
# echo
test_str "Hello" "echo Hello there" test_str "Hello" "echo Hello there"
test_str "Hello;" "echo Hello there;"
test_str "'Hello'" "echo 'Hello there'"
test_str "Hello;Hello" "echo Hello; echo Wesh attends quoi; echo pouquoi je suis une ligne en dessous"
# programs
test_str "LS" "ls"
test_str "Le SS" "lss"
summarize