gabr 2.0.13 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Makefile +0 -0
- package/README.md +59 -64
- package/bin/bats-exec-suite +20 -9
- package/bin/bats-exec-test +22 -19
- package/bin/bats-format-tap-stream +7 -0
- package/example/GIT.md +35 -3
- package/example/IFS.sh +3 -0
- package/example/clang.c +17 -0
- package/example/git.sh +16 -18
- package/example/npm.sh +15 -6
- package/example/usage.sh +18 -17
- package/gabr.linux.sh +34 -23
- package/gabr.sh +30 -26
- package/package.json +3 -4
- package/say.sh +10 -0
- package/start/start.sh +11 -0
- package/test/gabr.bats +25 -11
- package/usage.sh +1 -5
- package/modules/bats-core/LICENSE.md +0 -53
- package/modules/bats-core/README.md +0 -530
- package/modules/bats-core/bin/bats +0 -44
- package/modules/bats-core/libexec/bats-core/bats +0 -171
- package/modules/bats-core/libexec/bats-core/bats-exec-suite +0 -101
- package/modules/bats-core/libexec/bats-core/bats-exec-test +0 -373
- package/modules/bats-core/libexec/bats-core/bats-format-tap-stream +0 -174
- package/modules/bats-core/libexec/bats-core/bats-preprocess +0 -58
- package/modules/bats-core/man/Makefile +0 -10
- package/modules/bats-core/man/README.md +0 -5
- package/modules/bats-core/man/bats.1 +0 -115
- package/modules/bats-core/man/bats.1.ronn +0 -115
- package/modules/bats-core/man/bats.7 +0 -178
- package/modules/bats-core/man/bats.7.ronn +0 -156
- package/modules/shdoc/LICENSE +0 -21
- package/modules/shdoc/README.md +0 -93
- package/modules/shdoc/shdoc +0 -174
- /package/example/{javascript → javascript.js} +0 -0
package/Makefile
CHANGED
|
File without changes
|
package/README.md
CHANGED
|
@@ -23,12 +23,12 @@ $ npm link gabr
|
|
|
23
23
|
> If you want to run `gabr` as a local function, try `. gabr`
|
|
24
24
|
|
|
25
25
|
## What is gabr.sh
|
|
26
|
-
Gabr is a Bash
|
|
26
|
+
Gabr is a Bash-function designed to call other Bash-functions.
|
|
27
27
|
Gabr takes arguments and will try to turn that in to a function call.
|
|
28
28
|
Gabr takes the path of least resistance towards a function call.
|
|
29
29
|
Let's illustrate that with a flowchart.
|
|
30
30
|
|
|
31
|
-

|
|
32
32
|
|
|
33
33
|
> This flowchart doesn't show error cases. These cases are mostly when the last argument did not result
|
|
34
34
|
> in the execution of a real function.
|
|
@@ -36,52 +36,32 @@ Let's illustrate that with a flowchart.
|
|
|
36
36
|
Let's illustrate further with a code example.
|
|
37
37
|
```shell
|
|
38
38
|
$ echo "\
|
|
39
|
-
function hello() {
|
|
40
|
-
printf '%s\n' 'Usage: gabr hello world' >&2
|
|
41
|
-
}
|
|
42
|
-
function world() {
|
|
43
|
-
printf '%s\n' 'Hello World.' >&2
|
|
44
|
-
}
|
|
45
|
-
" > ./hello.sh
|
|
46
|
-
$ gabr hello
|
|
47
|
-
Usage: gabr hello world
|
|
48
|
-
$ gabr hello world
|
|
49
|
-
Hello World.
|
|
50
|
-
```
|
|
51
|
-
> By naming the file and the function hello,
|
|
52
|
-
> a tiny API emerged to call the function.
|
|
53
|
-
|
|
54
|
-
A different approach would be:
|
|
55
|
-
```shell
|
|
56
|
-
$ echo "\
|
|
57
39
|
if [ \$# -eq 0 ]; then
|
|
58
|
-
|
|
40
|
+
printf '%s\n' 'Usage: gabr hello world' >&2
|
|
59
41
|
fi
|
|
60
|
-
function usage() {
|
|
61
|
-
printf '%s' 'Usage: gabr hello world'
|
|
62
|
-
}
|
|
63
42
|
function world() {
|
|
64
43
|
printf '%s\n' 'Hello World.' >&2
|
|
65
44
|
}
|
|
66
45
|
" > ./hello.sh
|
|
67
46
|
$ gabr hello
|
|
68
47
|
Usage: gabr hello world
|
|
69
|
-
$ gabr hello usage
|
|
70
|
-
Usage: gabr hello world
|
|
71
48
|
$ gabr hello world
|
|
72
49
|
Hello World.
|
|
73
50
|
```
|
|
74
|
-
|
|
51
|
+
|
|
52
|
+
And there you have it. That's all it does. But it is deceptively useful.
|
|
75
53
|
|
|
76
54
|
## Why use gabr.sh?
|
|
55
|
+
Use it when you want to make a simple API to automate stuff *you* care about.
|
|
77
56
|
Consider the following commands to delete a tag with git:
|
|
78
57
|
```shell
|
|
79
58
|
git tag -d 1.0.1
|
|
80
59
|
git push origin :refs/tags/1.0.1
|
|
81
60
|
```
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
61
|
+
This is hard to remember next time you'd need it.
|
|
62
|
+
It's also hard to delete multiple tags because you'd need
|
|
63
|
+
to shift your cursor around to change the tags.
|
|
64
|
+
Now consider the following function.
|
|
85
65
|
```bash
|
|
86
66
|
set -eu
|
|
87
67
|
function deleteTag() {
|
|
@@ -91,18 +71,35 @@ function deleteTag() {
|
|
|
91
71
|
```
|
|
92
72
|
> Let's say it's saved in `./git.sh`
|
|
93
73
|
|
|
94
|
-
|
|
74
|
+
This is easy to forget too, but one can refresh memory by looking at the file.
|
|
75
|
+
|
|
76
|
+
To run this function like `gabr` would, one could simply write:
|
|
95
77
|
```shell
|
|
96
78
|
$ (. git.sh; deleteTag 1.0.1)
|
|
97
79
|
```
|
|
98
|
-
But doing it like this is hard to communicate and prone to human error.
|
|
80
|
+
But doing it like this is hard to communicate and prone to human error.
|
|
81
|
+
With `gabr` a more direct api emerges to do these kind of things:
|
|
99
82
|
```
|
|
100
83
|
$ gabr git deleteTag 1.0.1
|
|
101
84
|
```
|
|
85
|
+
With this basic concept, all functions you see in .sh files
|
|
86
|
+
will be available through a simple api that is easy to communicate.
|
|
87
|
+
Just type in what you see.
|
|
88
|
+
|
|
89
|
+
## Sourcing `gabr` vs running `gabr`
|
|
90
|
+
For normal use I recommend running `gabr` as a file. This is default behavior when running `npm link`.
|
|
91
|
+
If you've forked the repo and npm-linked from there then any changes will update the linked file.
|
|
92
|
+
|
|
93
|
+
It is also possible to source `gabr`. This can be used in scripts or a shell-terminal.
|
|
94
|
+
By running `. gabr`, gabr will not run as a file but instead as a function. For example:
|
|
95
|
+
```shell
|
|
96
|
+
$ . gabr
|
|
97
|
+
$ GABR_DEBUG_MODE=1 # we do not need to export this
|
|
98
|
+
$ gabr example human
|
|
99
|
+
```
|
|
102
100
|
|
|
103
101
|
## Variables
|
|
104
102
|
|
|
105
|
-
### Variables
|
|
106
103
|
### GABR_STRICT_MODE (default:true)
|
|
107
104
|
A variable called `GABR_STRICT_MODE` may be used to toggle the following snippet:
|
|
108
105
|
```bash
|
|
@@ -110,7 +107,7 @@ set -eEuo pipefail
|
|
|
110
107
|
local IFS=$'\n\t'
|
|
111
108
|
trap 'return $?' ERR SIGINT
|
|
112
109
|
```
|
|
113
|
-
This snippet will run once inside the
|
|
110
|
+
This snippet will run once inside the function's subshell clause.
|
|
114
111
|
Let's go over the three lines:
|
|
115
112
|
|
|
116
113
|
1)
|
|
@@ -133,7 +130,6 @@ To opt-out of strict-mode:
|
|
|
133
130
|
```shell
|
|
134
131
|
$ export GABR_STRICT_MODE=off
|
|
135
132
|
```
|
|
136
|
-
> export is not needed when running as a local function
|
|
137
133
|
|
|
138
134
|
### GABR_DEBUG_MODE
|
|
139
135
|
Setting this variable to a value will turn on debug mode for files and functions.
|
|
@@ -143,11 +139,11 @@ file source and function call.
|
|
|
143
139
|
$ export GABR_DEBUG_MODE=true
|
|
144
140
|
```
|
|
145
141
|
|
|
146
|
-
This variable is useful, because
|
|
142
|
+
This variable is useful, because just using `set -x` might also output `gabr`'s internal code.
|
|
147
143
|
|
|
148
|
-
### GABR_ROOT
|
|
144
|
+
### GABR_ROOT
|
|
149
145
|
If `GABR_ROOT` is set to a value the `gabr` function will change directory
|
|
150
|
-
to this
|
|
146
|
+
to this value on every invocation.
|
|
151
147
|
```shell
|
|
152
148
|
$ export GABR_ROOT=$(git rev-parse --show-toplevel)
|
|
153
149
|
```
|
|
@@ -158,35 +154,28 @@ in the same output. Keep in mind that the `gabr` function will lose it's flexibi
|
|
|
158
154
|
it will always run from a fixed location.
|
|
159
155
|
|
|
160
156
|
### GABR_DEFAULT
|
|
161
|
-
A global variable called `GABR_DEFAULT` may be used to influence the
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
A global variable called `GABR_DEFAULT` may be used to influence the exit condition.
|
|
158
|
+
`gabr` will exit it's internal loop when it finds a function it can call.
|
|
159
|
+
The argument `usage` always results in a function call and thus can be used as a means to exit.
|
|
160
|
+
A second option may be added by setting `GABR_DEFAULT` (global) or `default` (local) to a value.
|
|
164
161
|
|
|
165
162
|
```shell
|
|
166
163
|
$ export GABR_DEFAULT=index
|
|
167
164
|
```
|
|
168
|
-
> This will make `index.sh` behave similar to index-files in other programming languages
|
|
169
|
-
|
|
170
|
-
This variable is useful, but the default value `usage` is probably the way to go.
|
|
165
|
+
> This will make `index.sh` behave similar to index-files in other programming languages.
|
|
166
|
+
> But `usage` makes more sense for Bash IMO
|
|
171
167
|
|
|
172
168
|
### GABR_EXT
|
|
173
|
-
`GABR_EXT` may be used to alter the value of `ext`.
|
|
174
|
-
sourced, files without are ran with `exec
|
|
169
|
+
`GABR_EXT` may be used to alter the value of `ext`. The default value is `.sh`.
|
|
170
|
+
Files with this extension are sourced, files without are ran with `exec`.
|
|
175
171
|
|
|
176
172
|
```shell
|
|
177
173
|
$ export GABR_EXT=.bash
|
|
178
174
|
```
|
|
179
175
|
|
|
180
176
|
With the right shebang, any programming language can be called. However, keep in mind
|
|
181
|
-
that `gabr` also looks for files without
|
|
182
|
-
`exec`.
|
|
183
|
-
```shell
|
|
184
|
-
$ gabr example javascript hello
|
|
185
|
-
Arguments received: 3
|
|
186
|
-
0 -> .../node/v11.7.0/bin/node
|
|
187
|
-
1 -> .../gabr/example/javascript
|
|
188
|
-
2 -> hello
|
|
189
|
-
```
|
|
177
|
+
that `gabr` also looks for files without an extension. These files will always run with
|
|
178
|
+
`exec`.
|
|
190
179
|
|
|
191
180
|
### Local variables
|
|
192
181
|
Gabr defines the following local variables. These will be defined in sourced files.
|
|
@@ -205,9 +194,15 @@ Gabr defines the following local variables. These will be defined in sourced fil
|
|
|
205
194
|
| FUNCNEST | | See manual ([reference](https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html)) | 50 | Prohibits overly recursive function calls |
|
|
206
195
|
|
|
207
196
|
## Functions
|
|
197
|
+
A default function will be generated that prints usage information about `gabr` when:
|
|
198
|
+
|
|
199
|
+
- No argument are given
|
|
200
|
+
- The argument is `usage`
|
|
201
|
+
- The argument is the value of `GABR_DEFAULT` and `GABR_DEFAULT` is set
|
|
202
|
+
|
|
208
203
|
### function usage ()
|
|
209
|
-
By default `usage` is
|
|
210
|
-
like
|
|
204
|
+
By default `usage` is an important namespace for the `gabr` function. `usage` behaves
|
|
205
|
+
like an exit condition. The argument will always result in a function call, and thus
|
|
211
206
|
exit the interal loop. The following snippet shows the last-resort function that will be generated when a `usage` function or file is not available.
|
|
212
207
|
|
|
213
208
|
```bash
|
|
@@ -240,16 +235,16 @@ usage(){
|
|
|
240
235
|
}
|
|
241
236
|
```
|
|
242
237
|
|
|
243
|
-
Finally, a default file may be consulted when the
|
|
244
|
-
|
|
238
|
+
Finally, a default file may be consulted. This is applicable when the
|
|
239
|
+
argument is only a directory. For an example of this, see `./test/usage.sh`
|
|
245
240
|
or run `gabr test` to see it in action.
|
|
246
241
|
|
|
247
242
|
### function $default ()
|
|
248
|
-
The
|
|
243
|
+
The name of the `usage` function may be altered with `GABR_DEFAULT` or simply `default`.
|
|
249
244
|
A last-resort function and variable will be made for this name instead.
|
|
245
|
+
The usage namespace will keep functioning.
|
|
250
246
|
This is done through variable indirection. ([reference](https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html))
|
|
251
|
-
To generate a function with a dynamic name a small eval trick is used.
|
|
252
|
-
the `default` variable may not contain special-characters.
|
|
247
|
+
To generate a function with a dynamic name a small eval trick is used.
|
|
253
248
|
|
|
254
249
|
```bash
|
|
255
250
|
default=help
|
|
@@ -263,7 +258,7 @@ help(){
|
|
|
263
258
|
|
|
264
259
|
The internal loop wil error at any argument that starts with a dash (-).
|
|
265
260
|
Any argument that comes behind the dash will be printed as
|
|
266
|
-
a warning to the user.
|
|
267
|
-
```
|
|
261
|
+
a warning to the user. The return code will be 1.
|
|
262
|
+
```bash
|
|
268
263
|
set -- '-' 'Error, something went wrong'
|
|
269
264
|
```
|
package/bin/bats-exec-suite
CHANGED
|
@@ -40,7 +40,7 @@ elif [[ "$num_jobs" != 1 ]]; then
|
|
|
40
40
|
exit 1
|
|
41
41
|
fi
|
|
42
42
|
|
|
43
|
-
trap 'kill 0; exit 1'
|
|
43
|
+
trap 'kill 0; exit 1' INT
|
|
44
44
|
|
|
45
45
|
all_tests=()
|
|
46
46
|
for filename in "$@"; do
|
|
@@ -71,16 +71,18 @@ for filename in "$@"; do
|
|
|
71
71
|
fi
|
|
72
72
|
done
|
|
73
73
|
|
|
74
|
+
test_count="${#all_tests[@]}"
|
|
75
|
+
|
|
74
76
|
if [[ -n "$count_only_flag" ]]; then
|
|
75
|
-
printf '%d\n' "${
|
|
77
|
+
printf '%d\n' "${test_count}"
|
|
76
78
|
exit
|
|
77
79
|
fi
|
|
78
80
|
|
|
79
81
|
status=0
|
|
80
|
-
printf '1..%d\n' "${
|
|
82
|
+
printf '1..%d\n' "${test_count}"
|
|
81
83
|
|
|
82
84
|
# No point on continuing if there's no tests.
|
|
83
|
-
if [[ "${
|
|
85
|
+
if [[ "${test_count}" == 0 ]]; then
|
|
84
86
|
exit
|
|
85
87
|
fi
|
|
86
88
|
|
|
@@ -92,10 +94,19 @@ if [[ "$num_jobs" != 1 ]]; then
|
|
|
92
94
|
parallel -qk -j "$num_jobs" --colsep="\t" -- bats-exec-test "${flags[@]}" '{1}' '{2}' '{#}' || status=1
|
|
93
95
|
else
|
|
94
96
|
# Just do it serially.
|
|
95
|
-
test_number=
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
test_number=0
|
|
98
|
+
for test_line in "${all_tests[@]}"; do
|
|
99
|
+
# Only handle non-empty lines
|
|
100
|
+
if [[ $test_line ]]; then
|
|
101
|
+
filename="${test_line%%$'\t'*}"
|
|
102
|
+
test_name="${test_line##*$'\t'}"
|
|
103
|
+
((++test_number))
|
|
104
|
+
bats-exec-test "${flags[@]}" "$filename" "$test_name" "$test_number" || status=1
|
|
105
|
+
fi
|
|
106
|
+
done
|
|
107
|
+
if [[ "${test_number}" != "${test_count}" ]]; then
|
|
108
|
+
printf '# bats warning: Only executed %s of %s tests\n' "$test_number" "$test_count"
|
|
109
|
+
status=1
|
|
110
|
+
fi
|
|
100
111
|
fi
|
|
101
112
|
exit "$status"
|
package/bin/bats-exec-test
CHANGED
|
@@ -212,9 +212,13 @@ bats_trim_filename() {
|
|
|
212
212
|
|
|
213
213
|
bats_debug_trap() {
|
|
214
214
|
if [[ "$BASH_SOURCE" != "$1" ]]; then
|
|
215
|
+
# The last entry in the stack trace is not useful when en error occured:
|
|
216
|
+
# It is either duplicated (kinda correct) or has wrong line number (Bash < 4.4)
|
|
217
|
+
# Therefore we capture the stacktrace but use it only after the next debug
|
|
218
|
+
# trap fired.
|
|
219
|
+
# Expansion is required for empty arrays which otherwise error
|
|
220
|
+
BATS_CURRENT_STACK_TRACE=( "${BATS_STACK_TRACE[@]+"${BATS_STACK_TRACE[@]}"}" )
|
|
215
221
|
bats_capture_stack_trace
|
|
216
|
-
BATS_LINENO="$BATS_CURRENT_LINENO"
|
|
217
|
-
BATS_CURRENT_LINENO="${BASH_LINENO[0]}"
|
|
218
222
|
fi
|
|
219
223
|
}
|
|
220
224
|
|
|
@@ -223,10 +227,9 @@ bats_debug_trap() {
|
|
|
223
227
|
# set `$?` properly. See #72 and #81 for details.
|
|
224
228
|
#
|
|
225
229
|
# For this reason, we call `bats_error_trap` at the very beginning of
|
|
226
|
-
# `bats_teardown_trap` (the `DEBUG` trap for the call will
|
|
227
|
-
#
|
|
228
|
-
#
|
|
229
|
-
# status value if needed.
|
|
230
|
+
# `bats_teardown_trap` (the `DEBUG` trap for the call will fix the stack trace)
|
|
231
|
+
# and check the value of `$BATS_TEST_COMPLETED` before taking other actions.
|
|
232
|
+
# We also adjust the exit status value if needed.
|
|
230
233
|
#
|
|
231
234
|
# See `bats_exit_trap` for an additional EXIT error handling case when `$?`
|
|
232
235
|
# isn't set properly during `teardown()` errors.
|
|
@@ -237,8 +240,8 @@ bats_error_trap() {
|
|
|
237
240
|
if [[ "$BATS_ERROR_STATUS" -eq 0 ]]; then
|
|
238
241
|
BATS_ERROR_STATUS=1
|
|
239
242
|
fi
|
|
240
|
-
BATS_STACK_TRACE
|
|
241
|
-
trap -
|
|
243
|
+
BATS_STACK_TRACE=( "${BATS_CURRENT_STACK_TRACE[@]}" )
|
|
244
|
+
trap - DEBUG
|
|
242
245
|
fi
|
|
243
246
|
}
|
|
244
247
|
|
|
@@ -260,7 +263,7 @@ bats_exit_trap() {
|
|
|
260
263
|
local line
|
|
261
264
|
local status
|
|
262
265
|
local skipped=''
|
|
263
|
-
trap -
|
|
266
|
+
trap - ERR EXIT
|
|
264
267
|
|
|
265
268
|
if [[ -n "$BATS_TEST_SKIPPED" ]]; then
|
|
266
269
|
skipped=' # skip'
|
|
@@ -280,7 +283,7 @@ bats_exit_trap() {
|
|
|
280
283
|
# If instead the test fails, and the `teardown()` error happens while
|
|
281
284
|
# `bats_teardown_trap` runs as the EXIT trap, the test will fail with no
|
|
282
285
|
# output, since there's no way to reach the `bats_exit_trap` call.
|
|
283
|
-
BATS_STACK_TRACE
|
|
286
|
+
BATS_STACK_TRACE=( "${BATS_CURRENT_STACK_TRACE[@]}" )
|
|
284
287
|
BATS_ERROR_STATUS=1
|
|
285
288
|
fi
|
|
286
289
|
printf 'not ok %d %s\n' "$BATS_TEST_NUMBER" "$BATS_TEST_DESCRIPTION" >&3
|
|
@@ -301,6 +304,7 @@ bats_exit_trap() {
|
|
|
301
304
|
fi
|
|
302
305
|
|
|
303
306
|
rm -f "$BATS_OUT"
|
|
307
|
+
bats_cleanup_preprocessed_source
|
|
304
308
|
exit "$status"
|
|
305
309
|
}
|
|
306
310
|
|
|
@@ -317,23 +321,22 @@ bats_perform_test() {
|
|
|
317
321
|
# function when the ERR trap fires. All versions of Bash appear to reset it
|
|
318
322
|
# on an unbound variable access error. bats_debug_trap will fire both before
|
|
319
323
|
# the offending line is executed, and when the error is triggered.
|
|
320
|
-
# Consequently, we use `
|
|
324
|
+
# Consequently, we use `BATS_CURRENT_STACK_TRACE` recorded by the
|
|
321
325
|
# first call to bats_debug_trap, _before_ the ERR trap or unbound variable
|
|
322
326
|
# access fires.
|
|
323
|
-
BATS_CURRENT_LINENO=0
|
|
324
|
-
BATS_LINENO=0
|
|
325
327
|
BATS_STACK_TRACE=()
|
|
328
|
+
BATS_CURRENT_STACK_TRACE=()
|
|
326
329
|
|
|
327
330
|
BATS_TEST_COMPLETED=
|
|
328
331
|
BATS_TEST_SKIPPED=
|
|
329
332
|
BATS_TEARDOWN_COMPLETED=
|
|
330
333
|
BATS_ERROR_STATUS=
|
|
331
|
-
trap
|
|
332
|
-
trap 'bats_error_trap'
|
|
333
|
-
trap 'bats_teardown_trap'
|
|
334
|
+
trap 'bats_debug_trap "$BASH_SOURCE"' DEBUG
|
|
335
|
+
trap 'bats_error_trap' ERR
|
|
336
|
+
trap 'bats_teardown_trap' EXIT
|
|
334
337
|
"$BATS_TEST_NAME" >>"$BATS_OUT" 2>&1
|
|
335
338
|
BATS_TEST_COMPLETED=1
|
|
336
|
-
trap 'bats_exit_trap'
|
|
339
|
+
trap 'bats_exit_trap' EXIT
|
|
337
340
|
bats_teardown_trap
|
|
338
341
|
}
|
|
339
342
|
|
|
@@ -350,8 +353,8 @@ BATS_OUT="${BATS_TMPNAME}.out"
|
|
|
350
353
|
bats_preprocess_source() {
|
|
351
354
|
BATS_TEST_SOURCE="${BATS_TMPNAME}.src"
|
|
352
355
|
bats-preprocess "$BATS_TEST_FILENAME" >"$BATS_TEST_SOURCE"
|
|
353
|
-
trap 'bats_cleanup_preprocessed_source'
|
|
354
|
-
trap 'bats_cleanup_preprocessed_source; exit 1'
|
|
356
|
+
trap 'bats_cleanup_preprocessed_source' ERR EXIT
|
|
357
|
+
trap 'bats_cleanup_preprocessed_source; exit 1' INT
|
|
355
358
|
}
|
|
356
359
|
|
|
357
360
|
bats_cleanup_preprocessed_source() {
|
|
@@ -7,6 +7,7 @@ IFS= read -r header
|
|
|
7
7
|
if [[ "$header" =~ $header_pattern ]]; then
|
|
8
8
|
count="${header:3}"
|
|
9
9
|
index=0
|
|
10
|
+
passed=0
|
|
10
11
|
failures=0
|
|
11
12
|
skipped=0
|
|
12
13
|
name=
|
|
@@ -78,6 +79,11 @@ summary() {
|
|
|
78
79
|
buffer ', %d skipped' "$skipped"
|
|
79
80
|
fi
|
|
80
81
|
|
|
82
|
+
not_run=$((count - passed - failures - skipped))
|
|
83
|
+
if [[ "$not_run" -gt 0 ]]; then
|
|
84
|
+
buffer ', %d not run' "$not_run"
|
|
85
|
+
fi
|
|
86
|
+
|
|
81
87
|
buffer '\n'
|
|
82
88
|
}
|
|
83
89
|
|
|
@@ -158,6 +164,7 @@ while IFS= read -r line; do
|
|
|
158
164
|
((++skipped))
|
|
159
165
|
skip "${BASH_REMATCH[2]}"
|
|
160
166
|
else
|
|
167
|
+
((++passed))
|
|
161
168
|
pass
|
|
162
169
|
fi
|
|
163
170
|
;;
|
package/example/GIT.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# git.sh
|
|
2
2
|
|
|
3
|
-
Git.sh contains some one-off git functions. To serve as example.
|
|
3
|
+
Git.sh contains some one-off git functions. To serve as example and to help with maintanance on this repo.
|
|
4
4
|
|
|
5
|
+
* [pullSubmodules()](#pullSubmodules)
|
|
6
|
+
* [updateSubmodules()](#updateSubmodules)
|
|
5
7
|
* [currentBranch()](#currentBranch)
|
|
8
|
+
* [root()](#root)
|
|
6
9
|
* [deleteBranch()](#deleteBranch)
|
|
7
10
|
* [upstream()](#upstream)
|
|
8
11
|
* [deleteStale()](#deleteStale)
|
|
@@ -11,6 +14,26 @@
|
|
|
11
14
|
* [renameTag()](#renameTag)
|
|
12
15
|
|
|
13
16
|
|
|
17
|
+
## pullSubmodules()
|
|
18
|
+
|
|
19
|
+
Inits content of /modules
|
|
20
|
+
### Example
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
$ gabr example git pullSubmodules
|
|
24
|
+
master
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## updateSubmodules()
|
|
28
|
+
|
|
29
|
+
Updates content of /modules
|
|
30
|
+
### Example
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
$ gabr example git updateSubmodules
|
|
34
|
+
master
|
|
35
|
+
```
|
|
36
|
+
|
|
14
37
|
## currentBranch()
|
|
15
38
|
|
|
16
39
|
Gets the current branch
|
|
@@ -21,6 +44,16 @@ $ gabr example git currentBranch
|
|
|
21
44
|
master
|
|
22
45
|
```
|
|
23
46
|
|
|
47
|
+
## root()
|
|
48
|
+
|
|
49
|
+
Returns root of git repository
|
|
50
|
+
### Example
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
$ gabr example git root
|
|
54
|
+
~/Code/your/project
|
|
55
|
+
```
|
|
56
|
+
|
|
24
57
|
## deleteBranch()
|
|
25
58
|
|
|
26
59
|
Deletes a local branch
|
|
@@ -68,7 +101,6 @@ $ gabr example git deleteLocalBranch feature-branch
|
|
|
68
101
|
|
|
69
102
|
* string [ $1 | $branch ] to-delete-branch-name (default:current) -- e.g. feature-branch
|
|
70
103
|
* string [ $2 ] existing-checkout-branch (default:master) -- e.g. develop
|
|
71
|
-
* string [ $3 | $remote ] to-delete-remote (default:current) -- e.g. origin
|
|
72
104
|
|
|
73
105
|
## deleteTag()
|
|
74
106
|
|
|
@@ -89,7 +121,7 @@ Rename a tag
|
|
|
89
121
|
### Example
|
|
90
122
|
|
|
91
123
|
```bash
|
|
92
|
-
gabr example git
|
|
124
|
+
gabr example git renameTag some-feature
|
|
93
125
|
```
|
|
94
126
|
|
|
95
127
|
### Arguments
|
package/example/IFS.sh
ADDED
package/example/clang.c
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
#!/usr/bin/c
|
|
2
|
+
#include <stdio.h>
|
|
3
|
+
|
|
4
|
+
int main(int args, char *argv[]) {
|
|
5
|
+
printf("Arguments received: %d", args);
|
|
6
|
+
int i = 0;
|
|
7
|
+
for (i = 0; i < args; i++){
|
|
8
|
+
printf("\n%s", argv[i]);
|
|
9
|
+
}
|
|
10
|
+
printf("\n");
|
|
11
|
+
return 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* Sidenote:
|
|
15
|
+
for shebang support
|
|
16
|
+
https://github.com/ryanmjacobs/c
|
|
17
|
+
*/
|
package/example/git.sh
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
2
|
# @file git.sh
|
|
3
3
|
#
|
|
4
|
-
# @brief Git.sh contains some one-off git functions. To serve as example.
|
|
4
|
+
# @brief Git.sh contains some one-off git functions. To serve as example and to help with maintanance on this repo.
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
declare remote="$(git remote)"
|
|
11
|
-
fi
|
|
12
|
-
if [ -z "${branch:-}" ]; then
|
|
13
|
-
declare branch
|
|
14
|
-
branch="$(git symbolic-ref HEAD 2>/dev/null)" || branch="undefined"
|
|
15
|
-
branch=${branch##refs/heads/}
|
|
16
|
-
fi
|
|
6
|
+
declare remote="$(git remote)"
|
|
7
|
+
declare branch
|
|
8
|
+
branch="$(git symbolic-ref HEAD 2>/dev/null)" || branch="undefined"
|
|
9
|
+
branch=${branch##refs/heads/}
|
|
17
10
|
|
|
18
|
-
# @description
|
|
11
|
+
# @description Inits content of /modules
|
|
19
12
|
# @example
|
|
20
13
|
# $ gabr example git pullSubmodules
|
|
21
14
|
# master
|
|
@@ -23,6 +16,13 @@ function pullSubmodules() {
|
|
|
23
16
|
git submodule update --init --recursive
|
|
24
17
|
}
|
|
25
18
|
|
|
19
|
+
# @description Updates content of /modules
|
|
20
|
+
# @example
|
|
21
|
+
# $ gabr example git updateSubmodules
|
|
22
|
+
# master
|
|
23
|
+
function updateSubmodules() {
|
|
24
|
+
git submodule update --remote --merge
|
|
25
|
+
}
|
|
26
26
|
|
|
27
27
|
# @description Gets the current branch
|
|
28
28
|
# @example
|
|
@@ -36,7 +36,7 @@ function currentBranch() {
|
|
|
36
36
|
# @example
|
|
37
37
|
# $ gabr example git root
|
|
38
38
|
# ~/Code/your/project
|
|
39
|
-
function root(){
|
|
39
|
+
function root() {
|
|
40
40
|
command git rev-parse --show-toplevel;
|
|
41
41
|
}
|
|
42
42
|
|
|
@@ -72,18 +72,16 @@ function deleteStale() {
|
|
|
72
72
|
# $ gabr example git deleteLocalBranch feature-branch
|
|
73
73
|
# @arg string [ $1 | $branch ] to-delete-branch-name (default:current) -- e.g. feature-branch
|
|
74
74
|
# @arg string [ $2 ] existing-checkout-branch (default:master) -- e.g. develop
|
|
75
|
-
# @arg string [ $3 | $remote ] to-delete-remote (default:current) -- e.g. origin
|
|
76
75
|
function deleteBranch() {
|
|
77
76
|
local branch=${1:-$branch}
|
|
78
77
|
local checkout=${2:-master}
|
|
79
|
-
local remote=${3:-remote}
|
|
80
78
|
if [ "${checkout}" = "${branch}" ]; then
|
|
81
79
|
echo "Checkout branch may not be the same as deleted branch" 1>&2
|
|
82
80
|
return 1
|
|
83
81
|
fi
|
|
84
82
|
git checkout $checkout
|
|
85
83
|
git branch -d $branch || echo "Already deleted"
|
|
86
|
-
git push --delete $(git config --get remote.origin.url) $branch || echo "Already deleted"
|
|
84
|
+
git push --delete $(git config --get remote.origin.url) $branch || echo "Already deleted remote"
|
|
87
85
|
}
|
|
88
86
|
|
|
89
87
|
# @description Delete a remote branch
|
|
@@ -97,7 +95,7 @@ function deleteTag() {
|
|
|
97
95
|
|
|
98
96
|
# @description Rename a tag
|
|
99
97
|
# @example
|
|
100
|
-
# gabr example git
|
|
98
|
+
# gabr example git renameTag some-feature
|
|
101
99
|
# @arg $1 old version
|
|
102
100
|
# @arg $2 new version
|
|
103
101
|
function renameTag() {
|
package/example/npm.sh
CHANGED
|
@@ -1,15 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
if !
|
|
2
|
+
if ! command -v git >/dev/null; then
|
|
3
3
|
echo "Warning: git is not available" 1>&2
|
|
4
4
|
return 1
|
|
5
5
|
fi
|
|
6
|
-
if !
|
|
6
|
+
if ! command -v node >/dev/null; then
|
|
7
7
|
echo "Warning: node is not available" 1>&2
|
|
8
8
|
return 1
|
|
9
9
|
fi
|
|
10
10
|
declare npmRoot="$(git rev-parse --show-toplevel)"
|
|
11
|
-
declare
|
|
12
|
-
|
|
11
|
+
declare -a data=(
|
|
12
|
+
$(node -p -e "\
|
|
13
|
+
const data=require('${npmRoot}/package.json');
|
|
14
|
+
[
|
|
15
|
+
data.name,
|
|
16
|
+
data.version
|
|
17
|
+
].join('\n')
|
|
18
|
+
")
|
|
19
|
+
)
|
|
20
|
+
declare name=${data[0]}
|
|
21
|
+
declare version=${data[1]}
|
|
13
22
|
function release() { # [ message ] - Release with a message
|
|
14
23
|
cd $npmRoot
|
|
15
24
|
git add . || 'Nothing to add'
|
|
@@ -23,8 +32,8 @@ function deprecate() { # [version] -- deprecate a version
|
|
|
23
32
|
cd $npmRoot
|
|
24
33
|
if [[ $# -eq 0 ]]; then
|
|
25
34
|
echo "\
|
|
26
|
-
Usage: deprecate [version] [message] -- e.g. deprecate 0.0.2
|
|
27
|
-
-- \$1 string version number (default:current)
|
|
35
|
+
Usage: deprecate [version] [message] -- e.g. deprecate 0.0.2 \"This version is too old\"
|
|
36
|
+
-- \$1 string version number (default:current)
|
|
28
37
|
-- \$2 string reason of deprecation (default:'x.x.x is no longer supported')"
|
|
29
38
|
return
|
|
30
39
|
fi
|