-
Notifications
You must be signed in to change notification settings - Fork 19
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
Enable regular expression for stdout, stderr assertion #177
Comments
I've put a bit of thought into this and I agree the feature is nice. I can't quite decide on how to go about implementing it. I'm struggling with what users would expect the api to be. We currently have the following: exactecho test:
stdout:
exactly: test This seems to be pretty cut and dry and should remain as it is. There is a possibility to add regex capability here, but I personally think this should not be touched. containsecho hello world:
stdout: hello # Default is a contains assertion
echo more output:
stdout:
contains:
- more
- output We could simply change the contains matcher logic over to regex. For example the following holds package main
import (
"fmt"
"regexp"
)
func main() {
r, _ := regexp.Compile("1")
fmt.Println(r.MatchString("There is 1 dog? jello"))
}
output: true linesecho test\nline 2:
stdout:
lines:
2: line 2 # asserts only the second line
package main
import (
"fmt"
"regexp"
)
func main() {
r, err := regexp.Compile("There is 1 dog?")
fmt.Println(err)
fmt.Println(r.MatchString("There is 1 dog? gello"))
} In order to provide the same functionality we would need to prepend and append the beginning ( I'm not sure if I'm missing anything here. I'm not the greatest with regex, but with a bit of research I think the following would do fine. My main concern with the above is really the discoverability of this feature... Also a bit of logic but eh on the surface it seem pretty straightforward and really increase complexity. Solution 2Simply echo test:
stdout:
regex: test 😄 ... This of course wouldn't support line by line assertions. We could, but I think that would fall into a bigger issue like "Support line assertions per matcher type". @SimonBaeumer let me know what you think. |
@dylanhitt Changing the current behaviour to support regexes is not possible without breaking it as you pointed already out. We could also provide custom bash/awk verifier to execute custom code which fails if the status code is 1 and succeeds on 0. |
I agree a separate directive is the best approach. How do you feel about pushing the lines to a separate issue? I think we could support it for every type of assertion without adding too much complexity. |
Prerequisites
Description
I think it would be nice if we can use regular expression in stdout and stderr assertion, for example:
Specifications
The text was updated successfully, but these errors were encountered: