Skip to content

Commit 195d959

Browse files
committed
Working spinner 🎉
1 parent 0530ed0 commit 195d959

File tree

5 files changed

+198
-37
lines changed

5 files changed

+198
-37
lines changed

README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,58 @@ utest.sh --tpipe-out "cat %input | sort > %output" <prog> <folder>
209209
Advantage of pipes are that you do not modify in/out files directly.
210210
And you can test programs that may potentailly give not exactly the same answers but which are still correct.
211211

212+
## Configuration file
213+
214+
### Global configuration
215+
216+
Instead of passing all parameters by command line we offer the ability to put everything into single *YAML* file!
217+
218+
Utest seek for `utest.yaml` file in current directory. It can contain all configuration available via
219+
command line switches and flags!
220+
221+
All config options are listed there:
222+
223+
```yaml
224+
225+
input: test/*.in
226+
good_output: test/%input_file_name.out
227+
good_err: test/%input_file_name.err
228+
need_error_files: false
229+
testing_script_out: ignore
230+
testing_script_err: ignore
231+
executions:
232+
- prog1
233+
- prog2
234+
prog1:
235+
command: ./test/totest.sh
236+
args: %input_file_name
237+
pipes_out:
238+
- echo 123 > %output
239+
pipes_in:
240+
- echo 123 > %output
241+
pipes_out_err:
242+
- echo 123 > %output
243+
- cat %input | echo 123 > %output
244+
prog2:
245+
command: echo 99
246+
247+
```
248+
249+
You can also configure environment for **single test case**!
250+
Just put `xyz.config.yaml` file next to your input file `xyz.in`.
251+
252+
All options of config file for single test are listed below:
253+
254+
```yaml
255+
256+
totest_sh:
257+
args: %input_file_name some additional args
258+
in: override_input_file.in
259+
260+
```
261+
262+
You must identify program by the command it calls.
263+
212264
[badge sts]: https://img.shields.io/badge/-styczynsky_digital_systems-blue.svg?style=flat-square&logoWidth=20&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABYAAAAXCAYAAAAP6L%2BeAAAABmJLR0QA%2FwD%2FAP%2BgvaeTAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH4AgSEh0nVTTLngAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAAm0lEQVQ4y2Pc%2Bkz2PwMNAAs2wVMzk4jSbJY%2BD6ccEwONACMsKIh1JSEgbXKeQdr4PO1cPPQMZiGkoC7bkCQD7%2Fx7znDn35AOClK9PEJSBbNYAJz999UGrOLocsM0KHB5EZ%2FXPxiVMDAwMDD8SP3DwJA6kFka5hJCQOBcDwMDAwPDm3%2FbGBj%2BbR8tNrFUTbiAB8tknHI7%2FuTilAMA9aAwA8miDpgAAAAASUVORK5CYII%3D
213265

214266
[badge download]: https://img.shields.io/badge/-download_me!-green.svg?style=flat-square&logoWidth=10&logo=data%3Aimage%2Fpng%3Bbase64%2CiVBORw0KGgoAAAANSUhEUgAAABkAAAArCAYAAACNWyPFAAAABmJLR0QA%2FwD%2FAP%2BgvaeTAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAAB3RJTUUH4AgTDjEFFOXcpQAAAM1JREFUWMPt2EsOgzAMBFDPJHD%2F80Jid1G1KpR8SqKu7C2QJzwWsoCZSWedb0Tvg5Q%2FlCOOOOKII4444ogjjvxW8bTjYtK57zNTSoCdNm5VBcmRhdua7SJpKaXhN2hmEmO0fd%2BnANXgl2WxbduGAVUFVbUY9rquPVARyDmDpJCktKBK66pACOE5Ia%2FhUlUhaTPm9xM4ZEJScs6YDXwFH0IYgq6Ay%2Bm6C5WAQyYXo9edUQ2oIr1Q5TPUh4iImJkAsMI1AO3O4u4fiV5AROQBGVB7Fu2akxMAAAAASUVORK5CYII%3D

test/_inp0.config.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.

test/inp0.config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
prog2:
2+
command: echo THIS IS OVERRIDEN
3+
args: INPUT %input_file_name

utest.sh

Lines changed: 130 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
VERSION="1.6.2"
3+
VERSION="1.7.0"
44

55
# Dependencies
66

