-
Notifications
You must be signed in to change notification settings - Fork 78
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
testscript: Accept !cmd (without space) or provide better error #190
Comments
I hit this as well and I think treating it as ! cmd is the right solution. Why would someone name a binary starting with a ! (which is special in shell as well) |
did same typo with !stderr also so I really think the not should work without needing a space |
Giving a better error message seems fine to me. I wouldn't want to change the syntax to allow Personally I'd say that erroring on any command with a Happy to review a PR :) |
I think I'll try my hand at a general spelling-correction to improve the error message (which should cover this case as well). If I can't manage that, I'll send a PR to detect |
If a command is not found, we go through the list of defined commands and check if any of them are sufficiently close to the one used. "Sufficiently close" is defined by having a Damerau-Levenshtein distance of 1, which feels like it hits the sweet spot between usefulness and ease of implementation. The negation case is still special-cased, as negation is not in the set of defined commands. Fixes rogpeppe#190
If a command is not found, we go through the list of defined commands and check if any of them are sufficiently close to the one used. "Sufficiently close" is defined by having a Damerau-Levenshtein distance of 1, which feels like it hits the sweet spot between usefulness and ease of implementation. The negation case is still special-cased, as negation is not in the set of defined commands. Fixes rogpeppe#190
If a command is not found, we go through the list of defined commands and check if any of them are sufficiently close to the one used. "Sufficiently close" is defined by having a Damerau-Levenshtein distance of 1, which feels like it hits the sweet spot between usefulness and ease of implementation. The negation case is still special-cased, as negation is not in the set of defined commands. Fixes rogpeppe#190
curious btw
what upstream are you referring to ? also noticed by the way that lines like
aren't
|
Currently https://github.com/golang/go/blob/master/src/cmd/go/script_test.go. testscript was started as a copy of that code while being refactored as a library. See all the testscripts upstream has, where the syntax is still very similar. |
If a command is not found, we go through the list of defined commands and check if any of them are sufficiently close to the one used. "Sufficiently close" is defined by having a Damerau-Levenshtein distance of 1, which feels like it hits the sweet spot between usefulness and ease of implementation. The negation case is still special-cased, as negation is not in the set of defined commands. Fixes rogpeppe#190
If a command is not found, we go through the list of defined commands and check if any of them are sufficiently close to the one used. "Sufficiently close" is defined by having a Damerau-Levenshtein distance of 1, which feels like it hits the sweet spot between usefulness and ease of implementation. The negation case is still special-cased, as negation is not in the set of defined commands. Fixes rogpeppe#190
If a command is not found, we go through the list of defined commands and check if any of them are sufficiently close to the one used. "Sufficiently close" is defined by having a Damerau-Levenshtein distance of 1, which feels like it hits the sweet spot between usefulness and ease of implementation. The negation case is still special-cased, as negation is not in the set of defined commands. Fixes rogpeppe#190
If a command is not found, we go through the list of defined commands and check if any of them are sufficiently close to the one used. "Sufficiently close" is defined by having a Damerau-Levenshtein distance of 1, which feels like it hits the sweet spot between usefulness and ease of implementation. The negation case is still special-cased, as negation is not in the set of defined commands. Fixes rogpeppe#190
If a command is not found, we go through the list of defined commands and check if any of them are sufficiently close to the one used. "Sufficiently close" is defined by having a Damerau-Levenshtein distance of 1, which feels like it hits the sweet spot between usefulness and ease of implementation. The negation case is still special-cased, as negation is not in the set of defined commands. Fixes #190
Hi @Merovius, just wanted to say a quick thanks for doing this! I hit this just yesterday, and the time between making the mistake to then smacking my head once I realized the mistake was longer than I would care to admit 😅 |
A colleague is trying out
testscript
and used!cmd
to call a custom command (note the lack of space). They got the error message "!cmd
not defined" and where confused why the negation was not recognized. I'd like to improve that.One option would be to accept the
!cmd
, parsing it as equivalent to! cmd
. This is easy to implement, but probably not backwards compatible.Another option is to provide a better error message if a command is not found. e.g. if
!cmd
is looked up and not found, butcmd
is, we could detect that and report "did you mean! cmd
?". Or - harder to implement, but more generally useful - we could search the defined commands by edit-distance to the missed command and if one of them is a close enough match, suggest that. x/tools has an internal package that might help.I can send a PR, but wanted to discuss what option you prefer.
The text was updated successfully, but these errors were encountered: