diff --git a/CHANGELOG.md b/CHANGELOG.md index aec50cb..af1435a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,15 @@ Most recent version is listed first. # v0.0.7 -- update to Go 1.20: https://github.com/komuw/kama/pull/34 +- Update to Go 1.20: https://github.com/komuw/kama/pull/34 +- Better formatting for zero-length slices and maps: https://github.com/komuw/kama/pull/36 # v0.0.6 -- update dependencies: https://github.com/komuw/kama/pull/32 -- update to Go 1.19: https://github.com/komuw/kama/pull/33 +- Update dependencies: https://github.com/komuw/kama/pull/32 +- Update to Go 1.19: https://github.com/komuw/kama/pull/33 ## v0.0.5 -- check if terminal supports color before printing stack traces: https://github.com/komuw/kama/pull/31 +- Check if terminal supports color before printing stack traces: https://github.com/komuw/kama/pull/31 ## v0.0.4 - Add ability to print stack traces: https://github.com/komuw/kama/pull/29 @@ -31,10 +32,10 @@ Most recent version is listed first. arrays/slices/maps that are inside structs. ## v0.0.2 -- add test example: https://github.com/komuw/kama/pull/13 -- add types to the fields of a struct: https://github.com/komuw/kama/pull/16 +- Add test example: https://github.com/komuw/kama/pull/13 +- Add types to the fields of a struct: https://github.com/komuw/kama/pull/16 ## v0.0.1 -- pretty print variables and packages: https://github.com/komuw/kama/pull/10 -- add cli: https://github.com/komuw/kama/pull/11 -- add pretty printing for data structures: https://github.com/komuw/kama/pull/12 +- Pretty print variables and packages: https://github.com/komuw/kama/pull/10 +- Add cli: https://github.com/komuw/kama/pull/11 +- Add pretty printing for data structures: https://github.com/komuw/kama/pull/12 diff --git a/dump.go b/dump.go index a315583..0ee7e3f 100644 --- a/dump.go +++ b/dump.go @@ -173,6 +173,10 @@ func dumpSlice(v reflect.Value, hideZeroValues bool, indentLevel int) string { typeName := v.Type().String() newline := "\n" + if numEntries <= 0 { + // do not use newline. + newline = "" + } leftSep := " " s := typeName + "{" + newline @@ -184,7 +188,11 @@ func dumpSlice(v reflect.Value, hideZeroValues bool, indentLevel int) string { remainder := numEntries - constraint s = s + fmt.Sprintf(" ...<%d more redacted>..", remainder) } - s = s + "}" + if v.IsZero() { + s = s + "(nil)}" + } else { + s = s + "}" + } return s } @@ -227,7 +235,11 @@ func dumpMap(v reflect.Value, hideZeroValues bool, indentLevel int) string { } s = strings.TrimRight(s, ",\n") // maybe use `strings.TrimSuffix` - s = s + "}" + if v.IsZero() { + s = s + "(nil)}" + } else { + s = s + "}" + } return s } diff --git a/go.mod b/go.mod index bacb872..123b1d9 100644 --- a/go.mod +++ b/go.mod @@ -3,20 +3,20 @@ module github.com/komuw/kama go 1.20 require ( - golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 - golang.org/x/tools v0.1.12 + golang.org/x/sys v0.5.0 + golang.org/x/tools v0.6.0 ) require ( - github.com/google/go-cmp v0.5.8 // indirect - github.com/kr/pretty v0.3.0 // indirect + github.com/google/go-cmp v0.5.9 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/kr/text v0.2.0 // indirect github.com/rogpeppe/go-internal v1.9.0 // indirect - golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect + golang.org/x/mod v0.8.0 // indirect ) require ( - github.com/frankban/quicktest v1.14.3 // test + github.com/frankban/quicktest v1.14.4 // test github.com/pkg/errors v0.9.1 // test - go.uber.org/goleak v1.1.12 // test + go.uber.org/goleak v1.2.1 // test ) diff --git a/go.sum b/go.sum index df9f7a5..1bada14 100644 --- a/go.sum +++ b/go.sum @@ -1,66 +1,27 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= -github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= -github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= -github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= -github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg= -github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= -github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= -github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= -github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY= +github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0= +github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.uber.org/goleak v1.1.12 h1:gZAh5/EyT/HQwlpkCy6wTpqfH9H8Lz8zbm3dZh+OyzA= -go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs= -golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc= -golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM= -golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= +go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= +go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= +golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= +golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/kama_test.go b/kama_test.go index ea3c881..6730efa 100644 --- a/kama_test.go +++ b/kama_test.go @@ -69,6 +69,8 @@ func SomeFunction(arg1 string, arg2 int) (string, error) { } func TestPrimitives(t *testing.T) { + t.Parallel() + tt := []interface{}{ false, true, @@ -120,6 +122,8 @@ func (h myHandler) ServeHTTP(http.ResponseWriter, *http.Request) { } func TestStdlibTypes(t *testing.T) { + t.Parallel() + tt := []interface{}{ errors.New, reflect.Value{}, @@ -135,6 +139,8 @@ func TestStdlibTypes(t *testing.T) { } func TestThirdPartyTypes(t *testing.T) { + t.Parallel() + tt := []interface{}{ pkgErrors.New, } diff --git a/packages_test.go b/packages_test.go index 825b13f..7230c08 100644 --- a/packages_test.go +++ b/packages_test.go @@ -7,6 +7,8 @@ import ( ) func TestStdlibPackages(t *testing.T) { + t.Parallel() + tt := []struct { importPath string expected pak @@ -70,6 +72,8 @@ func TestStdlibPackages(t *testing.T) { } func TestThirdPartyPackages(t *testing.T) { + t.Parallel() + tt := []struct { importPath string expected pak @@ -119,6 +123,8 @@ func TestThirdPartyPackages(t *testing.T) { } func TestError(t *testing.T) { + t.Parallel() + c := qt.New(t) _, err := newPak("github.com/pkg/NoSuchModule") diff --git a/stack_test.go b/stack_test.go index a91c32e..6ef966d 100644 --- a/stack_test.go +++ b/stack_test.go @@ -7,7 +7,11 @@ import ( ) func Test_getStackTrace(t *testing.T) { + t.Parallel() + t.Run("test-get-stacktraces", func(t *testing.T) { + t.Parallel() + c := qt.New(t) got := a() @@ -30,7 +34,11 @@ func c() []string { } func Test_stackp(t *testing.T) { + t.Parallel() + t.Run("test-stackp", func(t *testing.T) { + t.Parallel() + d() }) } diff --git a/testdata/slice_of_http_Request_value_structs.txt b/testdata/slice_of_http_Request_value_structs.txt index 44ef1bc..c75999a 100755 --- a/testdata/slice_of_http_Request_value_structs.txt +++ b/testdata/slice_of_http_Request_value_structs.txt @@ -12,18 +12,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -36,18 +35,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -60,18 +58,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -84,18 +81,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -108,18 +104,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -132,18 +127,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -156,18 +150,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -180,18 +173,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -204,18 +196,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -228,18 +219,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -252,18 +242,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -276,18 +265,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -300,18 +288,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -324,18 +311,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -348,18 +334,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -372,18 +357,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -396,18 +380,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -420,18 +403,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -444,18 +426,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -468,18 +449,17 @@ SNIPPET: []http.Request{ Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), diff --git a/vars_test.go b/vars_test.go index dfc5845..dac71a0 100644 --- a/vars_test.go +++ b/vars_test.go @@ -82,29 +82,29 @@ func bigArray() [10_000]int { var BigString = `AT last the sleepy atmosphere was stirred—and vigorously: the murder trial came on in the court. It became the absorbing topic of village talk immediately. Tom could not get away from it. Every reference to the murder sent a shudder to his heart, for his troubled conscience and fears almost persuaded him that these remarks were put forth in his hearing as “feelers”; he did not see how he could be suspected of knowing anything about the murder, but still he could not be comfortable in the midst of this gossip. It kept him in a cold shiver all the time. He took Huck to a lonely place to have a talk with him. It would be some relief to unseal his tongue for a little while; to divide his burden of distress with another sufferer. Moreover, he wanted to assure himself that Huck had remained discreet. “Huck, have you ever told anybody about—that?” -“’Bout what?” +“'Bout what?” “You know what.” -“Oh—’course I haven’t.” +“Oh—'course I haven't.” “Never a word?” “Never a solitary word, so help me. What makes you ask?” “Well, I was afeard.” -“Why, Tom Sawyer, we wouldn’t be alive two days if that got found out. You know that.” +“Why, Tom Sawyer, we wouldn't be alive two days if that got found out. You know that.” Tom felt more comfortable. After a pause: -“Huck, they couldn’t anybody get you to tell, could they?” -“Get me to tell? Why, if I wanted that halfbreed devil to drownd me they could get me to tell. They ain’t no different way.” -“Well, that’s all right, then. I reckon we’re safe as long as we keep mum. But let’s swear again, anyway. It’s more surer.” -“I’m agreed.” +“Huck, they couldn't anybody get you to tell, could they?” +“Get me to tell? Why, if I wanted that halfbreed devil to drownd me they could get me to tell. They ain't no different way.” +“Well, that's all right, then. I reckon we're safe as long as we keep mum. But let's swear again, anyway. It's more surer.” +“I'm agreed.” So they swore again with dread solemnities. -“What is the talk around, Huck? I’ve heard a power of it.” -“Talk? Well, it’s just Muff Potter, Muff Potter, Muff Potter all the time. It keeps me in a sweat, constant, so’s I want to hide som’ers.” -“That’s just the same way they go on round me. I reckon he’s a goner. Don’t you feel sorry for him, sometimes?” -“Most always—most always. He ain’t no account; but then he hain’t ever done anything to hurt anybody. Just fishes a little, to get money to get drunk on—and loafs around considerable; but lord, we all do that—leastways most of us—preachers and such like. But he’s kind of good—he give me half a fish, once, when there warn’t enough for two; and lots of times he’s kind of stood by me when I was out of luck.” -“Well, he’s mended kites for me, Huck, and knitted hooks on to my line. I wish we could get him out of there.” -“My! we couldn’t get him out, Tom. And besides, ’twouldn’t do any good; they’d ketch him again.” -“Yes—so they would. But I hate to hear ’em abuse him so like the dickens when he never done—that.” -“I do too, Tom. Lord, I hear ’em say he’s the bloodiest looking villain in this country, and they wonder he wasn’t ever hung before.” -“Yes, they talk like that, all the time. I’ve heard ’em say that if he was to get free they’d lynch him.” -“And they’d do it, too.” +“What is the talk around, Huck? I've heard a power of it.” +“Talk? Well, it's just Muff Potter, Muff Potter, Muff Potter all the time. It keeps me in a sweat, constant, so's I want to hide som'ers.” +“That's just the same way they go on round me. I reckon he's a goner. Don't you feel sorry for him, sometimes?” +“Most always—most always. He ain't no account; but then he hain't ever done anything to hurt anybody. Just fishes a little, to get money to get drunk on—and loafs around considerable; but lord, we all do that—leastways most of us—preachers and such like. But he's kind of good—he give me half a fish, once, when there warn't enough for two; and lots of times he's kind of stood by me when I was out of luck.” +“Well, he's mended kites for me, Huck, and knitted hooks on to my line. I wish we could get him out of there.” +“My! we couldn't get him out, Tom. And besides, 'twouldn't do any good; they'd ketch him again.” +“Yes—so they would. But I hate to hear 'em abuse him so like the dickens when he never done—that.” +“I do too, Tom. Lord, I hear 'em say he's the bloodiest looking villain in this country, and they wonder he wasn't ever hung before.” +“Yes, they talk like that, all the time. I've heard 'em say that if he was to get free they'd lynch him.” +“And they'd do it, too.” The boys had a long talk, but it brought them little comfort. As the twilight drew on, they found themselves hanging about the neighborhood of the little isolated jail, perhaps with an undefined hope that something would happen that might clear away their difficulties. But nothing happened; there seemed to be no angels or fairies interested in this luckless captive. The boys did as they had often done before—went to the cell grating and gave Potter some tobacco and matches. He was on the ground floor and there were no guards.` @@ -114,6 +114,8 @@ type SomeStructWIthSlice struct { } func TestBasicVariables(t *testing.T) { + t.Parallel() + tt := []struct { tName string variable interface{} @@ -309,7 +311,7 @@ func TestBasicVariables(t *testing.T) { Signature: []string{"string"}, Fields: []string{}, Methods: []string{}, - Val: `"AT last the sleepy atmosphere was stirred—and vigorously: the murder trial came on in the court. It ...<3404 more redacted>..`, + Val: `"AT last the sleepy atmosphere was stirred—and vigorously: the murder trial came on in the court. It ...<3332 more redacted>..`, }, }, { @@ -389,6 +391,8 @@ func TestBasicVariables(t *testing.T) { for _, v := range tt { v := v t.Run(v.tName, func(t *testing.T) { + t.Parallel() + c := qt.New(t) res := newVari(v.variable) c.Assert(res, qt.DeepEquals, v.expected) @@ -397,6 +401,8 @@ func TestBasicVariables(t *testing.T) { } func TestStdlibVariables(t *testing.T) { + t.Parallel() + tt := []struct { tName string variable interface{} @@ -459,18 +465,17 @@ func TestStdlibVariables(t *testing.T) { Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -537,18 +542,17 @@ func TestStdlibVariables(t *testing.T) { Proto: "", ProtoMajor: int(0), ProtoMinor: int(0), - Header: http.Header{}, + Header: http.Header{(nil)}, Body: io.ReadCloser nil, GetBody: func() (io.ReadCloser, error), ContentLength: int64(0), - TransferEncoding: []string{ -}, + TransferEncoding: []string{(nil)}, Close: false, Host: "", - Form: url.Values{}, - PostForm: url.Values{}, + Form: url.Values{(nil)}, + PostForm: url.Values{(nil)}, MultipartForm: *multipart.Form(nil), - Trailer: http.Header{}, + Trailer: http.Header{(nil)}, RemoteAddr: "", RequestURI: "", TLS: *tls.ConnectionState(nil), @@ -562,9 +566,141 @@ func TestStdlibVariables(t *testing.T) { for _, v := range tt { v := v t.Run(v.tName, func(t *testing.T) { + t.Parallel() + c := qt.New(t) res := newVari(v.variable) c.Assert(res, qt.DeepEquals, v.expected) }) } } + +func TestSliceMap(t *testing.T) { + t.Parallel() + c := qt.New(t) + + var nilSlice []string = nil + var nilMap map[string]int = nil + + tt := []struct { + tName string + variable interface{} + expected vari + }{ + { + tName: "nil slice", + variable: nilSlice, + expected: vari{ + Name: "[]string", + Kind: reflect.Slice, + Signature: []string{"[]string"}, + Fields: []string{}, + Methods: []string{}, + Val: "[]string{(nil)}", + }, + }, + { + tName: "no element slice", + variable: []string{}, + expected: vari{ + Name: "[]string", + Kind: reflect.Slice, + Signature: []string{"[]string"}, + Fields: []string{}, + Methods: []string{}, + Val: "[]string{}", + }, + }, + { + tName: "one element slice", + variable: []string{"hello"}, + expected: vari{ + Name: "[]string", + Kind: reflect.Slice, + Signature: []string{"[]string"}, + Fields: []string{}, + Methods: []string{}, + Val: `[]string{ + "hello", +}`, + }, + }, + { + tName: "two element slice", + variable: []string{"one", "two"}, + expected: vari{ + Name: "[]string", + Kind: reflect.Slice, + Signature: []string{"[]string"}, + Fields: []string{}, + Methods: []string{}, + Val: `[]string{ + "one", + "two", +}`, + }, + }, + { + tName: "nil map", + variable: nilMap, + expected: vari{ + Name: "map[string]int", + Kind: reflect.Map, + Signature: []string{"map[string]int"}, + Fields: []string{}, + Methods: []string{}, + Val: "map[string]int{(nil)}", + }, + }, + { + tName: "no element map", + variable: map[string]int{}, + expected: vari{ + Name: "map[string]int", + Kind: reflect.Map, + Signature: []string{"map[string]int"}, + Fields: []string{}, + Methods: []string{}, + Val: "map[string]int{}", + }, + }, + { + tName: "one element map", + variable: map[string]int{"o": 1}, + expected: vari{ + Name: "map[string]int", + Kind: reflect.Map, + Signature: []string{"map[string]int"}, + Fields: []string{}, + Methods: []string{}, + Val: `map[string]int{ + "o": int(1), }`, + }, + }, + { + tName: "two element map", + variable: map[string]int{"o": 1, "two": 2}, + expected: vari{ + Name: "map[string]int", + Kind: reflect.Map, + Signature: []string{"map[string]int"}, + Fields: []string{}, + Methods: []string{}, + Val: `map[string]int{ + "o": int(1), + "two": int(2), }`, + }, + }, + } + + for _, v := range tt { + v := v + + t.Run(v.tName, func(t *testing.T) { + t.Parallel() + + res := newVari(v.variable) + c.Assert(res, qt.DeepEquals, v.expected) + }) + } +}