Comments (3)
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:
exact
echo 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.
contains
echo 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 true
. (I don't believe this would cause any breaking changes but someone chime in if I'm missing one, my regex understanding is rough 😅 ).
package main
import (
"fmt"
"regexp"
)
func main() {
r, _ := regexp.Compile("1")
fmt.Println(r.MatchString("There is 1 dog? jello"))
}
output: true
lines
echo test\nline 2:
stdout:
lines:
2: line 2 # asserts only the second line
lines
is currently an exact match so we'd need to be careful with how this is implemented. We could simple switch the matcher over to regex matcher but this however would create a different behavior. For example the following example would validate as true
where commander currently validates it as false
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 (^
) and ending ($
) anchors to lines before we validate. If the user is verbose with their regex and submit something like 1: ^There is 1 dog?$
we simply don't add the anchors.
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 2
Simply
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.
from commander.
@dylanhitt Changing the current behaviour to support regexes is not possible without breaking it as you pointed already out.
Imho solution 2 sounds reasonable, so adding a regex
and regexLines
to support a regex over the whole and result and over a specific line.
We could also provide custom bash/awk verifier to execute custom code which fails if the status code is 1 and succeeds on 0.
from commander.
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.
from commander.
Related Issues (20)
- "Test may not be filtered when --dir is enabled" HOT 5
- Test Suite aggregation should occur in runtime HOT 2
- Create a custom GitHub action for Commander HOT 1
- Properly mock file and dirs in app tests to not read from the filesystem
- config value dir, should work for file assertion
- user should be able to set the working dir with `--workdir` HOT 1
- Add junit ouput support HOT 1
- Move away from travisCI HOT 5
- Add yaml linter in CI
- documented install command fails with go 1.16 HOT 5
- Upgrade docker version
- Change []runtime.TestCase in Suite to an array of pointers
- Unable to run docker via kind cluster HOT 11
- SSH public key authentication broken in commander 2.4.0 on CentOS 8.4.2105 HOT 1
- Add proper error handling and coroutine cancellation
- Rename TestCommandContext to TestCommandConfig
- Support bash and awk verifiers HOT 1
- Commands in Installation section try to download non-existing version HOT 1
- dotfiles in test dir cause a panic HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from commander.