Skip to content

Commit

Permalink
refactor: use stretchr/testify throughout codebase (#1931)
Browse files Browse the repository at this point in the history
Currently, we use 2 implementations of testify in our codebase -
`jaekwon/testify` and `stretchr/testify`

To streamline our practices and minimize confusion, it's a good idea to
opt for a single implementation.

After discussion, we all agreed on using `stretchr/testify` throughout
our codebase.

Closes #777
  • Loading branch information
harry-hov authored Apr 18, 2024
1 parent 6f54d2b commit f26634b
Show file tree
Hide file tree
Showing 41 changed files with 190 additions and 193 deletions.
1 change: 0 additions & 1 deletion contribs/gnodev/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ require (
github.com/gorilla/sessions v1.2.1 // indirect
github.com/gotuna/gotuna v0.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/jaekwon/testify v1.6.1 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.18 // indirect
Expand Down
3 changes: 0 additions & 3 deletions contribs/gnodev/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion contribs/gnokeykc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ require (
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.19.0 // indirect
github.com/jaekwon/testify v1.6.1 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/peterbourgon/ff/v3 v3.4.0 // indirect
Expand Down
3 changes: 0 additions & 3 deletions contribs/gnokeykc/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions gno.land/pkg/gnoland/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
bft "github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/jaekwon/testify/assert"
"github.com/jaekwon/testify/require"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestBalance_Verify(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions gno.land/pkg/integration/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package integration
import (
"errors"

"github.com/jaekwon/testify/assert"
"github.com/jaekwon/testify/require"
"github.com/rogpeppe/go-internal/testscript"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

// This error is from testscript.Fatalf and is needed to correctly
Expand Down
2 changes: 1 addition & 1 deletion gno.land/pkg/integration/testing_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
bft "github.com/gnolang/gno/tm2/pkg/bft/types"
"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/std"
"github.com/jaekwon/testify/require"
"github.com/stretchr/testify/require"
)

const (
Expand Down
16 changes: 8 additions & 8 deletions gno.land/pkg/sdk/vm/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"testing"

"github.com/jaekwon/testify/assert"
"github.com/stretchr/testify/assert"

"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/gnolang/gno/tm2/pkg/std"
Expand Down Expand Up @@ -94,7 +94,7 @@ func Echo(msg string) string {
msg2 := NewMsgCall(addr, coins, pkgPath, "Echo", []string{"hello world"})
res, err := env.vmk.Call(ctx, msg2)
assert.NoError(t, err)
assert.Equal(t, res, `("echo:hello world" string)`)
assert.Equal(t, `("echo:hello world" string)`, res)
// t.Log("result:", res)
}

Expand Down Expand Up @@ -147,7 +147,7 @@ func GetAdmin() string {
msg2 := NewMsgCall(addr, coins, pkgPath, "Echo", []string{"hello world"})
res, err := env.vmk.Call(ctx, msg2)
assert.Error(t, err)
assert.Equal(t, res, "")
assert.Equal(t, "", res)
fmt.Println(err.Error())
assert.True(t, strings.Contains(err.Error(), "insufficient coins error"))
}
Expand Down Expand Up @@ -237,7 +237,7 @@ func Echo(msg string) string {
msg2 := NewMsgCall(addr, coins, pkgPath, "Echo", []string{"hello world"})
res, err := env.vmk.Call(ctx, msg2)
assert.NoError(t, err)
assert.Equal(t, res, `("echo:hello world" string)`)
assert.Equal(t, `("echo:hello world" string)`, res)
}

// Sending too much realm package coins fails.
Expand Down Expand Up @@ -335,7 +335,7 @@ func GetAdmin() string {
res, err := env.vmk.Call(ctx, msg2)
addrString := fmt.Sprintf("(\"%s\" string)", addr.String())
assert.NoError(t, err)
assert.Equal(t, res, addrString)
assert.Equal(t, addrString, res)
}

// Call Run without imports, without variables.
Expand All @@ -362,7 +362,7 @@ func main() {
msg2 := NewMsgRun(addr, coins, files)
res, err := env.vmk.Run(ctx, msg2)
assert.NoError(t, err)
assert.Equal(t, res, "hello world!\n")
assert.Equal(t, "hello world!\n", res)
}

// Call Run with stdlibs.
Expand Down Expand Up @@ -393,7 +393,7 @@ func main() {
res, err := env.vmk.Run(ctx, msg2)
assert.NoError(t, err)
expectedString := fmt.Sprintf("hello world! %s\n", addr.String())
assert.Equal(t, res, expectedString)
assert.Equal(t, expectedString, res)
}

func TestNumberOfArgsError(t *testing.T) {
Expand Down Expand Up @@ -430,9 +430,9 @@ func Echo(msg string) string {
msg2 := NewMsgCall(addr, coins, pkgPath, "Echo", []string{"hello world", "extra arg"})
assert.PanicsWithValue(
t,
"wrong number of arguments in call to Echo: want 1 got 2",
func() {
env.vmk.Call(ctx, msg2)
},
"wrong number of arguments in call to Echo: want 1 got 2",
)
}
2 changes: 1 addition & 1 deletion gnovm/pkg/gnoenv/gnohome_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"
"testing"

"github.com/jaekwon/testify/require"
"github.com/stretchr/testify/require"
)

func TestHomeDir(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions gnovm/pkg/gnoenv/gnoroot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"
"testing"

"github.com/jaekwon/testify/require"
"github.com/stretchr/testify/require"
)

func TestGuessGnoRootDir_WithSetGnoRoot(t *testing.T) {
Expand All @@ -19,7 +19,7 @@ func TestGuessGnoRootDir_WithSetGnoRoot(t *testing.T) {
_GNOROOT = testPath
root, err := GuessRootDir()
require.NoError(t, err)
require.Equal(t, root, testPath)
require.Equal(t, testPath, root)
}

func TestGuessGnoRootDir_UsingCallerStack(t *testing.T) {
Expand All @@ -37,7 +37,7 @@ func TestGuessGnoRootDir_UsingCallerStack(t *testing.T) {
testPath, _ := filepath.Abs(filepath.Join(".", "..", "..", ".."))
root, err := GuessRootDir()
require.NoError(t, err)
require.Equal(t, root, testPath)
require.Equal(t, testPath, root)
}

func TestGuessGnoRootDir_Error(t *testing.T) {
Expand All @@ -61,7 +61,7 @@ func TestInferGnoRootFromGoMod(t *testing.T) {
t.Run("go is present", func(t *testing.T) {
root, err := inferRootFromGoMod()
require.NoError(t, err)
require.Equal(t, root, testPath)
require.Equal(t, testPath, root)
})

t.Run("go is not present", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnoenv/migration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"path/filepath"
"testing"

"github.com/jaekwon/testify/require"
"github.com/stretchr/testify/require"
)

func TestFixOldDefaultGnoHome(t *testing.T) {
Expand Down
20 changes: 10 additions & 10 deletions gnovm/pkg/gnolang/gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"unsafe"

// "github.com/davecgh/go-spew/spew"
"github.com/jaekwon/testify/assert"
"github.com/jaekwon/testify/require"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestRunInvalidLabels(t *testing.T) {
Expand Down Expand Up @@ -284,7 +284,7 @@ func TestDoOpEvalBaseConversion(t *testing.T) {
} else {
m.doOpEval()
v := m.PopValue()
assert.Equal(t, v.V.String(), tc.expect)
assert.Equal(t, tc.expect, v.V.String())
}
}
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func assertOutput(t *testing.T, input string, output string) {
n := MustParseFile("main.go", input)
m.RunFiles(n)
m.RunMain()
assert.Equal(t, string(buf.Bytes()), output)
assert.Equal(t, output, string(buf.Bytes()))
err := m.CheckEmpty()
assert.Nil(t, err)
}
Expand Down Expand Up @@ -469,9 +469,9 @@ func TestModifyTypeAsserted(t *testing.T) {
x2.A = 2

// only x2 is changed.
assert.Equal(t, x.A, 1)
assert.Equal(t, v.(Struct1).A, 1)
assert.Equal(t, x2.A, 2)
assert.Equal(t, 1, x.A)
assert.Equal(t, 1, v.(Struct1).A)
assert.Equal(t, 2, x2.A)
}

type Interface1 interface {
Expand Down Expand Up @@ -668,7 +668,7 @@ func TestCallLHS(t *testing.T) {
return &x
}
*xptr() = 2
assert.Equal(t, x, 2)
assert.Equal(t, 2, x)
}

// XXX is there a way to test in Go as well as Gno?
Expand All @@ -684,6 +684,6 @@ func TestCallFieldLHS(t *testing.T) {
}
y := 0
xptr().X, y = 2, 3
assert.Equal(t, x.X, 2)
assert.Equal(t, y, 3)
assert.Equal(t, 2, x.X)
assert.Equal(t, 3, y)
}
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/go2gno_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"testing"

"github.com/jaekwon/testify/assert"
"github.com/stretchr/testify/assert"
)

func TestParseForLoop(t *testing.T) {
Expand Down
27 changes: 14 additions & 13 deletions gnovm/pkg/gnolang/gonative_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/gnolang/gno/tm2/pkg/crypto"
"github.com/jaekwon/testify/assert"
"github.com/stretchr/testify/assert"
)

// args is an even number of elements,
Expand Down Expand Up @@ -42,13 +42,13 @@ func TestGoNativeDefine(t *testing.T) {
rt := reflect.TypeOf(Foo{})
pkg.DefineGoNativeType(rt)
nt := pkg.GetValueRef(nil, Name("Foo")).GetType().(*NativeType)
assert.Equal(t, nt.Type, rt)
assert.Equal(t, rt, nt.Type)
path := pkg.GetPathForName(nil, Name("Foo"))
assert.Equal(t, path.Depth, uint8(1))
assert.Equal(t, path.Index, uint16(0))
assert.Equal(t, uint8(1), path.Depth)
assert.Equal(t, uint16(0), path.Index)
pv := pkg.NewPackage()
nt = pv.GetBlock(nil).GetPointerTo(nil, path).TV.GetType().(*NativeType)
assert.Equal(t, nt.Type, rt)
assert.Equal(t, rt, nt.Type)
store := gonativeTestStore(pkg, pv)

// Import above package and evaluate foo.Foo.
Expand All @@ -58,8 +58,8 @@ func TestGoNativeDefine(t *testing.T) {
})
m.RunDeclaration(ImportD("foo", "test.foo"))
tvs := m.Eval(Sel(Nx("foo"), "Foo"))
assert.Equal(t, len(tvs), 1)
assert.Equal(t, tvs[0].V.(TypeValue).Type, nt)
assert.Equal(t, 1, len(tvs))
assert.Equal(t, nt, tvs[0].V.(TypeValue).Type)
}

func TestGoNativeDefine2(t *testing.T) {
Expand Down Expand Up @@ -90,11 +90,11 @@ func main() {
n := MustParseFile("main.go", c)
m.RunFiles(n)
m.RunMain()
assert.Equal(t, string(out.Bytes()), `A: 1
assert.Equal(t, `A: 1
B: 0
C: 0
D:
`)
`, out.String())
}

func TestGoNativeDefine3(t *testing.T) {
Expand Down Expand Up @@ -129,11 +129,11 @@ func main() {
n := MustParseFile("main.go", c)
m.RunFiles(n)
m.RunMain()
assert.Equal(t, string(out.Bytes()), `A: 1
assert.Equal(t, `A: 1
B: 0
C: 0
D:
`)
`, out.String())
}

func TestCrypto(t *testing.T) {
Expand All @@ -142,6 +142,7 @@ func TestCrypto(t *testing.T) {
addr := crypto.Address{}
store := gonativeTestStore()
tv := Go2GnoValue(nilAllocator, store, reflect.ValueOf(addr))
assert.Equal(t, tv.String(),
`(array[0x0000000000000000000000000000000000000000] github.com/gnolang/gno/tm2/pkg/crypto.Address)`)
assert.Equal(t,
`(array[0x0000000000000000000000000000000000000000] github.com/gnolang/gno/tm2/pkg/crypto.Address)`,
tv.String())
}
6 changes: 3 additions & 3 deletions gnovm/pkg/gnolang/machine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/gnolang/gno/tm2/pkg/store/dbadapter"
"github.com/gnolang/gno/tm2/pkg/store/iavl"
stypes "github.com/gnolang/gno/tm2/pkg/store/types"
"github.com/jaekwon/testify/assert"
"github.com/stretchr/testify/assert"
)

func BenchmarkCreateNewMachine(b *testing.B) {
Expand Down Expand Up @@ -53,6 +53,6 @@ func TestRunMemPackageWithOverrides_revertToOld(t *testing.T) {
// Check last value, assuming it is the result of Redecl.
v := m.Values[0]
assert.NotNil(t, v)
assert.Equal(t, v.T.Kind(), StringKind)
assert.Equal(t, v.V, StringValue("1"))
assert.Equal(t, StringKind, v.T.Kind())
assert.Equal(t, StringValue("1"), v.V)
}
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"
"testing"

"github.com/jaekwon/testify/require"
"github.com/stretchr/testify/require"

"github.com/gnolang/gno/tm2/pkg/amino"
)
Expand Down
Loading

0 comments on commit f26634b

Please sign in to comment.