sorry if this is a duplicate, i had no idea what to search for...
my use case is more complex, but can be narrowed down to the following problem:
i want to run a bash script, which invokes all sorts of binaries, for example: grep. i want to assert that the binaries were invoked with the correct arguments. these assertions should be part of automated testing, i don't want to manually start checking things. this should go into ci cycle.
is there some standard way of doing this?
if not, i thought of moving all the binaries i wish to assert, replace them with a spy which first logs the arguments and then invokes the original binary and finally remove itself and return the original binary.
is this feasible? is there a better approach to the problem?
Just an idea, I didn't see this anywhere but:
Unless you're using full paths to invoke those binaries, you could create mocks of those libraries, e.g., in your projects
bin/
directory and make that directory be the first in your$PATH
.To mock
grep
, for example, you could do:A helper executable to increment counts:
A mock template (in bin/grep):