From 55c431755608b298f658a7567aae491350f4ba2f Mon Sep 17 00:00:00 2001 From: Oleg Butuzov <butuzov@users.noreply.github.com> Date: Mon, 15 May 2023 11:30:43 +0300 Subject: [PATCH] fix: remove `testify/assert` dependency (#23) --- go.mod | 8 +----- go.sum | 17 ----------- internal/checker/imports_test.go | 26 ++++++++++++----- internal/checker/testing_test.go | 5 ++-- internal/checker/violation_test.go | 45 ++++++++++++++++++++++-------- 5 files changed, 56 insertions(+), 45 deletions(-) diff --git a/go.mod b/go.mod index 48a34e6..5d8fab6 100644 --- a/go.mod +++ b/go.mod @@ -2,15 +2,9 @@ module github.com/butuzov/mirror go 1.19 -require ( - github.com/stretchr/testify v1.8.2 - golang.org/x/tools v0.8.0 -) +require golang.org/x/tools v0.8.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.10.0 // indirect golang.org/x/sys v0.7.0 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index b0dc75b..d84f5f1 100644 --- a/go.sum +++ b/go.sum @@ -1,15 +1,3 @@ -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.10.0 h1:lFO9qtOdlre5W1jxS3r/4szv2/6iXxScdzjoBMXNhYk= golang.org/x/mod v0.10.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= @@ -17,8 +5,3 @@ golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/tools v0.8.0 h1:vSDcovVPld282ceKgDimkRSC8kpaH1dgyc9UMzlt84Y= golang.org/x/tools v0.8.0/go.mod h1:JxBZ99ISMI5ViVkT1tr6tdNmXeTrcpVSD3vZ1RsRdN4= -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= diff --git a/internal/checker/imports_test.go b/internal/checker/imports_test.go index 33df643..08517f6 100644 --- a/internal/checker/imports_test.go +++ b/internal/checker/imports_test.go @@ -4,7 +4,6 @@ import ( "go/token" "testing" - "github.com/stretchr/testify/assert" "golang.org/x/tools/go/ast/inspector" ) @@ -70,25 +69,38 @@ func TestImports(t *testing.T) { fset := token.NewFileSet() ar, err := Txtar(t, fset, test.txtarPath) + if err != nil { + t.Errorf("nil err expected - got %s", err) + } - assert.Nil(t, err) - assert.Len(t, ar, 1) + if len(ar) != 1 { + t.Errorf("Files in txtar: got(%d) vs want(%d)", len(ar), 1) + } ins := inspector.New(ar) testImports := Load(fset, ins) // assert - assert.Len(t, testImports["a.go"], test.importsLen) + if len(testImports["a.go"]) != test.importsLen { + t.Errorf("Imports len not match: got(%d) vs want(%d)", len(testImports["a.go"]), test.importsLen) + } for k, v := range test.hasImports { str, ok := testImports.Lookup("a.go", k) - assert.True(t, ok, "Import `%s` not found", k) - assert.Equal(t, v, str, "Wrong package found want(%s) vs got(%s)", v, str) + if !ok { + t.Errorf("Import `%s` not found", k) + } + + if v != str { + t.Errorf("Wrong package found want(%s) vs got(%s)", v, str) + } } // test if lookup produce fail str, ok := testImports.Lookup("a.go", "foobar") - assert.False(t, ok, "found somethig enexpected %s", str) + if ok { + t.Errorf("found enexpected package %s", str) + } }) } } diff --git a/internal/checker/testing_test.go b/internal/checker/testing_test.go index 8f86f16..7711073 100644 --- a/internal/checker/testing_test.go +++ b/internal/checker/testing_test.go @@ -8,13 +8,14 @@ import ( "strings" "testing" - "github.com/stretchr/testify/assert" "golang.org/x/tools/txtar" ) func ParseExprFrom(t *testing.T, fset *token.FileSet, src any) ast.Expr { astExpr, err := parser.ParseExprFrom(fset, "a.go", src, parser.AllErrors) - assert.NoError(t, err) + if err != nil { + t.Errorf("nil err expected - got %s", err) + } return astExpr } diff --git a/internal/checker/violation_test.go b/internal/checker/violation_test.go index 810ddf5..ae60c39 100644 --- a/internal/checker/violation_test.go +++ b/internal/checker/violation_test.go @@ -7,7 +7,6 @@ import ( "go/types" "testing" - "github.com/stretchr/testify/assert" "golang.org/x/tools/go/ast/inspector" ) @@ -103,8 +102,14 @@ func TestViolation(t *testing.T) { } v2 := test.Violation.With(base, expr, args) - assert.Equal(t, test.ExpectedSuggest, string(v2.suggest(fset))) - assert.Equal(t, test.Message, v2.Message()) + fix := string(v2.suggest(fset)) + if test.ExpectedSuggest != fix { + t.Errorf("Fix not match: want(%s) vs got(%s)", test.ExpectedSuggest, fix) + } + message := v2.Message() + if test.Message != message { + t.Errorf("Message not match: want(%s) vs got(%s)", test.Message, message) + } }) } } @@ -171,7 +176,9 @@ func TestComplex(t *testing.T) { t.Run(test.Name, func(t *testing.T) { fset := token.NewFileSet() ar, err := Txtar(t, fset, test.TxtAr) - assert.Nil(t, err) + if err != nil { + t.Errorf("nil err expected - got %s", err) + } var ( ins = inspector.New(ar) @@ -188,7 +195,9 @@ func TestComplex(t *testing.T) { // ------ Setup ---------------------------------------------------------- _, err = conf.Check("source", fset, ar, &info) - assert.NoError(t, err) + if err != nil { + t.Errorf("nil err expected - got %s", err) + } check := New([]Violation{test.Violation}) check.Type = WrapType(&info) @@ -206,25 +215,37 @@ func TestComplex(t *testing.T) { callExpr := n.(*ast.CallExpr) expr := callExpr.Fun.(*ast.SelectorExpr) x, ok := expr.X.(*ast.Ident) - assert.True(t, ok) + if !ok { + t.Errorf("Expected ast.Indent") + } name := expr.Sel.Name // skipping import checks with correct import path v := check.Match(test.ImportPath, name) - assert.NotNil(t, v) - assert.Equal(t, *v, test.Violation) + if v == nil { + t.Error("nil violation not expected") + } args, found := check.Handle(v, callExpr) - assert.True(t, found, "no string to string conversions found") + if !found { + t.Errorf("no string to string conversions found") + } v2 := v.With(check.Print(x), callExpr, args) gciIssue := v2.Issue(fset) - assert.Equal(t, test.ExpectedFix, gciIssue.InlineFix, "fix not match") - assert.Equal(t, test.ExpectedMessage, gciIssue.Message, "message not match") + if test.ExpectedFix != gciIssue.InlineFix { + t.Errorf("Fix not match: want(%s) vs got(%s)", test.ExpectedFix, gciIssue.InlineFix) + } + + if test.ExpectedMessage != gciIssue.Message { + t.Errorf("Message not match: want(%s) vs got(%s)", test.ExpectedMessage, gciIssue.Message) + } }) - assert.True(t, happend, "Test Not Happend") + if !happend { + t.Errorf("Test Not Happend") + } }) } }