Skip to content

Commit

Permalink
fix: remove testify/assert dependency (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
butuzov authored May 15, 2023
1 parent 85325bc commit 55c4317
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 45 deletions.
8 changes: 1 addition & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
17 changes: 0 additions & 17 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
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=
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=
26 changes: 19 additions & 7 deletions internal/checker/imports_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"go/token"
"testing"

"github.com/stretchr/testify/assert"
"golang.org/x/tools/go/ast/inspector"
)

Expand Down Expand Up @@ -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)
}
})
}
}
5 changes: 3 additions & 2 deletions internal/checker/testing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
45 changes: 33 additions & 12 deletions internal/checker/violation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"go/types"
"testing"

"github.com/stretchr/testify/assert"
"golang.org/x/tools/go/ast/inspector"
)

Expand Down Expand Up @@ -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)
}
})
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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")
}
})
}
}

0 comments on commit 55c4317

Please sign in to comment.