Skip to content

Commit ccd24b6

Browse files
author
Sylvain Viart
committed
final commit in branch before merge to master
1 parent e7d60ea commit ccd24b6

File tree

8 files changed

+104
-82
lines changed

8 files changed

+104
-82
lines changed

TODO.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* ~~test python's version behavior with our input~~
1515
* ~~add example of usage for handling `-` (stdin argument)~~
1616
* ~~remove 100% compatible with python~~
17+
* ~~add documentation on how to add functional testing in bats~~
1718

1819
## better error handling
1920

@@ -23,28 +24,50 @@ See also:
2324

2425
PR: https://github.com/docopt/docopt.go/pull/65
2526

27+
It probably needs to rewrite the docopt parser.
28+
2629
## --json output ?
2730

2831
same as `--no-mangle` but json formated
2932

3033
Somewhat discussed here: https://github.com/docopt/docopt/issues/174
3134

35+
Trivial, could be implemented, even without embbeding JSON lib.
36+
See branch `json-api` too.
37+
3238
## functional testing for all options
3339

3440
`./docopts --help`
41+
* `tests/functional_tests_docopts.bats` was introduced in PR #52
3542

3643
## return or kill for function instead of exit
3744

3845
Add a parameter to handle return or kill instead of exit so it can be launched inside a function.
3946

47+
See also: https://github.com/docopt/docopts/issues/43
48+
4049
## embeded JSON?
4150

4251
See [API_proposal.md](API_proposal.md)
4352

53+
Drop JSON but keep new command line action arguments option style?
54+
55+
```
56+
docopts parse "$usage" : [<args>...]
57+
```
58+
4459
## generate bash completion from usage
4560

61+
Would probably need a new docopt parser too.
62+
63+
```
64+
docopts -h "$help" --generate-completion
65+
```
66+
4667
```
4768
docopts -h "$help" --generate-completion
69+
# or
70+
docopts completion "$usage"
4871
```
4972

5073
## embed test routine (argument validation)?

bug/double_dash_mangle/BUILD.md

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

bug/double_dash_mangle/test-docopts.sh

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

docker/README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Some docker container with docopts installed
2+
3+
No special purpose than to recreate an environment with `docopts`
4+
5+
## Build the docker image
6+
7+
The `--build-arg` is used to pass teh version of `docpots` to download pre-built binary.
8+
If you're publishing `docpots` the `../VERSION` may not yet reflect a published version.
9+
You can find previously published VERSION in `../tests/VERSION`.
10+
11+
```
12+
docker build -f debian-docopts.Dockerfile --build-arg VERSION=$(cat ./VERSION) -t debian-docpots .
13+
```
14+
15+
## Run interactive
16+
17+
You will have latest python version 0.6.1 in PATH as `docopts` and Go version in PATH too as `docopts0`
18+
19+
Golang work space will also be installed if you want to test something.
20+
21+
```
22+
docker run -it debian-docpots:latest
23+
```

bug/double_dash_mangle/Dockerfile renamed to docker/debian-docopts.Dockerfile

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,19 @@ RUN apt-get install -y --no-install-recommends \
1919
WORKDIR /app
2020
COPY *.sh \
2121
/app/
22-
RUN chmod a+x test-docopts.sh
2322

24-
# install precompiled binary publiished ==> docopts0
25-
RUN wget https://github.com/docopt/docopts/releases/download/v0.6.3-rc2/docopts_linux_amd64
23+
# install precompiled binary published ==> docopts0
24+
ARG VERSION
25+
RUN wget https://github.com/docopt/docopts/releases/download/$VERSION/docopts_linux_amd64
2626
RUN install -o root -g root -m a+x docopts_linux_amd64 /usr/local/bin/docopts0
2727

2828
# install a golang build env
2929
# predownload the tgz so it get docker cached
30-
RUN wget --quiet https://dl.google.com/go/go1.14.1.linux-amd64.tar.gz
30+
RUN wget --quiet https://dl.google.com/go/go1.17.1.linux-amd64.tar.gz
3131
RUN ./update_go.sh
3232
ENV PATH=$PATH:/app:/usr/local/go/bin:/root/go/bin
3333

34-
# clone patched version from contributor repository
35-
RUN git clone -b do-not-publish-double-dash https://github.com/DanaLacoste/docopts.git patched
36-
37-
# prepare gobuilding pre-requisites
38-
WORKDIR /app/patched
3934
RUN go get github.com/docopt/docopt-go && go get github.com/docopt/docopts
40-
# build patched version
41-
RUN go build docopts.go
4235

4336
# intall python version 0.6.1 ==> /usr/local/bin/docopts
4437
RUN pip3 install docopts

bug/double_dash_mangle/update_go.sh renamed to docker/update_go.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ set -e
1717

1818
# change this go version for updating
1919
# can be copy/paste from the email announcing the version
20-
GOVER=go1.14.1
20+
GOVER=go1.17.1
2121

2222
if [[ $actual_gover == $GOVER ]] ; then
2323
echo "$gobin version: $actual_gover is the same as $GOVER"

