Skip to content

Commit

Permalink
Patch release 0.9.2
Browse files Browse the repository at this point in the history
Signed-off-by: Torsten Long <[email protected]>
  • Loading branch information
razziel89 committed Nov 7, 2024
1 parent f159e88 commit fd6f030
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 33 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test-lint-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ jobs:
chmod +x mdslw
sudo mv mdslw /usr/local/bin
env:
MDSLW_VERSION: 0.11.1
MDSLW_SHA256: 75a172e9d9a59793a4dbb5adb0e0dd0778171c6aa07188fc0733bb20c6889e1e
MDSLW_VERSION: 0.12.4
MDSLW_SHA256: 2899399d14c230f3bc3e4d8b275a1e7a61f061e65fc58e79a0ef1802c1c534bf
BASE_URL: "https://github.com/razziel89/mdslw/releases/download"

- uses: actions/checkout@v3
Expand Down
33 changes: 16 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,25 @@ check-dependencies:
command -v shellcheck &>/dev/null || (echo "ERROR, please install shellcheck" >&2; exit 1)
command -v shfmt &>/dev/null || (echo "ERROR, please install shfmt" >&2; exit 1)
command -v jq &>/dev/null || (echo "ERROR, please install jq" >&2; exit 1)
command -v kcov &>/dev/null || (echo "ERROR, please install kcov " >&2; exit 1)
command -v kcov &>/dev/null || (echo "ERROR, please install kcov" >&2; exit 1)
command -v mdslw &>/dev/null || (echo "ERROR, please install mdslw" >&2; exit 1)

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

.PHONY: lint
lint:
shellcheck ./bin/* ./lib/* ./tests/*
$(MAKE) check-format
shellcheck $(SHELLCHECK_OPTS) ./bin/* ./lib/* ./tests/*
shfmt --diff $(SHFMT_OPTS) --language-dialect bash ./bin/* ./lib/*
shfmt --diff $(SHFMT_OPTS) --language-dialect bats ./tests/*
mdslw --mode=check $(MDSLW_OPTS) .

format:
shfmt --write --simplify $(SHFMT_OPTS) --language-dialect bash ./bin/* ./lib/*
shfmt --write --simplify $(SHFMT_OPTS) --language-dialect bats ./tests/*
mdslw --mode=format --upstream="prettier --parser=markdown" .
shellcheck --format=diff $(SHELLCHECK_OPTS) bin/* lib/* tests/* | git apply --allow-empty

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

format:
shfmt -w -s -bn -i 2 -sr -ln bash ./bin/* ./lib/*
shfmt -w -s -bn -i 2 -sr -ln bats ./tests/*
mdslw --mode=format --upstream="prettier --parser=markdown" .
shellcheck --format=diff bin/* lib/* tests/* | git apply --allow-empty

check-format:
shfmt -d -s -bn -i 2 -sr -ln bash ./bin/* ./lib/*
shfmt -d -s -bn -i 2 -sr -ln bats ./tests/*
mdslw --mode=check --upstream="prettier --parser=markdown" .

build:
./generate_deployable.sh

Expand Down
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,20 @@ But we are eager to hear your feedback on how we could improve!
Shellmock is open-sourced under the Apache-2.0 license.
See the [LICENSE](./LICENSE) file for details.

> Copyright (c) 2022 - for information on the respective copyright owner
> see the NOTICE file or the repository
> https://github.com/boschresearch/shellmock
> Copyright (c) 2022 - for information on the respective copyright owner see the
> NOTICE file or the repository https://github.com/boschresearch/shellmock
>
> Licensed under the Apache License, Version 2.0 (the "License"); you may not
> use this file except in compliance with the License. You may obtain a copy of
> the License at
> use this file except in compliance with the License.
> You may obtain a copy of the License at
>
> http://www.apache.org/licenses/LICENSE-2.0
>
> Unless required by applicable law or agreed to in writing, software
> distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
> WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
> License for the specific language governing permissions and limitations under
> the License.
> WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
> See the License for the specific language governing permissions and
> limitations under the License.
<!---
Copyright (c) 2022 - for information on the respective copyright owner
Expand Down
6 changes: 4 additions & 2 deletions bin/mock_exe.sh
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ provide_output() {

run_hook() {
local cmd_spec="$1"
shift
local args=("$@")
# If a hook function was specified, run it. It has to be exported for this to
# work.
local hook_env_var
Expand All @@ -306,7 +308,7 @@ run_hook() {
&& [[ $(type -t "${!hook_env_var-}") == function ]]
then
# Run hook in sub-shell to reduce its influence on the mock.
if ! ("${!hook_env_var}"); then
if ! ("${!hook_env_var}" "${args[@]}"); then
# Not using errecho because we want this to always show up in the test's
# output. Anything output via errecho will end up in a file that is only
# looked at when asserting expectations.
Expand Down Expand Up @@ -388,7 +390,7 @@ main() {
forward "${cmd}" "$@"
else
provide_output "${cmd_spec}"
run_hook "${cmd_spec}"
run_hook "${cmd_spec}" "$@"
return_with_code "${cmd_spec}"
fi
}
Expand Down
3 changes: 1 addition & 2 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,7 @@ What happens in details:
That is, the mock has not been called with at least one set of arguments
that match a previous call to `shellmock config`.

Please have a look at the [full command reference](./usage.md) for all
details.
Please have a look at the [full command reference](./usage.md) for all details.
You can also have a look at [this detailed example](./example.md) or
[shellmock's own tests][shellmock-tests].
You may also check out our [how-to for creating tests](./howto.md).
Expand Down
5 changes: 3 additions & 2 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Any error calling the hook will be considered an error (also see
A hook can be used to perform additional assertions or record additional data.
Since the hook function is run in a sub-process, it cannot modify any shell
variables and has access only to environment variables.
The hook function receives all the arguments that the mock has been called with.

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

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

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

Expand Down
18 changes: 18 additions & 0 deletions tests/main.bats
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,24 @@ indices, cannot continue: 2 1"
run ! shellmock config my_exe 0 hook:_missing_hook
}

@test "hook matched on arguments and getting arguments" {
shellmock new my_exe
_hook_matched() {
echo "$*" > "${BATS_TEST_TMPDIR}/matched"
}
shellmock config my_exe 0 1:some-arg
shellmock config my_exe 0 hook:_hook_matched 1:another-arg

run -0 my_exe some-arg
[[ ! -s "${BATS_TEST_TMPDIR}/matched" ]]

run -0 my_exe another-arg
[[ -s "${BATS_TEST_TMPDIR}/matched" ]]
[[ $(cat "${BATS_TEST_TMPDIR}/matched") == another-arg ]]

shellmock assert expectations my_exe
}

@test "removing and re-creating a mock after creating one" {
# Not defined at first.
run ! my_exe
Expand Down

0 comments on commit fd6f030

Please sign in to comment.