bats/helpers: Reset executable hash after stubbing #194
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
stub_program_in_path
now callshash
on the new stub to ensure it is discovered instead of the implementation it's intended to replace. Previously, ifstub_program_in_path
was invoked for a program that had already been executed by the test, the original program would still get invoked rather than the stub (unlesshash
was called orPATH
was updated elsewhere).Per the comments from the 'bats-helpers: {stub,restore}_program_in_path trigger Bash command rehash' test case:
restore_program_in_path
unconditionally updatesPATH
, which resets Bash's executable path hash table. I didn't realize this until callingstub_program_in_path
onrm
and finding that therm
stub was only found when it was the first in a series of programs to be stubbed. After some trial and error, I realized this was because thecreate_bats_test_script
call invokesrm
andstub_program_in_path
only modifiesPATH
on the first call.This isn't documented in the Bash man page, but once I figured out what was happening, my hypothesis was confirmed by: https://superuser.com/a/1000317