Commit a50802c3 authored by Eric Myhre's avatar Eric Myhre

add dependency on frankban/quicktest.

Begin using it in some parts of testing of schema parse&compile.
(I don't think I'll try to push all usage of go-wish over to quicktest
in one flurry of diffs right now.  But it might be future work.)

The breaking point is that asserting on lists of errors using go-wish
was starting to exhibit Weird behaviors for only *some* error types.
It's likely that this would be addressable using some kind of go-cmp
customization, but go-wish doesn't really expose that ability.
The quicktest library does.

Switching to quicktest also brings a bunch of other nice features
along with it, like stack traces and other forms of additional info.
The holistic feel of it is also pretty similar to go-wish (particularly
since https://github.com/frankban/quicktest/pull/77 ), so many things
should be easy to switch.  I suspect I might want some more checker
functions to assert on types... but those should be easy to add as
a third party, either as a go-cmp.Transformer or a qt.Checker (and
then we can work on upstreaming at leisure, if appropriate).

In this commit, I'm handling the error list situation using a
go-cmp.Transformer to stringify all the errors.  This means that the
error *types* aren't checked, which is definitely loses ditches some
information... but the upside is that its easy to use the tests to
check that the eventual string of the error message is human-readable.
In this API, I think that readability is the higher priority.
parent d7980ca8
......@@ -37,3 +37,18 @@
[submodule ".gopath/src/github.com/warpfork/go-wish"]
path = .gopath/src/github.com/warpfork/go-wish
url = https://github.com/warpfork/go-wish
[submodule ".gopath/src/github.com/rogpeppe/go-internal"]
path = .gopath/src/github.com/rogpeppe/go-internal
url = https://github.com/rogpeppe/go-internal
[submodule ".gopath/src/github.com/frankban/quicktest"]
path = .gopath/src/github.com/frankban/quicktest
url = https://github.com/frankban/quicktest
[submodule ".gopath/src/github.com/kr/pretty"]
path = .gopath/src/github.com/kr/pretty
url = https://github.com/kr/pretty
[submodule ".gopath/src/github.com/kr/text"]
path = .gopath/src/github.com/kr/text
url = https://github.com/kr/text
[submodule ".gopath/src/github.com/google/go-cmp"]
path = .gopath/src/github.com/google/go-cmp
url = https://github.com/google/go-cmp
Subproject commit e7d1f0b53af1e9c9cf66924bc310190b1db8c339
Subproject commit 3a98a11b2c6d5ad66696f2954b3811f0244fb71d
Subproject commit a883a8422cd235c67c6c4fdcb7bbb022143e10b1
Subproject commit cafcf9720371e5625e7300397de921f58e069d17
Subproject commit dc4b49510d96256f881880b9802536a6a70edfcc
......@@ -3,6 +3,8 @@ module github.com/ipld/go-ipld-prime
go 1.14
require (
github.com/frankban/quicktest v1.11.3
github.com/google/go-cmp v0.5.4
github.com/ipfs/go-cid v0.0.4
github.com/minio/sha256-simd v0.1.1 // indirect
github.com/mr-tron/base58 v1.1.3 // indirect
......
github.com/frankban/quicktest v1.11.3 h1:8sXhOn0uLys67V8EsXLc6eszDs8VXWxL3iRvebPhedY=
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/ipfs/go-cid v0.0.4 h1:UlfXKrZx1DjZoBhQHmNHLC1fK1dUJDN20Y28A7s+gJ8=
github.com/ipfs/go-cid v0.0.4/go.mod h1:4LLaPOQwmk5z9LBgQnpkivrx8BJjUyGwTXCd5Xfj6+M=
github.com/jtolds/gls v4.20.0+incompatible h1:xdiiI2gbIgH/gLH7ADydsJ1uDOEzR8yvV7C0MuV77Wo=
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 h1:lYpkrQH5ajf0OXOcUbGjvZxxijuBwbbmlSxLiuofa+g=
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8RvIylQ358TN4wwqatJ8rNavkEINozVn9DtGI3dfQ=
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
......@@ -41,3 +50,5 @@ golang.org/x/sys v0.0.0-20200122134326-e047566fdf82 h1:ywK/j/KkyTHcdyYSZNXGjMwgm
golang.org/x/sys v0.0.0-20200122134326-e047566fdf82/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
......@@ -101,7 +101,7 @@ var rules = map[TypeKind][]rule{
alwaysApplies,
func(ts *TypeSystem, t Type) []error {
tRef := TypeReference(t.(*TypeMap).keyTypeRef)
if hasStringRepresentation(ts.types[tRef]) {
if !hasStringRepresentation(ts.types[tRef]) {
return []error{fmt.Errorf("type %q is not a string typekind nor representation with string kind", tRef)}
}
return nil
......
......@@ -5,6 +5,8 @@ import (
"strings"
"testing"
qt "github.com/frankban/quicktest"
"github.com/google/go-cmp/cmp"
"github.com/polydawn/refmt/json"
. "github.com/warpfork/go-wish"
......@@ -201,7 +203,7 @@ func testParse(t *testing.T, schemajson string, expectParseErr error, expectType
return nil
}
ts, typesystemErrs := dmt.Compile()
Require(t, typesystemErrs, ShouldEqual, expectTypesystemError)
qt.Assert(t, typesystemErrs, qt.CmpEquals(cmp.Transformer("asdf", func(e error) string { return e.Error() })), expectTypesystemError)
return ts
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment