Skip to content
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

test(bash): Add a bunch of tests for bash special characters. #25

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

JeffFaer
Copy link
Contributor

Right now, these tests fail. They will pass after spf13/cobra#2126 has been merged.

This PR is based on top of #24

testprog was failing with "cannot execute: required file not found".
Some Google sleuthing found that it was probably because libc6 was
missing.

Redhat has a similar error where it was complaining that glibc v2.32 was
missing. ubi8 only seemed to be able to install v2.28, but ubi9 runs
testprog without any other tweaks.

Signed-off-by: Jeffrey Faer <[email protected]>
@marckhouzam
Copy link
Owner

I’m trying to look into this one, but I’m having docker issues. Some update site is down right now. I’ll try again later on.

Copy link
Owner

@marckhouzam marckhouzam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've merged #24, so you can rebase this on the new main

@JeffFaer
Copy link
Contributor Author

JeffFaer commented Nov 8, 2024

I've merged #24, so you can rebase this on the new main

Done!

@marckhouzam
Copy link
Owner

@JeffFaer Could you sign-ff the two last commits, or else the DCO check fails.

completions = []string{"bear\tan animal", "bearpaw\ta dessert", "dog", "unicorn\tmythical"}
specialCharComps = []string{"at@", "equal=", "slash/", "colon:", "period.", "comma,", "letter"}
completions = []string{"bear\tan animal", "bearpaw\ta dessert", "dog", "unicorn\tmythical"}
completionsWithSpecialCharacters = []string{"bash space", "bash\\escape", "bash\\ escaped\\ space", "bash>redirect", "bash#comment", "bash$var", "bash|pipe", "bash;semicolon"}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is hard to test by hand because I cannot get the shell to finish the completion since they all have the same bash string right before the special character. Also, to avoid using double slashes, which I find confusing, can you use forward ticks as quotes?

So please change the above line to be:

completionsWithSpecialCharacters = []string{`bash1 space`, `bash2\escape`, `bash3\ escaped\ space`, `bash4>redirect`, `bash5#comment`, `bash6$var`, `bash7|pipe`, `bash8;semicolon`}

Then we can test by hand and do testprog prefix special-chars bash1[tab][tab]

_completionTests_verifyCompletion "testprog prefix special-chars bash#c" "bash#comment"
_completionTests_verifyCompletion "testprog prefix special-chars bash\$v" 'bash$var'
_completionTests_verifyCompletion "testprog prefix special-chars bash|p" "bash|pipe"
_completionTests_verifyCompletion "testprog prefix special-chars bash;s" "bash;semicolon"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not seem right as a result for the completion.
The idea is that if the completion choice is bash>redirect then it must appear on the shell as bash\>redirect.

Shell completions should not insert special shell characters but should instead escape them.
So, when doing testprog prefix special-chars bash|p[tab][tab], we should get testprog prefix special-chars bash\|pipe.
I'm not sure that is even possible to achieve with bash, but at least, if there is only one completion choice and it is bash|pipe, then testprog prefix special-chars ba[tab][tab] should complete to testprog prefix special-chars bash|pipe
Same goes for the other special chars except #, which seems to be passed to the program without needing to be espcaped.

A good way to see how the completions should behave is to compare them with zsh.

zsh
$ source <(testprog completion zsh)
$ testprog prefix special-chars bash4<TAB>

# becomes
$ testprog prefix special-chars bash4\>redirect

@@ -180,7 +180,7 @@ _completionTests_complete() {
COMP_CWORD=$((${#COMP_WORDS[@]}-1))
# We must check for a space as the last character which will tell us
# that the previous word is complete and the cursor is on the next word.
[ "${cmdLine: -1}" = " " ] && COMP_CWORD=${#COMP_WORDS[@]}
[ "${cmdLine: -1}" = " " ] && COMP_CWORD=${#COMP_WORDS[@]} && COMP_WORDS[COMP_CWORD]=''
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this?

_completionTests_verifyCompletion "testprog prefix special-chars bash\\e" "bash\\escape"
# TODO: completionTests_verifyCompletion doesn't support testing something
# like this.
#_completionTests_verifyCompletion "testprog prefix special-chars bash\\ e" "bash\\ escaped\\ space"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a test for the bash space case provided by the completion logic?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants