Skip to content

Commit a547893

Browse files
committed
Improved messaging style
1 parent 9ecfef6 commit a547893

File tree

5 files changed

+147
-32
lines changed

5 files changed

+147
-32
lines changed

test/inp1.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
425

test/inp1.out

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
15

test/inp2.in

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
425

test/inp2.out

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
15

utest.sh

+143-32
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ flag_testing_programs=
4141
flag_additional_test_name_info=
4242

4343

44+
4445
C_RED=$(printf "\e[1;31m")
4546
C_GREEN=$(printf "\e[1;32m")
4647
C_BLUE=$(printf "\e[1;34m")
@@ -99,6 +100,7 @@ function print_help {
99100
printf " All available [test_flags] are:\n"
100101
printf " --ttools <tools> - set additional debug tools\n"
101102
printf " Tools is the coma-separated array of tools names. Tools names can be as the following:\n"
103+
printf " * size - prints the size of input file in bytes.\n"
102104
printf " * time - prints time statistic using Unix time command.\n"
103105
printf " * stime - measures time using bash date command (not as precise as time tool).\n"
104106
printf " * vmemcheck - uses valgrind memcheck tools to search for application leaks.\n"
@@ -142,8 +144,24 @@ function print_help {
142144
}
143145

144146

147+
function prepare_input {
148+
if [[ -f $param_dir ]]; then
149+
folder_loc=${param_dir%%.*}
150+
if [[ ! -d "$folder_loc" ]]; then
151+
printf "${B_INFO}Test input is zip file -- needs unzipping...${E_INFO}\n"
152+
printf "${B_INFO}This may take a while...${E_INFO}\n"
153+
mkdir "$folder_loc"
154+
unzip -q "$param_dir" -d "$folder_loc"
155+
fi
156+
flag_good_err_path="${flag_good_err_path//$param_dir/$folder_loc}"
157+
flag_good_out_path="${flag_good_out_path//$param_dir/$folder_loc}"
158+
param_dir="$folder_loc"
159+
fi
160+
}
145161

146162
function verify_args {
163+
printf "${B_BOLD}--- utest.sh VERSION ${VERSION}v ---${E_BOLD}\n\n"
164+
147165
if [[ ${flag_force} = 'false' ]]; then
148166

149167
prog_use_autodetect=false
@@ -320,6 +338,7 @@ function count_input_files {
320338

321339

322340
function print_summary {
341+
printf "\n"
323342
if [[ $flag_minimal = 'false' ]]; then
324343
if [[ "$not_exists_index" != "0" ]]; then
325344
printf " ${B_WARN} $not_exists_index output files do not exits ${E_WARN}\n"
@@ -427,28 +446,107 @@ function test_err {
427446

428447

429448

449+
450+
451+
452+
453+
454+
455+
456+
457+
458+
message_accumulator=""
459+
message_last_file_head=""
460+
message_tooling_data_accumulator=""
461+
462+
function push_test_message_with_head {
463+
message_accumulator_head=""
464+
message_accumulator_file_head=""
465+
466+
if [[ "$message_accumulator" = "" ]]; then
467+
message_accumulator_head="${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $input_file"
468+
if [ $flag_testing_programs_len -gt 1 ]; then
469+
message_accumulator="${message_accumulator}\n${message_accumulator_head}\n"
470+
message_accumulator_head=""
471+
fi
472+
fi
473+
474+
message_accumulator_file_head="$flag_additional_test_name_info"
475+
if [[ "$message_accumulator_file_head" = "$message_last_file_head" ]]; then
476+
message_accumulator_file_head=""
477+
else
478+
message_last_file_head="$message_accumulator_file_head"
479+
fi
480+
481+
tooling_data="${message_tooling_data_accumulator}"
482+
if [[ "$1" = "" ]]; then
483+
message_accumulator_line=$(printf "%s%s%s\n" "${message_accumulator_head}${message_accumulator_file_head}" "$2" "")
484+
else
485+
message_accumulator_line=$(printf "%-30s%-30s%s\n" "${message_accumulator_head}${message_accumulator_file_head}" "$1" "${tooling_data}")
486+
fi
487+
488+
#printf "{PUSH TO ACCUMULATOR ${message_accumulator_line}}"
489+
message_accumulator="${message_accumulator}\n${message_accumulator_line}"
490+
}
491+
492+
function push_test_message_error {
493+
push_test_message_with_head "${B_ERR}$1${E_ERR}"
494+
}
495+
496+
function push_test_message_error_details {
497+
lineprefix=$(printf "%-20s" " ")
498+
err_message=$(echo -en "$1" | sed "s/^/${lineprefix}${B_ERR}\|${E_ERR} /g")
499+
push_test_message_with_head "" "${B_ERR}${err_message}${E_ERR}"
500+
}
501+
502+
function push_test_message_good {
503+
push_test_message_with_head "${B_OK}[OK]${E_OK}" ""
504+
}
505+
506+
function push_test_message_tooling_info {
507+
message_tooling_data_accumulator="${message_tooling_data_accumulator} ${B_INFO}[$1]${E_INFO}"
508+
}
509+
510+
function push_test_message_next_program {
511+
message_tooling_data_accumulator=""
512+
}
513+
514+
function flush_test_messages {
515+
echo -en "${message_accumulator}"
516+
message_accumulator=""
517+
message_last_file_head=""
518+
message_tooling_data_accumulator=""
519+
}
520+
521+
522+
523+
524+
525+
526+
527+
528+
529+
530+
531+
430532
function flush_err_messages {
431533
if [[ "$print_error_by_default" = "true" ]]; then
432534
err_index=$((err_index+1))
433535
err_message=$(cat "$err_path")
434-
printf "${B_INFO}i Provided error message: [${err_message}]${B_INFO}\n"
435536
if [[ $flag_extreamely_minimalistic = 'true' ]]; then
436-
printf "${B_ERR}$input_file${E_ERR}\n"
537+
push_test_message_error "$input_file"
437538
else
438539
if [[ $flag_very_minimal = 'true' ]]; then
439-
printf "%-35s %s\n" "${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $input_file $flag_additional_test_name_info" "${B_ERR}[ERR] Error at stderr${E_ERR}"
540+
push_test_message_error "Error at stderr"
440541
else
441-
printf "%-35s %s\n" "${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $input_file $flag_additional_test_name_info" "${B_ERR}[ERR] Error at stderr${E_ERR}"
442-
err_message=$(echo -en "$err_message" | sed "s/^/ $B_ERR\|$E_ERR /g")
443-
printf "$err_message\n"
542+
push_test_message_error "Error at stderr"
543+
push_test_message_error_details "$err_message\n"
444544
fi
445545
fi
446546
fi
447547
clean_temp_content
448548
}
449549

450-
451-
452550
function abort_if_too_many_errors {
453551
if [[ "$err_index" -gt 5 ]]; then
454552
if [[ $flag_always_continue = 'false' ]]; then
@@ -469,24 +567,23 @@ function check_out_script {
469567
if [[ $ok != 'true' ]]; then
470568
err_index=$((err_index+1))
471569
err_message=$diff
472-
err_message=$(echo -en "$err_message" | sed "s/^/ $B_ERR\|$E_ERR /g")
473570
if [[ $flag_extreamely_minimalistic = 'false' ]]; then
474-
printf "%-35s %s\n" "${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $input_file $flag_additional_test_name_info" "${B_ERR}[ERR] Invalid tester answer${E_ERR}"
571+
push_test_message_error "Invalid tester answer"
475572
else
476-
printf "${B_ERR}$input_file${E_ERR}\n"
573+
push_test_message_error "$input_file"
477574
fi
478575
if [[ $flag_very_minimal = 'false' ]]; then
479576
# We dont want this
480577
if [[ 'true' = 'false' ]]; then
481-
printf "\n ${B_ERR}_${E_ERR} \n$err_message\n ${B_ERR}|_${E_ERR} \n"
578+
push_test_message_error " \n$err_message\n ${B_ERR}|_${E_ERR} \n"
482579
else
483-
printf "$err_message\n"
580+
push_test_message_error_details "$err_message\n"
484581
fi
485582
fi
486583
else
487584
ok_index=$((ok_index+1))
488585
if [[ $flag_skip_ok = 'false' ]]; then
489-
printf "%-35s %s\n" "${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $input_file $flag_additional_test_name_info" "${B_OK}[OK]${E_OK}"
586+
push_test_message_good
490587
fi
491588
rm -f $err_path
492589
fi
@@ -504,18 +601,17 @@ function check_out_script_err {
504601
print_error_by_default=false
505602
err_index=$((err_index+1))
506603
err_message=$diff
507-
err_message=$(echo -en "$err_message" | sed "s/^/ $B_ERR\|$E_ERR /g")
508604
if [[ $flag_extreamely_minimalistic = 'false' ]]; then
509-
printf "%-35s %s\n" "${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $err_path $flag_additional_test_name_info" "${B_ERR}[ERR] Invalid tester answer for stderr${E_ERR}"
605+
push_test_message_error "Invalid tester answer for stderr"
510606
else
511-
printf "${B_ERR}$err_path${E_ERR}\n"
607+
push_test_message_erro "$err_path"
512608
fi
513609
if [[ $flag_very_minimal = 'false' ]]; then
514610
# We dont want this
515611
if [[ 'true' = 'false' ]]; then
516-
printf "\n ${B_ERR}_${E_ERR} \n$err_message\n ${B_ERR}|_${E_ERR} \n"
612+
push_test_message_error_details " \n$err_message\n ${B_ERR}|_${E_ERR} \n"
517613
else
518-
printf "$err_message\n"
614+
push_test_message_error_details "$err_message\n"
519615
fi
520616
fi
521617
fi
@@ -525,27 +621,26 @@ function check_out_diff {
525621
if [[ $diff != '' ]]; then
526622
err_index=$((err_index+1))
527623
err_message=$diff
528-
err_message=$(echo -en "$err_message" | sed "s/^/ $B_ERR\|$E_ERR /g")
529624

530625
if [[ $flag_extreamely_minimalistic = 'false' ]]; then
531-
printf "%-35s %s\n" "${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $input_file $flag_additional_test_name_info" "${B_ERR}[ERR] Non matching output${E_ERR}"
626+
push_test_message_error "Non matching output"
532627
else
533-
printf "${B_ERR}$input_file${E_ERR}\n"
628+
push_test_message_error "$input_file\n"
534629
fi
535630

536631
if [[ $flag_very_minimal = 'false' ]]; then
537632
# We dont want this
538633
if [[ 'true' = 'false' ]]; then
539-
printf "\n ${B_ERR}_${E_ERR} \n$err_message\n ${B_ERR}|_${E_ERR} \n"
634+
push_test_message_error_details " \n$err_message\n ${B_ERR}|_${E_ERR} \n"
540635
else
541-
printf "$err_message\n"
636+
push_test_message_error_details "$err_message\n"
542637
fi
543638
fi
544639

545640
else
546641
ok_index=$((ok_index+1))
547642
if [[ $flag_skip_ok = 'false' ]]; then
548-
printf "%-35s %s\n" "${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $input_file $flag_additional_test_name_info" "${B_OK}[OK]${E_OK}"
643+
push_test_message_good
549644
fi
550645
rm -f $err_path
551646

@@ -664,34 +759,46 @@ function run_program {
664759

665760
if [[ $flag_tools_use_stime = 'true' ]]; then
666761
tool_time_data_stime_end=`date +%s%3N`
667-
tooling_additional_test_info="${tooling_additional_test_info}Execution time (script dependent): $((tool_time_data_stime_end-tool_time_data_stime_start)) ms\n"
762+
push_test_message_tooling_info "$((tool_time_data_stime_end-tool_time_data_stime_start))ms"
763+
#tooling_additional_test_info="${tooling_additional_test_info}Execution time (script dependent): $((tool_time_data_stime_end-tool_time_data_stime_start)) ms\n"
668764
fi
669765

670766
if [[ $flag_tools_use_time = 'true' ]]; then
671767
#r=$($param_prog $input_prog_flag_acc < $input_file_path 1> $out_path 2> $err_path)
672768
timeOut=$({ time $param_prog $input_prog_flag_acc < $input_file_path 1> /dev/null 2> /dev/null ; } 2>&1 )
673769
timeOut="$(echo -e "${timeOut}" | sed '/./,$!d')"
674-
tooling_additional_test_info="${tooling_additional_test_info}${timeOut}\n"
770+
#tooling_additional_test_info="${tooling_additional_test_info}${timeOut}\n"
771+
timeReal=$(echo "${timeOut}" | grep real | sed -e 's/real//')
772+
timeReal="$(echo -e "${timeReal}" | tr -d '[:space:]')"
773+
push_test_message_tooling_info "${timeReal}"
675774
fi
676775

677776
if [[ $flag_tools_use_vmassif = 'true' ]]; then
678777
{ valgrind --tool=massif --pages-as-heap=yes --massif-out-file=massif.out $param_prog $input_prog_flag_acc < $input_file_path 1> /dev/null 2> /dev/null ; } > /dev/null 2>&1
679778
memUsage=$(grep mem_heap_B massif.out | sed -e 's/mem_heap_B=\(.*\)/\1/' | sort -g | tail -n 1)
680779
memUsage=$(echo "scale=5; $memUsage/1000000" | bc)
681-
tooling_additional_test_info="${tooling_additional_test_info}Peak memory usage: ${memUsage}MB\n"
780+
#tooling_additional_test_info="${tooling_additional_test_info}Peak memory usage: ${memUsage}MB\n"
781+
push_test_message_tooling_info "${memUsage}MB"
682782
rm ./massif.out
683783
fi
684784

685785
if [[ $flag_tools_use_vmemcheck = 'true' ]]; then
686786
{ valgrind --tool=memcheck $param_prog $input_prog_flag_acc < $input_file_path > /dev/null ; } 2> ./memcheck.out
687787
leaksReport=$(sed 's/==.*== //' ./memcheck.out | sed -n -e '/LEAK SUMMARY:/,$p' | sed 's/LEAK SUMMARY://' | head -5)
688788
if [[ $leaksReport != '' ]]; then
689-
tooling_additional_test_info="${tooling_additional_test_info}Leaks detected / Report:\n${leaksReport}\n"
789+
#tooling_additional_test_info="${tooling_additional_test_info}Leaks detected / Report:\n${leaksReport}\n"
790+
push_test_message_tooling_info "Leaks!"
690791
else
691-
tooling_additional_test_info="${tooling_additional_test_info}No leaks possible.\n"
792+
#tooling_additional_test_info="${tooling_additional_test_info}No leaks possible.\n"
793+
push_test_message_tooling_info "No leaks"
692794
fi
693795
rm ./memcheck.out
694796
fi
797+
798+
if [[ $flag_tools_use_size = 'true' ]]; then
799+
inputFileSize=$(stat -c%s "${input_file_path}")
800+
push_test_message_tooling_info "<${inputFileSize} bytes"
801+
fi
695802

696803

697804
}
@@ -786,6 +893,7 @@ done
786893

787894

788895
set_format
896+
prepare_input
789897
verify_args
790898
clean_out_err_paths
791899
collect_testing_programs
@@ -809,7 +917,7 @@ do
809917
prog=${flag_testing_programs[${prog_iter}]}
810918
#echo "|===> Prog ${prog}"
811919
if [ $flag_testing_programs_len -gt 1 ]; then
812-
flag_additional_test_name_info="(${B_INFO} ${prog} ${E_INFO})"
920+
flag_additional_test_name_info="${B_INFO} ${prog} ${E_INFO}"
813921
else
814922
flag_additional_test_name_info=""
815923
fi
@@ -835,11 +943,14 @@ do
835943
test_out
836944
print_tooling_additional_test_info
837945
fi
838-
file_index=$((file_index+1))
839946
fi
840947
clean_temp_content
841948
prog_iter=$((prog_iter+1))
949+
push_test_message_next_program
842950
done
951+
952+
file_index=$((file_index+1))
953+
flush_test_messages
843954
done
844955

845956

0 commit comments

Comments
 (0)