Skip to content

Commit e51188e

Browse files
committed
docs update
1 parent c2a2488 commit e51188e

4 files changed

Lines changed: 68 additions & 54 deletions

File tree

README.md

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ and back them with shell step definitions:
2121

2222
```bash
2323
@When I run '{command}'
24-
run "$command"
24+
run "$command"
2525

2626
@Then the output should include '{text}'
27-
[[ "$LAST_STDOUT" == *"$text"* ]]
27+
[[ "$LAST_STDOUT" == *"$text"* ]]
2828
```
2929

30+
Indenting the step body is recommended for readability, but optional.
31+
3032
## Install
3133

3234
### Installing using the setup script
@@ -166,10 +168,10 @@ loads step definitions. You can rename it with `SHELLKIN_SUPPORT_FILE`.
166168

167169
```bash
168170
@When I run '{command}'
169-
run "$command"
171+
run "$command"
170172

171173
@Then the output should include '{text}'
172-
[[ "$LAST_STDOUT" == *"$text"* ]]
174+
[[ "$LAST_STDOUT" == *"$text"* ]]
173175
```
174176

175177
Each step definition starts with a header line:
@@ -182,13 +184,14 @@ Each step definition starts with a header line:
182184

183185
The lines that follow are the step body and are executed when the step
184186
matches.
187+
Indenting the body is recommended for readability, but optional.
185188

186189
Definition headers can use named tokens in braces. When a step matches, each
187190
token becomes an exported shell variable available to the body:
188191

189192
```bash
190193
@Then the file '{path}' should exist
191-
[[ -f "$path" ]]
194+
[[ -f "$path" ]]
192195
```
193196

194197
Token names must start with a letter or underscore, and may contain letters,
@@ -207,7 +210,7 @@ assertions.
207210

208211
```bash
209212
@When I run '{command}'
210-
run "$command"
213+
run "$command"
211214
```
212215

213216
`run` always returns success, even if the command fails. Inspect the captured
@@ -219,7 +222,7 @@ Use `fail` to fail the current step with an optional custom message.
219222

220223
```bash
221224
@Then the output should include '{text}'
222-
[[ "$LAST_STDOUT" == *"$text"* ]] || fail "invalid output detected"
225+
[[ "$LAST_STDOUT" == *"$text"* ]] || fail "invalid output detected"
223226
```
224227

225228
### `defer`
@@ -229,11 +232,11 @@ finishes.
229232

230233
```bash
231234
@Given I am in a temp directory
232-
old_pwd=$PWD
233-
temp_dir=$(mktemp -d)
234-
cd "$temp_dir"
235-
defer cd "$old_pwd"
236-
defer rm -rf "$temp_dir"
235+
old_pwd=$PWD
236+
temp_dir=$(mktemp -d)
237+
cd "$temp_dir"
238+
defer cd "$old_pwd"
239+
defer rm -rf "$temp_dir"
237240
```
238241

239242
Deferred actions are scenario-scoped, run after both passing and failing
@@ -254,9 +257,14 @@ Example:
254257

255258
```bash
256259
@Then the output should match
257-
[[ "$LAST_STDOUT" == "$DOC_STRING" ]]
260+
[[ "$LAST_STDOUT" == "$DOC_STRING" ]]
258261
```
259262

263+
## Examples
264+
265+
For real-world examples, see this repository's [features](features) directory
266+
and the [rush features](https://github.com/DannyBen/rush/tree/master/features).
267+
260268
## Uninstalling
261269

262270
If you used the setup script, you can run this uninstall script:

doc/shellkin-stepdefs.5

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,19 @@ The step body is plain shell code.
3636
.IP
3737
.EX
3838
\(atWhen I run \(aq{command}\(aq
39-
run \(dq$command\(dq
39+
run \(dq$command\(dq
4040
.EE
4141
.PP
42+
Indenting the body is recommended for readability, but optional.
43+
.PP
4244
Each definition continues until the next valid step header or the end of
4345
the file.
4446
.SS Tokens
4547
Patterns may contain named tokens in braces.
4648
.IP
4749
.EX
4850
\(atThen the file \(aq{path}\(aq should exist
49-
\f[B][[\f[R] \-f \(dq$path\(dq \f[B]]]\f[R]
51+
\f[B][[\f[R] \-f \(dq$path\(dq \f[B]]]\f[R]
5052
.EE
5153
.PP
5254
When the step matches, each token is exported as a shell variable for
@@ -60,7 +62,7 @@ Run a shell command and capture its result for later assertions.
6062
.IP
6163
.EX
6264
\(atWhen I run \(aq{command}\(aq
63-
run \(dq$command\(dq
65+
run \(dq$command\(dq
6466
.EE
6567
.PP
6668
The \f[B]run\f[R] helper always returns success, even when the command
@@ -70,18 +72,18 @@ Fail the current step with an optional custom message.
7072
.IP
7173
.EX
7274
\(atThen the output should include \(aq{text}\(aq
73-
\f[B][[\f[R] \(dq$LAST_STDOUT\(dq == *\(dq$text\(dq* \f[B]]]\f[R] \f[B]||\f[R] fail \(dqinvalid output detected\(dq
75+
\f[B][[\f[R] \(dq$LAST_STDOUT\(dq == *\(dq$text\(dq* \f[B]]]\f[R] \f[B]||\f[R] fail \(dqinvalid output detected\(dq
7476
.EE
7577
.SS defer
7678
Register cleanup code to run when the current scenario finishes.
7779
.IP
7880
.EX
7981
\(atGiven I am in a temp directory
80-
old_pwd=$PWD
81-
temp_dir=$(mktemp \-d)
82-
cd \(dq$temp_dir\(dq
83-
defer cd \(dq$old_pwd\(dq
84-
defer rm \-rf \(dq$temp_dir\(dq
82+
old_pwd=$PWD
83+
temp_dir=$(mktemp \-d)
84+
cd \(dq$temp_dir\(dq
85+
defer cd \(dq$old_pwd\(dq
86+
defer rm \-rf \(dq$temp_dir\(dq
8587
.EE
8688
.PP
8789
Deferred actions are scoped to the current scenario.
@@ -117,7 +119,7 @@ Then the output should match
117119
.IP
118120
.EX
119121
\(atThen the output should match
120-
\f[B][[\f[R] \(dq$LAST_STDOUT\(dq == \(dq$DOC_STRING\(dq \f[B]]]\f[R]
122+
\f[B][[\f[R] \(dq$LAST_STDOUT\(dq == \(dq$DOC_STRING\(dq \f[B]]]\f[R]
121123
.EE
122124
.SH EXAMPLE
123125
.IP
@@ -131,16 +133,16 @@ temp_workspace() \f[B]{\f[R]
131133
.IP
132134
.EX
133135
\(atGiven I am in a temp directory
134-
old_pwd=$PWD
135-
temp_workspace
136-
defer cd \(dq$old_pwd\(dq
137-
defer rm \-rf \(dq$temp_dir\(dq
136+
old_pwd=$PWD
137+
temp_workspace
138+
defer cd \(dq$old_pwd\(dq
139+
defer rm \-rf \(dq$temp_dir\(dq
138140
139141
\(atWhen I run \(aq{command}\(aq
140-
run \(dq$command\(dq
142+
run \(dq$command\(dq
141143
142144
\(atThen the file \(aq{path}\(aq should exist
143-
\f[B][[\f[R] \-f \(dq$path\(dq \f[B]]]\f[R]
145+
\f[B][[\f[R] \-f \(dq$path\(dq \f[B]]]\f[R]
144146
.EE
145147
.SH SEE ALSO
146148
\f[B]shellkin\f[R](1), \f[B]shellkin\-test\f[R](1),

doc/shellkin-stepdefs.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,11 @@ The step body is plain shell code.
4646

4747
```bash
4848
@When I run '{command}'
49-
run "$command"
49+
run "$command"
5050
```
5151

52+
Indenting the body is recommended for readability, but optional.
53+
5254
Each definition continues until the next valid step header or the end of the
5355
file.
5456

@@ -59,7 +61,7 @@ Patterns may contain named tokens in braces.
5961

6062
```bash
6163
@Then the file '{path}' should exist
62-
[[ -f "$path" ]]
64+
[[ -f "$path" ]]
6365
```
6466

6567
When the step matches, each token is exported as a shell variable for use in
@@ -78,7 +80,7 @@ Run a shell command and capture its result for later assertions.
7880

7981
```bash
8082
@When I run '{command}'
81-
run "$command"
83+
run "$command"
8284
```
8385

8486
The **run** helper always returns success, even when the command fails.
@@ -90,7 +92,7 @@ Fail the current step with an optional custom message.
9092

9193
```bash
9294
@Then the output should include '{text}'
93-
[[ "$LAST_STDOUT" == *"$text"* ]] || fail "invalid output detected"
95+
[[ "$LAST_STDOUT" == *"$text"* ]] || fail "invalid output detected"
9496
```
9597

9698
defer
@@ -100,11 +102,11 @@ Register cleanup code to run when the current scenario finishes.
100102

101103
```bash
102104
@Given I am in a temp directory
103-
old_pwd=$PWD
104-
temp_dir=$(mktemp -d)
105-
cd "$temp_dir"
106-
defer cd "$old_pwd"
107-
defer rm -rf "$temp_dir"
105+
old_pwd=$PWD
106+
temp_dir=$(mktemp -d)
107+
cd "$temp_dir"
108+
defer cd "$old_pwd"
109+
defer rm -rf "$temp_dir"
108110
```
109111

110112
Deferred actions are scoped to the current scenario. They run after both
@@ -137,7 +139,7 @@ Then the output should match
137139

138140
```bash
139141
@Then the output should match
140-
[[ "$LAST_STDOUT" == "$DOC_STRING" ]]
142+
[[ "$LAST_STDOUT" == "$DOC_STRING" ]]
141143
```
142144

143145
EXAMPLE
@@ -153,16 +155,16 @@ temp_workspace() {
153155

154156
```bash
155157
@Given I am in a temp directory
156-
old_pwd=$PWD
157-
temp_workspace
158-
defer cd "$old_pwd"
159-
defer rm -rf "$temp_dir"
158+
old_pwd=$PWD
159+
temp_workspace
160+
defer cd "$old_pwd"
161+
defer rm -rf "$temp_dir"
160162

161163
@When I run '{command}'
162-
run "$command"
164+
run "$command"
163165

164166
@Then the file '{path}' should exist
165-
[[ -f "$path" ]]
167+
[[ -f "$path" ]]
166168
```
167169

168170
SEE ALSO

features/step_definitions/core.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
@Given I am in a temp directory
2-
TEMP_DIR=$(mktemp -d)
3-
cd "$TEMP_DIR"
2+
old_pwd="$(pwd)"
3+
TEMP_DIR=$(mktemp -d)
4+
cd "$TEMP_DIR"
5+
defer cd "$old_pwd"
46

57
@When I run '{command}'
6-
PATH="$(pwd):$PATH" run "$command"
8+
PATH="$(pwd):$PATH" run "$command"
79

810
@Then the file '{path}' should exist
9-
[[ -f "$path" ]]
11+
[[ -f "$path" ]]
1012

1113
@Then the output should include '{text}'
12-
[[ "$LAST_STDOUT" == *"$text"* ]]
14+
[[ "$LAST_STDOUT" == *"$text"* ]]
1315

1416
@Then the error output should include '{text}'
15-
[[ "$LAST_STDERR" == *"$text"* ]]
17+
[[ "$LAST_STDERR" == *"$text"* ]]
1618

1719
@Then the output should match
18-
[[ "$LAST_STDOUT" == "$DOC_STRING" ]]
20+
[[ "$LAST_STDOUT" == "$DOC_STRING" ]]
1921

2022
@Then the exit code should mean success
21-
[[ "$LAST_EXIT_CODE" -eq 0 ]]
23+
[[ "$LAST_EXIT_CODE" -eq 0 ]]
2224

2325
@Then the exit code should mean failure
24-
[[ "$LAST_EXIT_CODE" -ne 0 ]]
26+
[[ "$LAST_EXIT_CODE" -ne 0 ]]

0 commit comments

Comments
 (0)