You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bats-mock fails if optional arguments to getter or setter functions are omitted and the expansion of unset variables / parameters is not allowed (that is, when set -u is used).
Some people are using set -euo pipefail in scripts to enforce a clean coding style. Sourcing such a script for testing may break tests using bats-mock.
How to reproduce:
#!/usr/bin/env bats
load bats-mock/src/bats-mock
setup() {
mock="$(mock_create)""${mock}"
}
@test "mock_get_call_args() with omitted optional argument succeeds when expansion of unset arguments is allowed" {
set +u
run mock_get_call_args "${mock}"
[[ "${status}"-eq 0 ]]
}
@test "mock_get_call_args() with omitted optional argument fails with unbound variable error when expansion of unset arguments is not allowed" {
set -u
run mock_get_call_args "${mock}"
[[ "${status}"-ne 0 ]]
[[ "${output}"=~'/bats-mock.bash: line '[0-9]*': $2: unbound variable' ]]
}
bats-mock fails if optional arguments to getter or setter functions are omitted and the expansion of unset variables / parameters is not allowed (that is, when
set -u
is used).Some people are using
set -euo pipefail
in scripts to enforce a clean coding style. Sourcing such a script for testing may break tests using bats-mock.How to reproduce:
Workaround:
Instead of
use
Possible Solution:
Use
${2-}
instead of$2
(provided$2
is optional).Example (from
mock_get_call_args
):The text was updated successfully, but these errors were encountered: