Skip to content

Commit a5f117c

Browse files
authored
Implement self tests (#1)
* First look at implementing self testing 👍 * Update Travis lang to be generic * Fix Travis permdied error * Try to fix Travis build * Try to remove cp Travis command * input path fixes + more tests 🚀 * Update readme
1 parent a7ac602 commit a5f117c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+102
-108
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
language: generic
2+
install:
3+
- npm install
4+
script:
5+
- chmod u+x ./utest.sh && cd self_test && bash ../utest.sh

README.md

Lines changed: 11 additions & 2 deletions

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bash-universal-tester",
3-
"version": "1.9.2",
3+
"version": "1.9.3",
44
"description": "Universal testing script for bash",
55
"keywords": "bash, testing, tester, utest, bash-test, testing, script",
66
"homepage": "https://github.com/styczynski/bash-universal-tester",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
self_test:
2+
cwd: ./basic_usage_cli
3+
command: ../../utest.sh --tc --tno-spinner \\\"echo 123\\\" files
File renamed without changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sometest3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
123

self_test/basic_usage_cli/test.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Performing tests...
3+
Call echo 123 (short name: echo 123)
4+
5+
6+
[1/3] test1.in [OK]
7+
[2/3] test2.in [OK]
8+
[3/3] test3.in [OK]
9+
10+
Done testing. All 3 tests passes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
self_test:
2+
cwd: %{input_file_folder}
3+
command: ../../utest.sh --tc --tno-spinner

self_test/basic_usage_yaml/basic_usage_yaml.in

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test2
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sometest3
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sometest3

self_test/basic_usage_yaml/test.out

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
Performing tests...
3+
Call prog0 (short name: prog0)
4+
5+
6+
[1/3] test1.in [OK]
7+
[2/3] test2.in [OK]
8+
[3/3] test3.in [OK]
9+
10+
Done testing. All 3 tests passes.

self_test/basic_usage_yaml/utest.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
input: files/*.in
2+
good_output: %input_file_folder/%input_file_name.out
3+
executions:
4+
- prog0
5+
prog0:
6+
command: cat %input_file_path

self_test/utest.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
input: ./**/*.in
2+
good_output: %{input_file_folder}/test.out
3+
executions:
4+
- self_test
5+
self_test:
6+
command: echo NOT CONFIGURED

test/LICENSE

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

test/README.md

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

test/_utest.yaml

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

test/inp0.config.yaml

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

test/inp0.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/inp0.in.piped

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/inp0.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/inp1.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/inp1.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/inp2.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/inp2.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/inp22.in

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/inp22.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/inp3.in

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

test/inp3.out

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/totest.sh

Lines changed: 0 additions & 7 deletions
This file was deleted.
File renamed without changes.

utest.sh

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

3-
VERSION="1.9.2"
3+
VERSION="1.9.3"
44
IFS=$'\n'
55

66
# Dependencies
@@ -224,6 +224,7 @@ flag_additional_test_name_info=
224224
flag_pipe_input=()
225225
flag_pipe_output=()
226226
flag_pipe_err_output=()
227+
param_cwd=""
227228

228229
flag_hook_init=()
229230
flag_hook_deinit=()
@@ -804,13 +805,13 @@ function run_testing {
804805
if [[ "$flag_good_out_path" != "$flag_good_out_path_unparsed" ]]; then
805806
good_out_path="$flag_good_out_path"
806807
else
807-
flag_good_out_path=$flag_good_out_path_unparsed
808+
good_out_path=$flag_good_out_path_unparsed
808809
fi
809810

810811
if [[ "$flag_good_err_path" != "$flag_good_err_path_unparsed" ]]; then
811812
good_err_path="$flag_good_err_path"
812813
else
813-
flag_good_err_path=$flag_good_err_path_unparsed
814+
good_err_path=$flag_good_err_path_unparsed
814815
fi
815816

816817
if [[ ! -f "$good_out_path" ]]; then
@@ -1026,7 +1027,8 @@ function evalspec {
10261027

10271028
function evalspecplain {
10281029
code="${1//\%/\$}"
1029-
eval echo $code
1030+
code=$(eval echo "$code")
1031+
echo "$code"
10301032
}
10311033

10321034
#
@@ -1154,6 +1156,7 @@ function load_single_test_configuration_file {
11541156

11551157
# Load global config
11561158
load_prop_variable "${global_config_prefix}" "command" "param_prog"
1159+
load_prop_variable "${global_config_prefix}" "cwd" "param_cwd"
11571160
load_prop_variable "${global_config_prefix}" "args" "input_prog_flag_acc"
11581161
load_prop_variable "${global_config_prefix}" "input" "input_file_path"
11591162

@@ -1187,7 +1190,7 @@ function load_single_test_configuration_file {
11871190
# Sotre call name of prog
11881191
load_prop_variable "" "param_prog" "param_prog_call_name" "false"
11891192
load_prop_variable "${config_prefix}" "command" "param_prog"
1190-
1193+
load_prop_variable "${config_prefix}" "cwd" "param_cwd"
11911194

11921195
load_prop_variable "${config_prefix}" "input" "input_file_path"
11931196

@@ -1636,16 +1639,27 @@ function run_program {
16361639
tool_time_data_stime_start=`date +%s%3N`
16371640
fi
16381641

1639-
# There are no pipes used so do not operate on files
1640-
if [[ "$flag_no_pipes" = "true" ]]; then
1641-
r=$(eval $param_prog $input_prog_flag_acc < "${input_file_path}" 1> "${out_path}" 2> "${err_path}")
1642-
else
1643-
r=$(eval $param_prog $input_prog_flag_acc < "${input_file_path}.piped" 1> "${out_path}.piped" 2> "${err_path}.piped")
1644-
fi
1645-
1646-
1647-
1642+
if [[ ! "$param_cwd" = "" ]]; then
1643+
eval_call="( cd $param_cwd ; ${param_prog} ${input_prog_flag_acc} )"
1644+
1645+
# There are no pipes used so do not operate on files
1646+
if [[ "$flag_no_pipes" = "true" ]]; then
1647+
eval $eval_call < "${input_file_path}" 1> "${out_path}" 2> "${err_path}"
1648+
else
1649+
eval $eval_call < "${input_file_path}.piped" 1> "${out_path}.piped" 2> "${err_path}.piped"
1650+
fi
16481651

1652+
else
1653+
1654+
# There are no pipes used so do not operate on files
1655+
if [[ "$flag_no_pipes" = "true" ]]; then
1656+
r=$(eval $param_prog $input_prog_flag_acc < "${input_file_path}" 1> "${out_path}" 2> "${err_path}")
1657+
else
1658+
r=$(eval $param_prog $input_prog_flag_acc < "${input_file_path}.piped" 1> "${out_path}.piped" 2> "${err_path}.piped")
1659+
fi
1660+
1661+
fi
1662+
16491663
if [[ $flag_tools_use_stime = 'true' ]]; then
16501664
tool_time_data_stime_end=`date +%s%3N`
16511665
push_test_message_tooling_info "$((tool_time_data_stime_end-tool_time_data_stime_start))ms"
@@ -1703,7 +1717,6 @@ function run_program {
17031717
rm -f "${out_path}.piped"
17041718
fi
17051719

1706-
17071720
}
17081721

17091722
function run_utest {
@@ -1821,4 +1834,10 @@ do
18211834
shift
18221835
done
18231836
run_utest
1824-
sready
1837+
sready
1838+
if [[ "$err_index" != "0" ]]; then
1839+
close 1
1840+
fi
1841+
1842+
close 0
1843+

utest.yaml

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

0 commit comments

Comments
 (0)