-
Notifications
You must be signed in to change notification settings - Fork 25
Extend stub_command to functions #92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
it allows to stub the assert function and get an expected result it is useful to test assert result when used in a function body (eq. in a matcher body) Signed-off-by: Eric Villard <dev@eviweb.fr>
Signed-off-by: Eric Villard <dev@eviweb.fr>
|
Perhaps this is more useful as added functionality to While it would still be possible to override |
Signed-off-by: Eric Villard <dev@eviweb.fr>
for the second time... :( Signed-off-by: Eric Villard <dev@eviweb.fr>
Signed-off-by: Eric Villard <dev@eviweb.fr>
|
@rylnd, you're right and it's done. best regards |
|
@rylnd, Eric |
|
@eviweb what is the status of this PR? |
|
hi @rylnd, |
|
@rylnd, |
rylnd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eviweb thanks again for your work; sorry for taking so long to get back to this.
|
|
||
| stub_command() { | ||
| local func_decl="$(get_function_declaration "$1")" | ||
| [ -n "${func_decl}" ] && eval "_shpec____${func_decl}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we ever unset this internal definition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Local vars do not need to be unset as they are local but KSH does not support the local keyword, I corrected that in another pending branch...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not referring to func_decl, I'm referring to the function that is evald here. After calling stub_command foo; unstub_command foo there will be still be a _shpec___foo function in the namespace, correct?
| get_function_declaration() | ||
| { | ||
| if [ "${SHELL}" = "dash" ]; then | ||
| type "$1" | tail -n +2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might be misunderstanding this: I thought that everything except for dash can use type; this seems to indicate the opposite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the discussion in #89, dash's own docs, and our previous conversation, I'm fine keeping use of the (non-POSIX) type and typeset commands. If this becomes a problem, we can revisit (or move this feature to a plugin).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what I explained in my last comment #92 (comment), Unfortunately there's currently no way I see to retrieve the body of a function under Dash 😞
| unstub_command "curl" | ||
| end | ||
|
|
||
| it "prevents loosing stubbed function" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/loosing/losing please!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be done if we can find a solution for the problem mentioned here #92 (comment)
|
@rylnd, |
|
@eviweb my mistake; I thought I had seen @hlangeveld you had done some research for #89 into how to obtain a command's type with various POSIX(ish) builtins; are you aware of any way to obtain the function declaration in dash? If not, then we either drop dash support or we move this work to a plugin. I will give #108 some thought; I would love to hear others' thoughts/ideas there as well. |
Hi,
here is a little enhancement that provides a way to stub the shpec assert function.
It is useful to check its behaviour when it is nested in a function body, like in a matcher for example.
Best regards
Eric