Repository navigation
test(plugin-contract): prove reload after unload (#34) #35
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # Negative fixture: the shipped fixture with the reload defect of | ||
| # z-shell/z-a-meta-plugins#54. Load defines its callback only when the name | ||
| # is free, and unload leaves the callback as an inert stub instead of removing | ||
| # it (as a plugin must when a manager can still dispatch to the name). The | ||
| # first load and repeated source are correct; after unload and a second load | ||
| # the stub survives, so the callback exists and returns 0 but does nothing. | ||
| () { | ||
| builtin emulate -L zsh | ||
| builtin setopt local_options typeset_silent | ||
|
|
||
| (( ${+parameters[_contract_fixture_active]} )) && return 0 | ||
|
|
||
| (( ${+functions[_contract_fixture_callback]} )) || _contract_fixture_callback() { | ||
| builtin emulate -L zsh | ||
| (( ${+parameters[_contract_fixture_effect]} )) && _contract_fixture_effect=ran | ||
| return 0 | ||
| } | ||
| typeset -g _contract_fixture_value=plugin | ||
|
|
||
| typeset -gi _contract_fixture_owned_hook=0 | ||
| if (( ${precmd_functions[(Ie)_contract_fixture_callback]:-0} == 0 )); then | ||
| precmd_functions+=(_contract_fixture_callback) | ||
| _contract_fixture_owned_hook=1 | ||
| fi | ||
|
|
||
| typeset -gi _contract_fixture_interactive=0 | ||
| if [[ -o interactive ]]; then | ||
| zle -N contract-fixture-widget _contract_fixture_callback | ||
| bindkey -N contract-fixture-map emacs | ||
| bindkey -M contract-fixture-map '^Xz' contract-fixture-widget | ||
| _contract_fixture_interactive=1 | ||
| fi | ||
|
|
||
| contract_fixture_plugin_unload() { | ||
| builtin emulate -L zsh | ||
| builtin setopt local_options typeset_silent | ||
|
|
||
| [[ ${_contract_fixture_value-} == plugin ]] && unset _contract_fixture_value | ||
| if (( _contract_fixture_owned_hook )); then | ||
| precmd_functions=(${precmd_functions:#_contract_fixture_callback}) | ||
| (( ${#precmd_functions} )) || unset precmd_functions | ||
| fi | ||
| if (( _contract_fixture_interactive )); then | ||
| bindkey -D contract-fixture-map | ||
| zle -D contract-fixture-widget | ||
| fi | ||
|
|
||
| # The defect: keep the name defined but inert. | ||
| functions[_contract_fixture_callback]='return 0' | ||
|
|
||
| unset _contract_fixture_active _contract_fixture_owned_hook | ||
| unset _contract_fixture_interactive | ||
| unfunction contract_fixture_plugin_unload | ||
| } | ||
|
|
||
| typeset -gi _contract_fixture_active=1 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| # Negative fixture: a plugin whose reloaded surface matches its first load | ||
| # while its callback no longer works. A one-time setup is guarded by a flag | ||
| # that unload forgets to clear, so a second load skips it. The setup's state | ||
| # lives under a name the contract observer excludes (`_zunit_*`), standing | ||
| # in for state no snapshot family covers, such as a file or a daemon. After | ||
| # unload and a second load the callback exists, returns 0 and is | ||
| # byte-identical, but its effect is gone, so only an effect check catches it. | ||
| () { | ||
| builtin emulate -L zsh | ||
| builtin setopt local_options typeset_silent | ||
|
|
||
| (( ${+parameters[_contract_fixture_active]} )) && return 0 | ||
|
|
||
| if (( ! ${+parameters[_zunit_reload_stale_setup_done]} )); then | ||
|
ss-o marked this conversation as resolved.
|
||
| typeset -g _zunit_reload_stale_ready=1 | ||
| typeset -gi _zunit_reload_stale_setup_done=1 | ||
| fi | ||
|
|
||
| _contract_fixture_callback() { | ||
| builtin emulate -L zsh | ||
| (( ${_zunit_reload_stale_ready:-0} )) || return 0 | ||
| (( ${+parameters[_contract_fixture_effect]} )) && _contract_fixture_effect=ran | ||
| return 0 | ||
| } | ||
|
|
||
| contract_fixture_plugin_unload() { | ||
| builtin emulate -L zsh | ||
| unset _zunit_reload_stale_ready | ||
| unfunction _contract_fixture_callback | ||
| # The defect: _zunit_reload_stale_setup_done is left set. | ||
| unset _contract_fixture_active | ||
| unfunction contract_fixture_plugin_unload | ||
| } | ||
|
|
||
| typeset -gi _contract_fixture_active=1 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.