Skip to content

Commit fd6f030

Browse files
committed
Patch release 0.9.2
Signed-off-by: Torsten Long <[email protected]>
1 parent f159e88 commit fd6f030

File tree

7 files changed

+51
-33
lines changed

7 files changed

+51
-33
lines changed

.github/workflows/test-lint-deploy.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ jobs:
9292
chmod +x mdslw
9393
sudo mv mdslw /usr/local/bin
9494
env:
95-
MDSLW_VERSION: 0.11.1
96-
MDSLW_SHA256: 75a172e9d9a59793a4dbb5adb0e0dd0778171c6aa07188fc0733bb20c6889e1e
95+
MDSLW_VERSION: 0.12.4
96+
MDSLW_SHA256: 2899399d14c230f3bc3e4d8b275a1e7a61f061e65fc58e79a0ef1802c1c534bf
9797
BASE_URL: "https://github.com/razziel89/mdslw/releases/download"
9898

9999
- uses: actions/checkout@v3

Makefile

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,25 @@ check-dependencies:
2929
command -v shellcheck &>/dev/null || (echo "ERROR, please install shellcheck" >&2; exit 1)
3030
command -v shfmt &>/dev/null || (echo "ERROR, please install shfmt" >&2; exit 1)
3131
command -v jq &>/dev/null || (echo "ERROR, please install jq" >&2; exit 1)
32-
command -v kcov &>/dev/null || (echo "ERROR, please install kcov " >&2; exit 1)
32+
command -v kcov &>/dev/null || (echo "ERROR, please install kcov" >&2; exit 1)
33+
command -v mdslw &>/dev/null || (echo "ERROR, please install mdslw" >&2; exit 1)
3334

34-
SHELLCHECK_OPTS := --enable=add-default-case,avoid-nullary-conditions,quote-safe-variables,require-variable-braces
35-
export SHELLCHECK_OPTS
35+
SHELLCHECK_OPTS := --external-sources --enable=add-default-case,avoid-nullary-conditions,quote-safe-variables,require-variable-braces
36+
SHFMT_OPTS := --space-redirects --binary-next-line --indent 2
37+
MDSLW_OPTS := --upstream="prettier --parser=markdown"
3638

3739
.PHONY: lint
3840
lint:
39-
shellcheck ./bin/* ./lib/* ./tests/*
40-
$(MAKE) check-format
41+
shellcheck $(SHELLCHECK_OPTS) ./bin/* ./lib/* ./tests/*
42+
shfmt --diff $(SHFMT_OPTS) --language-dialect bash ./bin/* ./lib/*
43+
shfmt --diff $(SHFMT_OPTS) --language-dialect bats ./tests/*
44+
mdslw --mode=check $(MDSLW_OPTS) .
45+
46+
format:
47+
shfmt --write --simplify $(SHFMT_OPTS) --language-dialect bash ./bin/* ./lib/*
48+
shfmt --write --simplify $(SHFMT_OPTS) --language-dialect bats ./tests/*
49+
mdslw --mode=format --upstream="prettier --parser=markdown" .
50+
shellcheck --format=diff $(SHELLCHECK_OPTS) bin/* lib/* tests/* | git apply --allow-empty
4151

4252
# Run tests under all possible combinations of some shell options.
4353
.PHONY: test
@@ -57,7 +67,7 @@ build-bash-version:
5767
# Ensure that the arguments have been set.
5868
[[ -n "$(BASH_VERSION)" && -n "$(BASH_PATH)" ]]
5969
cd "$(BASH_PATH)" && \
60-
curl -sSfL -o bash.tar.gz "$(DOWNLOAD_URL_PREFIX)/bash-$(BASH_VERSION).tar.gz" && \
70+
curl -fL -o bash.tar.gz "$(DOWNLOAD_URL_PREFIX)/bash-$(BASH_VERSION).tar.gz" && \
6171
tar -xvzf bash.tar.gz && \
6272
cd "bash-$(BASH_VERSION)" && \
6373
./configure && \
@@ -122,17 +132,6 @@ coverage: test
122132
} \
123133
}' < <(jq < $$(ls -d1 .coverage/bats.*/coverage.json) | sed 's/,$$//')
124134