docopts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func To_bash(v interface{}) string {
183183
case []string:
184184
arr := v.([]string)
185185
if len(arr) == 0 {
186-
// bash emtpy array
186+
// bash empty array
187187
s = "()"
188188
} else {
189189
// escape all strings

docs/developer.md

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,43 @@ go test -v
108108

109109
### bats (functionnal testing) (bash)
110110

111+
Most `.bats` files in `tests/` folder are test for bash code `docopts.sh` functions,
112+
and are more internal stuff, hack as you wish but it may be more complicated to
113+
handle at first.
114+
115+
Functional tests are in [`tests/functional_tests_docopts.bats`](tests/functional_tests_docopts.bats).
116+
117+
This this `bats` syntax test, this means almost bash.
118+
119+
Add a new functional test:
120+
121+
```
122+
@test "your comment describing the test here" {
123+
# run is a bats helper that run a command catching all
124+
# use the $DOCOPTS_BIN to ensure to point to the good binary
125+
# pass any docopts argument to test, good or wrong
126+
run $DOCOPTS_BIN -G ARGS -h 'Usage: prog dump [-]' : dump -
127+
128+
# output is caught by bats (stdout + stderr)
129+
# and wont be displayed, unless a test fail: any non-0 bash code
130+
echo "$output"
131+
132+
# test docopts return value 0 on success
133+
[[ $status -eq 0 ]]
134+
135+
regexp='some bash regexp'
136+
[[ "$output" =~ $regexp ]]
137+
}
138+
```
139+
140+
run only functional test (`bats` in `PATH`):
141+
142+
``` bash
143+
# test are ran from test folder only
144+
cd tests
145+
bats functional_tests_docopts.bats
146+
```
147+
111148
### `docopts_test.go` (unit testing) (golang + JSON)
112149

113150
It uses standard `go test`. Some method are "exposed" with Capital name only for testing purpose.
@@ -119,14 +156,14 @@ Options loop test JSON: [`common_input_test.json`](../common_input_test.json)
119156
This is our input file for testing options parsed recieved from docopt lib. We emulate docopt parsed options and give
120157
them as input to our method.
121158

122-
JSON tests are read as a list of test: (others json keys should be ignored and are used as comment)
159+
JSON tests are read as a list of test: (others JSON keys should be ignored and are used as comment)
123160
Our parser JSON parser / loader [`test_json_load.go`](../test_json_load/test_json_load.go), only used for testing.
124161

125162
```go
126163
type TestString struct {
127-
Input map[string]interface{}
128-
Expect_args []string
129-
Expect_global []string
164+
Input map[string]interface{}
165+
Expect_args []string
166+
Expect_global []string
130167
Expect_global_prefix []string // optional
131168
}
132169
```
@@ -153,25 +190,29 @@ add a new bloc of JSON object (dict / hash / map):
153190
],
154191
"expect_global": [
155192
"FILE=('pipo' 'molo' 'toto')"
193+
],
194+
"expect_global_prefix": [
195+
"ARGS_FILE=('pipo' 'molo' 'toto')"
156196
]
157197
},
158198
```
159199

160200
* `description` a comment which is ignored
161-
* other extra JSON key that are not the 3 following will be ignored too.
201+
* other extra JSON key that are not the 4 following will be ignored too.
162202
* `input` correspond to the `map[string]interface{}` of docopt parsed options.
163203
* `expect_args` the text rows of the associative array code for bash4 that is outputed by `Print_bash_args()` matched in order.
164204
* `expect_global` the text definition of the bash global vars that is outputed by `Print_bash_global()` matched in order.
165205
* `expect_global_prefix` [optional] if present will be used for testing `Mangle_key` + `Global_prefix` instead of [`rewrite_prefix("ARGS",)`](../docopts_test.go)
166-
So in `expect_global_prefix` the prefix must be `ARGS` + `_`.
206+
So left hand values in `expect_global_prefix` the prefix must be `ARGS` + `_`.
167207

168208

169209
### testcases.docopt (agnostic test universal to docopt parsing language)
170210

171-
This file is still avaible from python docopt original repository too [testcases.docopt](https://github.com/docopt/docopt/blob/511d1c57b59cd2ed663a9f9e181b5160ce97e728/testcases.docopt)
211+
This file is still avaible from python docopt lib original repository
212+
too [testcases.docopt](https://github.com/docopt/docopt/blob/511d1c57b59cd2ed663a9f9e181b5160ce97e728/testcases.docopt)
172213

173214
This is the input file used by `language_agnostic_tester.py`, which is a middleware originaly written to read
174-
`testcases.docopt` and to send it to ~> `testee.sh` ~> `docopts` ~> JSON ~> the result is the validated against the
215+
`testcases.docopt` and to send it to ~> `testee.sh` ~> `docopts -A` ~> JSON ~> the result is the validated against the
175216
embedded JSON expected result.
176217

177218
Input file format is historically as follow:
@@ -191,7 +232,7 @@ $ prog -a
191232

192233
## Golang debugger
193234

194-
Debugger is a must for any programming language. Go provide an extrenal debugger named [delve](https://github.com/go-delve/delve)
235+
Debugger is a must for any programming language. Go provides an extrenal debugger named [delve](https://github.com/go-delve/delve)
195236

196237
https://github.com/go-delve/delve/tree/master/Documentation
197238

@@ -215,6 +256,6 @@ s # for steping into the current function
215256
p some_varialbles
216257
```
217258

218-
The debugger will then magically bring you step after step to the bug!
219-
Enjoy! and promote dubugger in evrery programming language and every programming course. :wink:
259+
The debugger will then magically bring you, step after step, to the bug!
260+
Enjoy! and promote dubugger in every programming language and every programming course. :wink:
220261

0 commit comments

Comments
 (0)