Skip to content

Commit

Permalink
deps: migrate from testify to gotest
Browse files Browse the repository at this point in the history
Keeping up with the preferred unit testing library.
  • Loading branch information
odsod committed Jun 11, 2020
1 parent 9649f0e commit 644519b
Show file tree
Hide file tree
Showing 38 changed files with 349 additions and 329 deletions.
34 changes: 17 additions & 17 deletions data_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"testing/quick"

"github.com/stretchr/testify/require"
"gotest.tools/v3/assert"
)

func TestData_Bit(t *testing.T) {
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestData_Bit(t *testing.T) {
j, ttBit := j, ttBit
t.Run(fmt.Sprintf("tt=%v,bit=%v", i, j), func(t *testing.T) {
bit := tt.data.Bit(ttBit.i)
require.Equal(t, ttBit.bit, bit)
assert.Equal(t, ttBit.bit, bit)
})
}
})
Expand All @@ -63,7 +63,7 @@ func TestData_Bit(t *testing.T) {
for _, tBit := range tt.bits {
data.SetBit(tBit.i, tBit.bit)
}
require.Equal(t, tt.data, data)
assert.DeepEqual(t, tt.data, data)
})
})
}
Expand All @@ -78,7 +78,7 @@ func TestData_Property_SetGetBit(t *testing.T) {
data.SetBit(i, bit)
return data.Bit(i)
}
require.NoError(t, quick.CheckEqual(f, g, nil))
assert.NilError(t, quick.CheckEqual(f, g, nil))
}

func TestData_LittleEndian(t *testing.T) {
Expand Down Expand Up @@ -133,7 +133,7 @@ func TestData_LittleEndian(t *testing.T) {
j, signal := j, signal
t.Run(fmt.Sprintf("signal:%v", j), func(t *testing.T) {
actual := tt.data.UnsignedBitsLittleEndian(signal.start, signal.length)
require.Equal(t, signal.unsigned, actual)
assert.Equal(t, signal.unsigned, actual)
})
}
})
Expand All @@ -142,7 +142,7 @@ func TestData_LittleEndian(t *testing.T) {
j, signal := j, signal
t.Run(fmt.Sprintf("signal:%v", j), func(t *testing.T) {
actual := tt.data.SignedBitsLittleEndian(signal.start, signal.length)
require.Equal(t, signal.signed, actual)
assert.Equal(t, signal.signed, actual)
})
}
})
Expand All @@ -154,7 +154,7 @@ func TestData_LittleEndian(t *testing.T) {
data.SetUnsignedBitsLittleEndian(signal.start, signal.length, signal.unsigned)
})
}
require.Equal(t, tt.data, data)
assert.DeepEqual(t, tt.data, data)
})
t.Run(fmt.Sprintf("SetSignedBits:%v", i), func(t *testing.T) {
var data Data
Expand All @@ -164,7 +164,7 @@ func TestData_LittleEndian(t *testing.T) {
data.SetSignedBitsLittleEndian(signal.start, signal.length, signal.signed)
})
}
require.Equal(t, tt.data, data)
assert.DeepEqual(t, tt.data, data)
})
}
}
Expand Down Expand Up @@ -234,7 +234,7 @@ func TestData_BigEndian(t *testing.T) {
j, signal := j, signal
t.Run(fmt.Sprintf("signal:%v", j), func(t *testing.T) {
actual := tt.data.UnsignedBitsBigEndian(signal.start, signal.length)
require.Equal(t, signal.unsigned, actual)
assert.Equal(t, signal.unsigned, actual)
})
}
})
Expand All @@ -243,7 +243,7 @@ func TestData_BigEndian(t *testing.T) {
j, signal := j, signal
t.Run(fmt.Sprintf("signal:%v", j), func(t *testing.T) {
actual := tt.data.SignedBitsBigEndian(signal.start, signal.length)
require.Equal(t, signal.signed, actual)
assert.Equal(t, signal.signed, actual)
})
}
})
Expand All @@ -255,7 +255,7 @@ func TestData_BigEndian(t *testing.T) {
data.SetUnsignedBitsBigEndian(signal.start, signal.length, signal.unsigned)
})
}
require.Equal(t, tt.data, data)
assert.DeepEqual(t, tt.data, data)
})
t.Run(fmt.Sprintf("SetSignedBits:%v", i), func(t *testing.T) {
var data Data
Expand All @@ -265,14 +265,14 @@ func TestData_BigEndian(t *testing.T) {
data.SetSignedBitsBigEndian(signal.start, signal.length, signal.signed)
})
}
require.Equal(t, tt.data, data)
assert.DeepEqual(t, tt.data, data)
})
}
}

