testify icon indicating copy to clipboard operation
testify copied to clipboard

Add prefix and suffix assertions

Open georgelesica-wf opened this issue 7 years ago • 5 comments

I found myself wanting to make assertions about string and slice prefixes and suffixes so I thought these might make sense for others as well.

I modeled the new assertions off of the existing Contains assertion, but I am open to changing it if the maintainers have other preferences.

I also changed the code generation script a bit to try to make it pass reliably across all relevant Go versions. If these issues can be resolved some better way I'd be happy to revert my changes.

georgelesica-wf avatar Jul 09 '18 20:07 georgelesica-wf

So I'm not really sure why, but I can't get the generate script to run locally...

$ ./.travis.gogenerate.sh
2018/07/09 15:24:06 assertions.go:19:2: could not import github.com/davecgh/go-spew/spew (can't find import: "github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew")
exit status 1
assert/assertions.go:23: running "go": exit status 1
2018/07/09 15:24:06 assertions.go:19:2: could not import github.com/davecgh/go-spew/spew (can't find import: "github.com/stretchr/testify/vendor/github.com/davecgh/go-spew/spew")
exit status 1
require/forward_requirements.go:16: running "go": exit status 1
$ go version
go version go1.10 darwin/amd64

If I switch to using a source importer (importer.For("source", nil)) then it works on the newer versions, but fails on the older version (since that importer didn't exist). I see the same error on master as I do when running this branch with 1.10, for what it's worth.

georgelesica-wf avatar Jul 09 '18 21:07 georgelesica-wf

@ernesto-jimenez I can't seem to get the code generation to work in all versions of Go, even on master, any thoughts?

georgelesica-wf avatar Jul 10 '18 18:07 georgelesica-wf

+1 for this PR :)

hekonsek avatar Jul 11 '18 12:07 hekonsek

It looks like https://github.com/stretchr/testify/pull/620 will fix the build.

georgelesica-wf avatar Jul 12 '18 21:07 georgelesica-wf

Another +1 for this addition

systay avatar Apr 29 '19 09:04 systay