Skip to content

Commit 535ba9f

Browse files
committed
chore: get rid of testify/assert in unit tests, to remove too much indirect dependencies
1 parent 7973b18 commit 535ba9f

File tree

4 files changed

+42
-35
lines changed

4 files changed

+42
-35
lines changed

component_test.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package volt
22

33
import (
44
"fmt"
5-
"github.com/stretchr/testify/assert"
65
"testing"
76
)
87

@@ -74,7 +73,9 @@ func TestGetComponent(t *testing.T) {
7473
for _, entityId := range entities {
7574
component := GetComponent[testTransform](world, entityId)
7675

77-
assert.NotNil(t, component)
76+
if component == nil {
77+
t.Errorf("Could not get created component for entityId %d", entityId)
78+
}
7879
}
7980
}
8081

@@ -108,14 +109,20 @@ func TestRemoveComponent(t *testing.T) {
108109
}
109110

110111
// if the indices in storage are messed up, then i & x would not match anymore
111-
assert.Equal(t, i, GetComponent[testTag](world, entityId).x)
112+
if i != GetComponent[testTag](world, entityId).x {
113+
t.Errorf("x value does not equals its i index in testTag, the storage indices are probably shuffled")
114+
}
112115
} else {
113116
if !world.HasComponents(entityId, []ComponentId{testTransformId, testTagId}...) {
114117
t.Errorf("Expected 2 components for entity %d", entityId)
115118
}
116119

117-
assert.Equal(t, i, GetComponent[testTransform](world, entityId).x)
118-
assert.Equal(t, i, GetComponent[testTag](world, entityId).x)
120+
if i != GetComponent[testTransform](world, entityId).x {
121+
t.Errorf("x value does not equals its i index in testTransform, the storage indices are probably shuffled")
122+
}
123+
if i != GetComponent[testTag](world, entityId).x {
124+
t.Errorf("x value does not equals its i index in testTag, the storage indices are probably shuffled")
125+
}
119126
}
120127
}
121128
}

go.mod

-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
module github.com/akmonengine/volt
22

33
go 1.23
4-
5-
require github.com/stretchr/testify v1.9.0
6-
7-
require (
8-
github.com/davecgh/go-spew v1.1.1 // indirect
9-
github.com/pmezard/go-difflib v1.0.0 // indirect
10-
gopkg.in/yaml.v3 v3.0.1 // indirect
11-
)

go.sum

-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +0,0 @@
1-
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
2-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
3-
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
5-
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
6-
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
7-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
8-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
9-
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
10-
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

world_test.go

+30-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package volt
22

33
import (
44
"fmt"
5-
"github.com/stretchr/testify/assert"
65
"testing"
76
)
87

@@ -17,10 +16,15 @@ func TestWorld_CreateEntity(t *testing.T) {
1716
}
1817

1918
// Check if the entities all exist in the world
20-
assert.True(t, len(world.Entities) == TEST_ENTITY_NUMBER)
19+
if len(world.Entities) != TEST_ENTITY_NUMBER {
20+
t.Errorf("Number of entities created invalid")
21+
}
2122
for i := 0; i < TEST_ENTITY_NUMBER; i++ {
2223
_, ok := world.Entities[entities[i]]
23-
assert.True(t, ok)
24+
25+
if !ok {
26+
t.Errorf("Entity %d was not created properly", entities[i])
27+
}
2428
}
2529
}
2630

@@ -36,11 +40,17 @@ func TestWorld_RemoveEntity(t *testing.T) {
3640
world.RemoveEntity(entities[TEST_ENTITY_NUMBER/2])
3741
world.RemoveEntity(entities[TEST_ENTITY_NUMBER-1])
3842

39-
// Check if the entities all exist in the world
40-
assert.True(t, len(world.Entities) == (TEST_ENTITY_NUMBER-3))
41-
assert.True(t, world.SearchEntity(fmt.Sprint(0)) == 0)
42-
assert.True(t, world.SearchEntity(fmt.Sprint(TEST_ENTITY_NUMBER/2)) == 0)
43-
assert.True(t, world.SearchEntity(fmt.Sprint(TEST_ENTITY_NUMBER-1)) == 0)
43+
// Check the expected world size
44+
if len(world.Entities) != (TEST_ENTITY_NUMBER - 3) {
45+
t.Errorf("World size not valid after removal of entities")
46+
}
47+
48+
// Check if the entities are correctly removed of the world
49+
for _, id := range []EntityId{0, TEST_ENTITY_NUMBER / 2, TEST_ENTITY_NUMBER - 1} {
50+
if world.SearchEntity(fmt.Sprint(0)) != 0 {
51+
t.Errorf("Entity %d was not removed", entities[id])
52+
}
53+
}
4454
}
4555

4656
func TestWorld_SearchEntity(t *testing.T) {
@@ -53,11 +63,15 @@ func TestWorld_SearchEntity(t *testing.T) {
5363

5464
// Test searching for existing entities
5565
for entityName, entityId := range entities {
56-
assert.Equal(t, entityId, world.SearchEntity(fmt.Sprint(entityName)))
66+
if entityId != world.SearchEntity(fmt.Sprint(entityName)) {
67+
t.Errorf("SearchEntity does not return correct entityId for %s", fmt.Sprint(entityName))
68+
}
5769
}
5870

5971
// Test searching for a non-existing entity
60-
assert.Zero(t, world.SearchEntity("nonexistent"))
72+
if id := world.SearchEntity("nonexistent"); id != 0 {
73+
t.Errorf("world.SearchEntity returned id %d for a non existent entity", id)
74+
}
6175
}
6276

6377
func TestWorld_GetEntityName(t *testing.T) {
@@ -70,9 +84,13 @@ func TestWorld_GetEntityName(t *testing.T) {
7084

7185
// Test the names for each entity
7286
for entityName, entityId := range entities {
73-
assert.Equal(t, fmt.Sprint(entityName), world.GetEntityName(entityId))
87+
if fmt.Sprint(entityName) != world.GetEntityName(entityId) {
88+
t.Errorf("world.GetEntityName does not return correct value for id %d", entityId)
89+
}
7490
}
7591

7692
// Test if none entity return an empty name
77-
assert.Empty(t, world.GetEntityName(0))
93+
if world.GetEntityName(0) != "" {
94+
t.Errorf("world.GetEntityName does not return empty string for entityId 0")
95+
}
7896
}

0 commit comments

Comments
 (0)