Skip to content

Commit

Permalink
feat: add package name to output of failed structures
Browse files Browse the repository at this point in the history
  • Loading branch information
xobotyi committed Mar 23, 2023
1 parent d87b6df commit 9daf863
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
2 changes: 1 addition & 1 deletion analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (a *analyzer) processStruct(
if f := a.litSkippedFields(lit, structTyp, !isSamePackage); len(f) > 0 {
structName := "anonymous struct"
if namedTyp != nil {
structName = namedTyp.Obj().Name()
structName = namedTyp.Obj().Pkg().Name() + "." + namedTyp.Obj().Name()
}

pos := lit.Pos()
Expand Down
22 changes: 11 additions & 11 deletions analyzer/testdata/src/i/i.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func shouldPassOnlyOptionalOmitted() {
}

func shouldFailRequiredOmitted() {
_ = Test{ // want "Test is missing field D"
_ = Test{ // want "i.Test is missing field D"
A: "",
B: 0,
C: 0.0,
Expand All @@ -69,11 +69,11 @@ func shouldPassEmptyStructWithNonNilErr() (Test, error) {
}

func shouldFailEmptyStructWithNilErr() (Test, error) {
return Test{}, nil // want "Test is missing fields A, B, C, D"
return Test{}, nil // want "i.Test is missing fields A, B, C, D"
}

func shouldFailEmptyNestedStructWithNonNilErr() ([]Test, error) {
return []Test{{}}, nil // want "Test is missing fields A, B, C, D"
return []Test{{}}, nil // want "i.Test is missing fields A, B, C, D"
}

func shouldPassUnnamed() {
Expand Down Expand Up @@ -110,8 +110,8 @@ func shouldFailEmbedded() {
}

func shouldFailEmbeddedCompletelyMissing() {
_ = Test2{ // want "Test2 is missing field Embedded"
External: e.External{ // want "External is missing field B"
_ = Test2{ // want "i.Test2 is missing field Embedded"
External: e.External{ // want "e.External is missing field B"
A: "",
},
}
Expand All @@ -130,8 +130,8 @@ func shouldPassGeneric() {
}

func shouldFailGeneric() {
_ = testGenericStruct[int]{} // want "testGenericStruct is missing fields A, B"
_ = testGenericStruct[int]{ // want "testGenericStruct is missing field B"
_ = testGenericStruct[int]{} // want "i.testGenericStruct is missing fields A, B"
_ = testGenericStruct[int]{ // want "i.testGenericStruct is missing field B"
A: 42,
}
}
Expand Down Expand Up @@ -169,8 +169,8 @@ func shouldPassSlicesOfStructs() {

func shouldFailSlicesOfStructs() {
_ = []Test3{
{}, // want "Test3 is missing field A"
Test3{B: 123}, // want "Test3 is missing field A"
{}, // want "i.Test3 is missing field A"
Test3{B: 123}, // want "i.Test3 is missing field A"
}
}

Expand All @@ -184,8 +184,8 @@ func shouldPassMapOfStructs() {

func shouldFailMapOfStructs() {
_ = map[string]Test3{
"a": {}, // want "Test3 is missing field A"
"b": Test3{B: 123}, // want "Test3 is missing field A"
"a": {}, // want "i.Test3 is missing field A"
"b": Test3{B: 123}, // want "i.Test3 is missing field A"
}
}

Expand Down
9 changes: 6 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
module github.com/GaijinEntertainment/go-exhaustruct/v2
module github.com/GaijinEntertainment/go-exhaustruct/v3

go 1.20

require (
golang.org/x/exp v0.0.0-20230303215020-44a13b063f3e
golang.org/x/tools v0.7.0
github.com/stretchr/testify v1.8.2
golang.org/x/tools v0.6.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/sys v0.6.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
23 changes: 19 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
golang.org/x/exp v0.0.0-20230303215020-44a13b063f3e h1:S8xf0d0OEmWrClvbMiUSp+7cGD00txONylwExlf9wR0=
golang.org/x/exp v0.0.0-20230303215020-44a13b063f3e/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sys v0.6.0 h1:MVltZSvRTcU2ljQOhs94SXPftV6DCNnZViHeQps87pQ=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/tools v0.7.0 h1:W4OVu8VVOaIO0yzWMNdepAulS7YfoS3Zabrm8DOXXU4=
golang.org/x/tools v0.7.0/go.mod h1:4pg6aUX35JBAogB10C9AtvVL+qowtN4pT3CGSQex14s=
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/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

0 comments on commit 9daf863

Please # to comment.