@@ -52,7 +52,7 @@ parse_yaml() {
5252
# for tested program
5353

5454
function shortname {
55-
short_name=$(basename "$1" | awk -F. '{print $1"_"$2}')
55+
short_name=$(basename "$1" | tr . _)
5656
printf "$short_name"
5757
}
5858

@@ -113,7 +113,8 @@ function _spinner() {
113113
sp='\|/-'
114114
delay=${SPINNER_DELAY:-0.15}
115115

116-
echo -ne " "
116+
#echo -ne " "
117+
printf "\n "
117118
while :
118119
do
119120
printf "\b${sp:i++%${#sp}:1}"
@@ -128,21 +129,23 @@ function _spinner() {
128129
if [[ -z ${3} ]]; then
129130
#echo "spinner is not running.."
130131
#exit 1
131-
#echo -e ""
132-
sleep 0
133-
else
134-
kill -9 $3 > /dev/null 2>&1
135-
while kill -0 $3 2>/dev/null; do sleep 0.005; done
136-
# inform the user upon success or failure
137-
echo -ne "\b"
138-
#if [[ $2 -eq 0 ]]; then
139-
# echo -en "${green}${on_success}${nc}"
140-
#else
141-
# echo -en "${red}${on_fail}${nc}"
142-
#fi
143-
#echo -e ""
144-
fi
145-
;;
132+
#echo -e ""
133+
sleep 0
134+
else
135+
kill -9 $3 > /dev/null 2>&1
136+
while kill -0 $3 2>/dev/null; do sleep 0.005; done
137+
sleep 0.005
138+
printf "\b\b\b \b\b\b"
139+
# inform the user upon success or failure
140+
#echo -ne "\b"
141+
#if [[ $2 -eq 0 ]]; then
142+
# echo -en "${green}${on_success}${nc}"
143+
#else
144+
# echo -en "${red}${on_fail}${nc}"
145+
#fi
146+
#echo -e ""
147+
fi
148+
;;
146149
*)
147150
echo "invalid argument, try {start/stop}"
148151
exit 1
@@ -151,7 +154,7 @@ function _spinner() {
151154
}
152155

153156
spinner_is_running=false
154-
flag_use_spinner=false
157+
flag_use_spinner=true
155158

156159
function start_spinner {
157160
if [[ "$flag_use_spinner" = "true" ]]; then
@@ -235,7 +238,8 @@ flag_additional_test_name_info=
235238
flag_pipe_input=()
236239
flag_pipe_output=()
237240
flag_pipe_err_output=()
238-
flag_no_pipes="true"
241+
# Should be changed
242+
flag_no_pipes="false"
239243
flag_full_in_path_in_desc="false"
240244

241245
flag_override_good_out_file=
@@ -267,6 +271,10 @@ E_OK=
267271

268272
TEXT_OK="OK"
269273

274+
# TODO REMOVE
275+
#sleep 1
276+
#sready
277+
#exit 22
270278

271279
function clean_temp_content {
272280
if [[ ${flag_out_temp} = 'true' ]]; then
@@ -775,21 +783,59 @@ function evalspecplain {
775783
}
776784

777785
#
778-
# Usage: load_prop_variable <variable_prefix> <variable_name> <output_variable>
786+
# Usage: load_prop_variable <variable_prefix> <variable_name> <output_variable> <false_to_disable_parsing>
779787
#
780788
function load_prop_variable {
781789
input_var_name="${1}${2}"
782790
output_var_name="${3}"
783-
input_var_value="${!input_var_name}"
791+
input_var_value_raw="${!input_var_name}"
792+
input_var_value="$input_var_value_raw"
793+
if [[ "$4" != "false" ]]; then
794+
input_var_value=$(evalspecplain "$input_var_value_raw")
795+
fi
784796
output_var_value="${!output_var_name}"
785797

786798
if [[ "${input_var_value}" != '' ]]; then
787-
return_buffer="${return_buffer}${output_var_name}=\"${output_var_value}\"\n"
799+
return_buffer="${output_var_name}=\"${output_var_value}\"\n${return_buffer}"
800+
#printf "load_prop_variable ${output_var_name} -> ${input_var_value}\n"
801+
eval $output_var_name="\$input_var_value"
802+
fi
803+
}
804+
805+
#
806+
# Usage: load_prop_value <value> <output_variable> <false_to_disable_parsing>
807+
#
808+
function load_prop_value {
809+
temp_prop_variable_cap="${1}"
810+
load_prop_variable "" "temp_prop_variable_cap" "${2}" "{3}"
811+
temp_prop_variable_cap=""
812+
}
813+
814+
#
815+
# Usage: load_prop_variable_arr <variable_prefix> <variable_name> <output_variable>
816+
#
817+
function load_prop_variable_arr {
818+
input_var_name="${1}${2}"
819+
output_var_name="${3}"
820+
input_var_value_raw=$(eval echo "\"\${${input_var_name}[@]}\"")
821+
#printf "_name => $input_var_name\n"
822+
#printf "_raw => $input_var_value_raw\n"
823+
input_var_value="$input_var_value_raw"
824+
#input_var_value=$(evalspecplain "$input_var_value_raw")
825+
output_var_value="${!output_var_name}"
826+
827+
if [[ "${input_var_value}" != '' ]]; then
828+
return_buffer="${output_var_name}=\"${output_var_value}\"\n${return_buffer}"
788829
#printf "load_prop_variable ${output_var_name} -> ${input_var_value}\n"
789-
eval $output_var_name=\$input_var_value
830+
831+
#eval $output_var_name=\$input_var_value
832+
eval $output_var_name='$input_var_value'
833+
834+
#printf "cur val => ${!output_var_name}\n"
790835
fi
791836
}
792837

838+
793839
function load_global_configuration_file {
794840
return_buffer=""
795841
global_configuration_file_path="./utest.yaml"
@@ -801,8 +847,20 @@ function load_global_configuration_file {
801847
#printf "LOAD GLOBAL CONFIURATION FILE ${global_configuration_file_path}\n"
802848
configuration_parsed_setup=$(parse_yaml "${global_configuration_file_path}" "global_config_" "false")
803849

804-
evalspec "$configuration_parsed_setup"
805-
850+
#printf "Global setup file contents:\n$configuration_parsed_setup\n"
851+
eval "$configuration_parsed_setup"
852+
853+
load_prop_variable "global_config_" "input" "param_dir" "false"
854+
load_prop_variable "global_config_" "good_output" "flag_good_out_path" "false"
855+
load_prop_variable "global_config_" "good_err" "flag_good_err_path" "false"
856+
857+
load_prop_variable "global_config_" "need_error_files" "flag_always_need_good_err" "false"
858+
859+
load_prop_variable "global_config_" "testing_script_out" "flag_test_out_script"
860+
load_prop_variable "global_config_" "testing_script_err" "flag_test_err_script"
861+
862+
863+
#printf "HERE flag_good_out_path => ${flag_good_out_path}\n"
806864

807865
if [[ "$global_config_executions_" != "" ]]; then
808866
prog_arr_parser_acc=""
@@ -825,24 +883,54 @@ function load_global_configuration_file {
825883

826884
function load_single_test_configuration_file {
827885
return_buffer=""
886+
887+
short_name=$(shortname "$param_prog")
888+
if [[ "$param_prog_call_name" != "" ]]; then
889+
short_name=$(shortname "$param_prog_call_name")
890+
fi
891+
#printf "short_name :=> $short_name\n"
892+
893+
config_prefix="test_config_${short_name}__"
894+
global_config_prefix="global_config_${short_name}__"
895+
896+
#printf "glob config prefix: ${global_config_prefix}test\n"
897+
898+
# Load global config
899+
load_prop_variable "${global_config_prefix}" "command" "param_prog"
900+
load_prop_variable "${global_config_prefix}" "args" "input_prog_flag_acc"
901+
load_prop_variable "${global_config_prefix}" "in" "input_file_path"
902+
903+
load_prop_variable_arr "${global_config_prefix}" "pipes_out_" "flag_pipe_output"
904+
load_prop_variable_arr "${global_config_prefix}" "pipes_out_err_" "flag_pipe_err_output"
905+
load_prop_variable_arr "${global_config_prefix}" "pipes_in_" "flag_pipe_input"
906+
907+
#load_prop_variable "${global_config_prefix}" "testing_script_out" "flag_test_out_script"
908+
#load_prop_variable "${global_config_prefix}" "testing_script_err" "flag_test_err_script"
909+
910+
911+
#flag_test_out_script
912+
828913
if [ -f "$single_test_configuration_file_path" ]; then
829914
#
830915
# Load configuration file for single test execution
831916
#
832917

833-
short_name=$(shortname "$param_prog")
834-
config_prefix="test_config_${short_name}__"
835-
836918
#printf "LOAD CONFIURATION FILE ${single_test_configuration_file_path}\n"
837919
configuration_parsed_setup=$(parse_yaml "${single_test_configuration_file_path}" "test_config_" "false" | grep "$short_name")
838920

839921
#printf "CONFIG:\n"
840922
#printf "$configuration_parsed_setup\n"
841923

842-
evalspec "$configuration_parsed_setup"
924+
eval "$configuration_parsed_setup"
843925

844926
load_prop_variable "${config_prefix}" "args" "input_prog_flag_acc"
845-
load_prop_variable "${config_prefix}" "executable" "param_prog"
927+
928+
#printf "input_prog_flag_acc ==> ${input_prog_flag_acc}\n"
929+
930+
# Sotre call name of prog
931+
load_prop_variable "" "param_prog" "param_prog_call_name" "false"
932+
load_prop_variable "${config_prefix}" "command" "param_prog"
933+
846934
load_prop_variable "${config_prefix}" "in" "input_file_path"
847935

848936

@@ -854,13 +942,18 @@ function load_single_test_configuration_file {
854942
}
855943

856944
function unload_single_test_configuration_file {
945+
946+
# Backup pre-global settings
947+
backup_global_config_script=$(printf "$return_buffer")
948+
eval "$backup_global_config_script"
949+
857950
if [ -f "$single_test_configuration_file_path" ]; then
858951
#
859952
# Unload configuration file for single test execution
860953
#
861954
configuration_parsed_teardown=$(parse_yaml "${single_test_configuration_file_path}" "test_config_" "true")
862955

863-
backup_config_script=$(printf "$configuration_parsed_teardown\n$return_buffer\n")
956+
backup_config_script=$(printf "$configuration_parsed_teardown")
864957

865958
#printf "backup config:\n"
866959
#printf "$backup_config_script"
@@ -933,6 +1026,7 @@ function push_test_message_next_program {
9331026
}
9341027

9351028
function flush_test_messages {
1029+
sready
9361030
echo -en "${message_accumulator}"
9371031
message_accumulator=""
9381032
message_last_file_head=""
@@ -972,7 +1066,7 @@ function abort_if_too_many_errors {
9721066
if [[ "$err_index" -gt 5 ]]; then
9731067
if [[ $flag_always_continue = 'false' ]]; then
9741068
sready
975-
printf "\n${B_WARN}[!] Abort testing +5 errors.${E_WARN}\nDo not use --ta flag to always continue."
1069+
printf "\n${B_WARN}[!] Abort testing +5 errors.${E_WARN}\nDo not use --ta flag to always continue."
9761070
clean_temp
9771071
close 1
9781072
fi
@@ -1084,7 +1178,7 @@ function check_testing_script {
10841178
fi
10851179
if [[ $test_not_exists = 'true' ]]; then
10861180
sready
1087-
printf "%-35s %s\n" "${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $input_file $flag_additional_test_name_info" "${B_ERR}[ERR] Testing script does not exists or is invalid command (--tscript). Abort.${E_ERR}"
1181+
printf "%-35s %s\n" "${B_DEBUG}[$file_index/$file_count]${E_DEBUG} $input_file $flag_additional_test_name_info" "${B_ERR}[ERR] Testing script does not exists or is invalid command (--tscript). Abort.${E_ERR}"
10881182
printf "%-30s %s\n" " " "${B_ERR}Used command: $flag_test_out_script${E_ERR}"
10891183

10901184
clean_temp
@@ -1170,7 +1264,7 @@ function print_tooling_additional_test_info {
11701264
if [[ $tooling_additional_test_info != '' ]]; then
11711265
tooling_message=$(echo -en "$tooling_additional_test_info" | sed "s/^/ /g")
11721266
sready
1173-
printf "${B_DEBUG}${tooling_message}${E_DEBUG}\n"
1267+
printf "${B_DEBUG}${tooling_message}${E_DEBUG}\n"
11741268
fi
11751269
}
11761270

@@ -1490,6 +1584,7 @@ do
14901584
#
14911585
flag_good_out_path_unparsed=$flag_good_out_path
14921586
flag_good_err_path_unparsed=$flag_good_err_path
1587+
14931588
flag_good_out_path=$(evalspecplain "$flag_good_out_path")
14941589
flag_good_err_path=$(evalspecplain "$flag_good_err_path")
14951590

utest.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
input: test/*.in
2+
good_output: test/%input_file_name.out
3+
need_error_files: false
4+
executions:
5+
- prog1
6+
- prog2
7+
prog1:
8+
command: ./test/totest.sh
9+
args: %input_file_name
10+
pipes_out:
11+
- echo 15 > %output
12+
prog2:
13+
command: echo 15

0 commit comments

Comments
 (0)