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
When I attempt to run a test with a stub, the test runner gets stuck without throwing an error. It must be exited with CTRL + C
$ find -type f | entr ./node_modules/bats/bin/bats -r ./helpers/tests
✓ a/b matcher to ensure the asserts are working
✓ createConfigFile
✓ toLowercase
gatherConfigOptions 4/4
I need to stub read to allow automated testing to work. But this code is causing the halt:
# tests.bats
load "batsMock/stub" # saved via git submodule into this folder
@test "gatherConfigOptions" {
# setup
stub read \
"echo 'returnValue1'" \
"echo 'returnValue2'"
# test execution & assert
local options=$(gatherConfigOptions)
assert_equal $options "wrongValue"
# teardown
unstub read
}
Also tried
Commenting out the unstub statement. No effect
I suspect that read is running unstubbed and causing the infinite delay. I could be wrong though.
Anyone able to tell what the issue is and how to overcome it?
Here is the function I am attempting to stub the internals of:
# ./helpers/helpers.sh
function gatherConfigOptions {
declare -A configData
read -p "prompt text here" "configData[languageCode]"
read -p "prompt text here" "configData[numberOfRepeats]"
echo "${configData[*]}"
}
The text was updated successfully, but these errors were encountered:
read is a shell builtin, so the builtin will always take priority over a disk command. Recall that bats-mock works by making an executable shim on disk, which is placed first in PATH, thereby "shadowing" other disk commands.
Because shell builtins take precedence over disk commands, the read builtin will never be shadowed by the bats-mock shims. 😞
However! the enable builtin allows you to disable shell builtins. 🎉
Disabling allows you to execute a disk command which has the same name as a shell builtin without using a full pathname.
See the enable man page with help enable. I can't vouch for whether it will work within a bats test, though, because the bats run command executes things in a subshell, IIRC. And I'm not certain if enable affects subshells or not. But it's worth a try, and I'd love to hear if it works for you (or not).
Just a note to say that I attempted this in my own tests and it didn't work. If someone else tries and figures out a way to make it work, please update here.
When I attempt to run a test with a stub, the test runner gets stuck without throwing an error. It must be exited with
CTRL + C
I need to stub
read
to allow automated testing to work. But this code is causing the halt:Also tried
unstub
statement. No effectI suspect that
read
is running unstubbed and causing the infinite delay. I could be wrong though.Anyone able to tell what the issue is and how to overcome it?
Here is the function I am attempting to stub the internals of:
The text was updated successfully, but these errors were encountered: