File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,8 +48,8 @@ install: all
4848test : docopts
4949 ./docopts --version
5050 go test -v
51- python language_agnostic_tester.py ./testee.sh
52- cd tests/ && bats .
51+ python3 language_agnostic_tester.py ./testee.sh
52+ cd ./ tests/ && bats .
5353
5454# README.md is composed with external source too
5555# Markdown hidden markup are used to insert some text form the dependancies
Original file line number Diff line number Diff line change 66 " pipo" ,
77 " molo" ,
88 " toto"
9- ]
9+ ],
10+ "EMPTY_ARRAY" : []
1011 },
1112 "expect_args" : [
1213 " declare -A args" ,
14+ " args['EMPTY_ARRAY,#']=0" ,
1315 " args['FILE,0']='pipo'" ,
1416 " args['FILE,1']='molo'" ,
1517 " args['FILE,2']='toto'" ,
1618 " args['FILE,#']=3"
1719 ],
1820 "expect_global" : [
21+ " EMPTY_ARRAY=()" ,
1922 " FILE=('pipo' 'molo' 'toto')"
2023 ]
2124 },
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ releases:
2525 - fix error refusing mangling double dash in global mode [#52]
2626 - still refuse to mangle single dash `[-]` in global mode (not compatible with v0.6.1)
2727 - now can mangle single-dash and double-dash in `-G` mode
28+ - fix output bash empty array #53
2829
2930 internal changes:
3031 - use Go 1.17.1 for compiling
Original file line number Diff line number Diff line change @@ -181,13 +181,18 @@ func To_bash(v interface{}) string {
181181 case string :
182182 s = fmt .Sprintf ("'%s'" , Shellquote (v .(string )))
183183 case []string :
184- // escape all strings
185184 arr := v .([]string )
186- arr_out := make ([]string , len (arr ))
187- for i , e := range arr {
188- arr_out [i ] = Shellquote (e )
185+ if len (arr ) == 0 {
186+ // bash emtpy array
187+ s = "()"
188+ } else {
189+ // escape all strings
190+ arr_out := make ([]string , len (arr ))
191+ for i , e := range arr {
192+ arr_out [i ] = Shellquote (e )
193+ }
194+ s = fmt .Sprintf ("('%s')" , strings .Join (arr_out [:], "' '" ))
189195 }
190- s = fmt .Sprintf ("('%s')" , strings .Join (arr_out [:], "' '" ))
191196 case nil :
192197 s = ""
193198 default :
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ Step to produce a release.
55## 1. prepare the release
66
77copy the previous ` ./VERSION ` to ` ./tests/VERSION `
8+ This is for functional test ` get_doctops.bats ` so it can fetch a
9+ published release version.
810
911```
1012cp ./VERSION ./tests/VERSION
Original file line number Diff line number Diff line change @@ -65,3 +65,20 @@ Usage: prog dump [-]
6565 [[ " $output " =~ $expected_regexp ]]
6666 [[ $( echo " $output " | wc -l) -eq 9 ]]
6767}
68+
69+ # bug #53 non empty array
70+ @test " multiple length argument returns a 0 sized array" {
71+ # Global mode
72+ run $DOCOPTS_BIN -h ' Usage: prog [NAME...]' :
73+ [[ $status -eq 0 ]]
74+ expected_regexp=' NAME=\(\)'
75+ [[ " $output " =~ $expected_regexp ]]
76+ [[ ${# lines[@]} -eq 1 ]]
77+
78+ # also with -G
79+ run $DOCOPTS_BIN -G ARGS -h ' Usage: prog [NAME...]' :
80+ [[ $status -eq 0 ]]
81+ expected_regexp=' ARGS_NAME=\(\)'
82+ [[ " $output " =~ $expected_regexp ]]
83+ [[ ${# lines[@]} -eq 1 ]]
84+ }
Original file line number Diff line number Diff line change 44#
55
66_run_get_docopts () {
7- # go to repository basepath
8- cd ..
9- [[ $( basename $PWD ) == ' docopts' ]]
7+ # ensure we are still in tests sub-folder
8+ [[ $( basename $PWD ) == ' tests' ]]
109 [[ -x docopts ]] && rm docopts
11- run ./get_docopts.sh
10+ run .. /get_docopts.sh
1211 echo " $output "
1312 [[ $status -eq 0 ]]
1413}
You can’t perform that action at this time.
0 commit comments