125-
format:
126-
shfmt -w -s -bn -i 2 -sr -ln bash ./bin/* ./lib/*
127-
shfmt -w -s -bn -i 2 -sr -ln bats ./tests/*
128-
mdslw --mode=format --upstream="prettier --parser=markdown" .
129-
shellcheck --format=diff bin/* lib/* tests/* | git apply --allow-empty
130-
131-
check-format:
132-
shfmt -d -s -bn -i 2 -sr -ln bash ./bin/* ./lib/*
133-
shfmt -d -s -bn -i 2 -sr -ln bats ./tests/*
134-
mdslw --mode=check --upstream="prettier --parser=markdown" .
135-
136135
build:
137136
./generate_deployable.sh
138137

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,20 @@ But we are eager to hear your feedback on how we could improve!
127127
Shellmock is open-sourced under the Apache-2.0 license.
128128
See the [LICENSE](./LICENSE) file for details.
129129

130-
> Copyright (c) 2022 - for information on the respective copyright owner
131-
> see the NOTICE file or the repository
132-
> https://github.com/boschresearch/shellmock
130+
> Copyright (c) 2022 - for information on the respective copyright owner see the
131+
> NOTICE file or the repository https://github.com/boschresearch/shellmock
133132
>
134133
> Licensed under the Apache License, Version 2.0 (the "License"); you may not
135-
> use this file except in compliance with the License. You may obtain a copy of
136-
> the License at
134+
> use this file except in compliance with the License.
135+
> You may obtain a copy of the License at
137136
>
138137
> http://www.apache.org/licenses/LICENSE-2.0
139138
>
140139
> Unless required by applicable law or agreed to in writing, software
141140
> distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
142-
> WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
143-
> License for the specific language governing permissions and limitations under
144-
> the License.
141+
> WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
142+
> See the License for the specific language governing permissions and
143+
> limitations under the License.
145144
146145
<!---
147146
Copyright (c) 2022 - for information on the respective copyright owner

bin/mock_exe.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ provide_output() {
297297

298298
run_hook() {
299299
local cmd_spec="$1"
300+
shift
301+
local args=("$@")
300302
# If a hook function was specified, run it. It has to be exported for this to
301303
# work.
302304
local hook_env_var
@@ -306,7 +308,7 @@ run_hook() {
306308
&& [[ $(type -t "${!hook_env_var-}") == function ]]
307309
then
308310
# Run hook in sub-shell to reduce its influence on the mock.
309-
if ! ("${!hook_env_var}"); then
311+
if ! ("${!hook_env_var}" "${args[@]}"); then
310312
# Not using errecho because we want this to always show up in the test's
311313
# output. Anything output via errecho will end up in a file that is only
312314
# looked at when asserting expectations.
@@ -388,7 +390,7 @@ main() {
388390
forward "${cmd}" "$@"
389391
else
390392
provide_output "${cmd_spec}"
391-
run_hook "${cmd_spec}"
393+
run_hook "${cmd_spec}" "$@"
392394
return_with_code "${cmd_spec}"
393395
fi
394396
}

docs/quickstart.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ What happens in details:
9797
That is, the mock has not been called with at least one set of arguments
9898
that match a previous call to `shellmock config`.
9999

100-
Please have a look at the [full command reference](./usage.md) for all
101-
details.
100+
Please have a look at the [full command reference](./usage.md) for all details.
102101
You can also have a look at [this detailed example](./example.md) or
103102
[shellmock's own tests][shellmock-tests].
104103
You may also check out our [how-to for creating tests](./howto.md).

docs/usage.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Any error calling the hook will be considered an error (also see
146146
A hook can be used to perform additional assertions or record additional data.
147147
Since the hook function is run in a sub-process, it cannot modify any shell
148148
variables and has access only to environment variables.
149+
The hook function receives all the arguments that the mock has been called with.
149150

150151
Every following argument to the `config` command is a so-called `argspec` (see
151152
below).
@@ -412,8 +413,8 @@ There are three recommended ways for defining multi-line output, namely
412413

413414
- adding literal line breaks to the string, or
414415
- using a here-document, or
415-
- [having bash interpret escape sequences][bash-ansi-escape] using a
416-
character sequence of the form `$'string'`.
416+
- [having bash interpret escape sequences][bash-ansi-escape] using a character
417+
sequence of the form `$'string'`.
417418

418419
[bash-ansi-escape]: https://www.gnu.org/software/bash/manual/html_node/ANSI_002dC-Quoting.html#ANSI_002dC-Quoting
419420

tests/main.bats

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,24 @@ indices, cannot continue: 2 1"
541541
run ! shellmock config my_exe 0 hook:_missing_hook
542542
}
543543

544+
@test "hook matched on arguments and getting arguments" {
545+
shellmock new my_exe
546+
_hook_matched() {
547+
echo "$*" > "${BATS_TEST_TMPDIR}/matched"
548+
}
549+
shellmock config my_exe 0 1:some-arg
550+
shellmock config my_exe 0 hook:_hook_matched 1:another-arg
551+
552+
run -0 my_exe some-arg
553+
[[ ! -s "${BATS_TEST_TMPDIR}/matched" ]]
554+
555+
run -0 my_exe another-arg
556+
[[ -s "${BATS_TEST_TMPDIR}/matched" ]]
557+
[[ $(cat "${BATS_TEST_TMPDIR}/matched") == another-arg ]]
558+
559+
shellmock assert expectations my_exe
560+
}
561+
544562
@test "removing and re-creating a mock after creating one" {
545563
# Not defined at first.
546564
run ! my_exe

0 commit comments

Comments
 (0)