func TestInvertEndian_Property_Idempotent(t *testing.T) {
for i := uint8(0); i < 64; i++ {
require.Equal(t, i, invertEndian(invertEndian(i)))
assert.Equal(t, i, invertEndian(invertEndian(i)))
}
}

Expand All @@ -284,7 +284,7 @@ func TestPackUnpackBigEndian(t *testing.T) {
data.UnpackBigEndian(data.PackBigEndian())
return data
}
require.NoError(t, quick.CheckEqual(f, g, nil))
assert.NilError(t, quick.CheckEqual(f, g, nil))
}

func TestPackUnpackLittleEndian(t *testing.T) {
Expand All @@ -295,13 +295,13 @@ func TestPackUnpackLittleEndian(t *testing.T) {
data.UnpackLittleEndian(data.PackLittleEndian())
return data
}
require.NoError(t, quick.CheckEqual(f, g, nil))
assert.NilError(t, quick.CheckEqual(f, g, nil))
}

func TestData_CheckBitRange(t *testing.T) {
// example case that big-endian signals and little-endian signals use different indexing
require.NoError(t, CheckBitRangeBigEndian(8, 55, 16))
require.Error(t, CheckBitRangeLittleEndian(8, 55, 16))
assert.NilError(t, CheckBitRangeBigEndian(8, 55, 16))
assert.ErrorContains(t, CheckBitRangeLittleEndian(8, 55, 16), "bit range out of bounds")
}

func BenchmarkData_UnpackLittleEndian(b *testing.B) {
Expand Down
11 changes: 6 additions & 5 deletions frame_json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"testing"
"testing/quick"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

func TestFrame_JSON(t *testing.T) {
Expand Down Expand Up @@ -67,14 +68,14 @@ func TestFrame_JSON(t *testing.T) {
} {
tt := tt
t.Run(fmt.Sprintf("JSON|frame=%v", tt.frame), func(t *testing.T) {
assert.Equal(t, tt.jsonFrame, tt.frame.JSON())
assert.Check(t, is.Equal(tt.jsonFrame, tt.frame.JSON()))
})
t.Run(fmt.Sprintf("UnmarshalJSON|frame=%v", tt.frame), func(t *testing.T) {
var frame Frame
if err := json.Unmarshal([]byte(tt.jsonFrame), &frame); err != nil {
t.Fatal(err)
}
assert.Equal(t, tt.frame, frame)
assert.Check(t, is.DeepEqual(tt.frame, frame))
})
}
}
Expand All @@ -83,11 +84,11 @@ func TestFrame_UnmarshalJSON_Invalid(t *testing.T) {
var f Frame
t.Run("invalid JSON", func(t *testing.T) {
data := `foobar`
assert.NotNil(t, f.UnmarshalJSON([]uint8(data)))
assert.Check(t, f.UnmarshalJSON([]uint8(data)) != nil)
})
t.Run("invalid payload", func(t *testing.T) {
data := `{"id":1,"data":"foobar","extended":false,"remote":false}`
assert.NotNil(t, f.UnmarshalJSON([]uint8(data)))
assert.Check(t, f.UnmarshalJSON([]uint8(data)) != nil)
})
}

Expand Down
11 changes: 6 additions & 5 deletions frame_string_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import (
"fmt"
"testing"

"github.com/stretchr/testify/assert"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)

func TestFrame_String(t *testing.T) {
Expand Down Expand Up @@ -55,14 +56,14 @@ func TestFrame_String(t *testing.T) {
} {
tt := tt
t.Run(fmt.Sprintf("String|frame=%v,str=%v", tt.frame, tt.str), func(t *testing.T) {
assert.Equal(t, tt.str, tt.frame.String())
assert.Check(t, is.Equal(tt.str, tt.frame.String()))
})
t.Run(fmt.Sprintf("UnmarshalString|frame=%v,str=%v", tt.frame, tt.str), func(t *testing.T) {
var actual Frame
if err := actual.UnmarshalString(tt.str); err != nil {
t.Fatal(err)
}
assert.Equal(t, actual, tt.frame)
assert.Check(t, is.DeepEqual(actual, tt.frame))
})
}
}
Expand All @@ -78,8 +79,8 @@ func TestParseFrame_Errors(t *testing.T) {
t.Run(fmt.Sprintf("str=%v", tt), func(t *testing.T) {
var frame Frame
err := frame.UnmarshalString(tt)
assert.Error(t, err)
assert.Equal(t, Frame{}, frame)
assert.ErrorContains(t, err, "invalid")
assert.Check(t, is.DeepEqual(Frame{}, frame))
})
}
}
7 changes: 3 additions & 4 deletions frame_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"testing"
"unsafe"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"gotest.tools/v3/assert"
)

// If this mocks ever starts failing, the documentation needs to be updated
// to prefer pass-by-pointer over pass-by-value.
func TestFrame_Size(t *testing.T) {
require.True(t, unsafe.Sizeof(Frame{}) <= 16, "Frame size is <= 16 bytes")
assert.Assert(t, unsafe.Sizeof(Frame{}) <= 16, "Frame size is <= 16 bytes")
}

func TestFrame_Validate_Error(t *testing.T) {
Expand All @@ -22,7 +21,7 @@ func TestFrame_Validate_Error(t *testing.T) {
} {
tt := tt
t.Run(fmt.Sprintf("%v", tt), func(t *testing.T) {
assert.NotNil(t, tt.Validate(), "should return validation error")
assert.Check(t, tt.Validate() != nil, "should return validation error")
})
}
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ require (
github.com/mattn/go-isatty v0.0.9 // indirect
github.com/shurcooL/go v0.0.0-20190704215121-7189cc372560 // indirect
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041
github.com/stretchr/testify v1.4.0
go.uber.org/goleak v0.10.0
golang.org/x/net v0.0.0-20200602114024-627f9648deb9
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd
golang.org/x/tools v0.0.0-20200609164405-eb789aa7ce50
gopkg.in/alecthomas/kingpin.v2 v2.2.6
gotest.tools/v3 v3.0.2
)
9 changes: 9 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,22 @@ github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/golang/mock v1.4.4-0.20200519145626-92f53b0a566c h1:SP2mbHeyu1pCO5i8Xv6e3xgoKKMEhm6DJNVnflRaim0=
github.com/golang/mock v1.4.4-0.20200519145626-92f53b0a566c/go.mod h1:Va/jHywg6k5sXNOWdWbM806eUNOSiXznot/rTG4olf0=
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9 h1:d5US/mDsogSGW37IV293h//ZFaeajb69h+EHFsv2xGg=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
github.com/pkg/errors v0.8.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/shurcooL/go v0.0.0-20190704215121-7189cc372560 h1:SpaoQDTgpo2YZkvmr2mtgloFFfPTjtLMlZkQtNAPQik=
github.com/shurcooL/go v0.0.0-20190704215121-7189cc372560/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041 h1:llrF3Fs4018ePo4+G/HV/uQUqEI1HMDjCeOf2V6puPc=
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
Expand All @@ -31,6 +36,7 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
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-20200226121028-0de0cce0169b h1:0mm1VjtFUOIlE1SbDlwjYaDxZVDP2S5ou6y0gSgXHu8=
Expand All @@ -49,6 +55,7 @@ golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e h1:aZzprAO9/8oim3qStq3wc1Xuxx4QmAGriC4VU4ojemQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200609164405-eb789aa7ce50 h1:59syOWj4+Fl+op4LL8fX1kO7HmbdEWfxlw4tcGvH+y0=
Expand All @@ -63,6 +70,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
rsc.io/quote/v3 v3.1.0 h1:9JKUTTIUgS6kzR9mK1YuGKv6Nl+DijDNIc0ghT58FaY=
rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0 h1:7uVkIFmeBqHfdjD+gZwtXXI+RODJ2Wc4O7MPEh/QiW4=
Expand Down
6 changes: 3 additions & 3 deletions internal/generate/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
"go.einride.tech/can/pkg/descriptor"
examplecan "go.einride.tech/can/testdata/gen/go/example"
"gotest.tools/v3/assert"
)

func TestCompile_ExampleDBC(t *testing.T) {
Expand Down Expand Up @@ -295,13 +295,13 @@ func TestCompile_ExampleDBC(t *testing.T) {
},
}
input, err := ioutil.ReadFile(exampleDBCFile)
require.NoError(t, err)
assert.NilError(t, err)
result, err := Compile(exampleDBCFile, input)
if err != nil {
t.Fatal(err)
}
if len(result.Warnings) > 0 {
t.Fatal(result.Warnings)
}
require.Equal(t, exampleDatabase, result.Database)
assert.DeepEqual(t, exampleDatabase, result.Database)
}
Loading

0 comments on commit 644519b

Please sign in to comment.