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_pathnow callshashon the new stub to ensure it is discovered instead of the implementation it's intended to replace. Previously, ifstub_program_in_pathwas invoked for a program that had already been executed by the test, the original program would still get invoked rather than the stub (unlesshashwas called orPATHwas updated elsewhere).Per the comments from the 'bats-helpers: {stub,restore}_program_in_path trigger Bash command rehash' test case:
restore_program_in_pathunconditionally updatesPATH, which resets Bash's executable path hash table. I didn't realize this until callingstub_program_in_pathonrmand finding that thermstub 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_scriptcall invokesrmandstub_program_in_pathonly modifiesPATHon 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