sstephenson / bats

Bash Automated Testing System
MIT License
7.12k stars 517 forks source link

Stubbing out built-in #155

Open CaptainQuirk opened 8 years ago

CaptainQuirk commented 8 years ago

Hi there,

Following on #38, I'm having an issue trying to stub out the type bash builtin.

I made a simple function around it to check if an executable is available on my system.

Before that, I was using the following construct

    env type "${1}" > /dev/null 2>&1

This allowed me to actually make my stubbed type function get priority over the built-in. I could then define a dummy stub that would exit with 1 or 0, depending on my case. Unfortunately, this construct fails because it stops at my environment and doesn't fall back, so to speak, to the bash built-in if no env type function is found.

Now, maybe I am trying to test something untestable ... My goal was to make sure that my is_installed function would return the result of the type call and that my program would in the appropriaté manner if a dependency was missing.

What do you think ?

Thanks in advance !

netj commented 8 years ago

Not clear what you're trying to do but just a few comments: