Skip to content

Commit

Permalink
all: Switch to the new test lib.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennwc committed Jan 6, 2024
1 parent 2edb32a commit e8abe68
Show file tree
Hide file tree
Showing 31 changed files with 337 additions and 288 deletions.
24 changes: 12 additions & 12 deletions balance/balance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package balance
import (
"testing"

"github.com/stretchr/testify/require"
"github.com/shoenig/test/must"

"github.com/noxworld-dev/opennox-lib/noxtest"
)

func TestReadBalance(t *testing.T) {
f, err := ReadBalance(noxtest.DataPath(t, GamedataFile))
require.NoError(t, err)
require.Equal(t, float64(0.2), f.FloatDef("", "BerserkerPainRatio", -1))
require.Equal(t, float64(0.2), f.FloatDef(TagSolo, "BerserkerPainRatio", -1))
require.Equal(t, float64(-1), f.FloatDef("", "BerserkerDamage", -1))
require.Equal(t, float64(100), f.FloatDef(TagSolo, "BerserkerDamage", -1))
require.Equal(t, float64(150), f.FloatDef(TagArena, "BerserkerDamage", -1))
require.Equal(t, float64(0.60), f.FloatDef("", "RepairCoefficient", -1))
require.Equal(t, float64(150), f.FloatDef(TagArena, "WarriorMaxHealth", -1))
require.Equal(t, []float64{0.5, 0.7, 1.0, 1.3, 1.6}, f.Array(TagSolo, "EnergyBoltDamage"))
require.Equal(t, []float64{1.3, 1.6, 2.0, 2.3, 2.6}, f.Array(TagArena, "EnergyBoltDamage"))
require.Equal(t, []float64{
must.NoError(t, err)
must.EqOp(t, float64(0.2), f.FloatDef("", "BerserkerPainRatio", -1))
must.EqOp(t, float64(0.2), f.FloatDef(TagSolo, "BerserkerPainRatio", -1))
must.EqOp(t, float64(-1), f.FloatDef("", "BerserkerDamage", -1))
must.EqOp(t, float64(100), f.FloatDef(TagSolo, "BerserkerDamage", -1))
must.EqOp(t, float64(150), f.FloatDef(TagArena, "BerserkerDamage", -1))
must.EqOp(t, float64(0.60), f.FloatDef("", "RepairCoefficient", -1))
must.EqOp(t, float64(150), f.FloatDef(TagArena, "WarriorMaxHealth", -1))
must.Eq(t, []float64{0.5, 0.7, 1.0, 1.3, 1.6}, f.Array(TagSolo, "EnergyBoltDamage"))
must.Eq(t, []float64{1.3, 1.6, 2.0, 2.3, 2.6}, f.Array(TagArena, "EnergyBoltDamage"))
must.Eq(t, []float64{
-1,
0, 5000, 11000, 18200, 26840,
37208, 49650, 64580, 82495, 103995,
Expand Down
32 changes: 16 additions & 16 deletions cfg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/require"
"github.com/shoenig/test/must"

"github.com/noxworld-dev/opennox-lib/noxtest"
)
Expand All @@ -23,16 +23,16 @@ func TestParseConfig(t *testing.T) {
if os.IsNotExist(err) {
t.SkipNow()
}
require.NoError(t, err)
must.NoError(t, err)
data = bytes.ReplaceAll(data, []byte("\r\n"), []byte("\n"))

file, err := Parse(bytes.NewReader(data))
require.NoError(t, err)
require.Len(t, file.Sections, 2)
must.NoError(t, err)
must.SliceLen(t, 2, file.Sections)
vers, _ := file.Sections[0].Get("Version")
require.NotZero(t, vers)
must.NotEqOp(t, "", vers)
mouse, _ := file.Sections[1].Get("MousePickup")
require.NotZero(t, mouse)
must.NotEqOp(t, "", mouse)
})
}
}
Expand Down Expand Up @@ -148,19 +148,19 @@ func TestConfig(t *testing.T) {
c := c
t.Run(c.name, func(t *testing.T) {
file, err := Parse(strings.NewReader(c.text))
require.NoError(t, err)
require.Equal(t, &File{
must.NoError(t, err)
must.Eq(t, &File{
Sections: c.file,
}, file)

var buf bytes.Buffer
err = file.WriteTo(&buf)
require.NoError(t, err)
must.NoError(t, err)
exp := c.text
if c.exp != "" {
exp = c.exp
}
require.Equal(t, exp, buf.String())
must.EqOp(t, exp, buf.String())
})
}
}
Expand All @@ -175,8 +175,8 @@ I+M = ToggleInventory
---
`
file, err := Parse(strings.NewReader(conf))
require.NoError(t, err)
require.Equal(t, &File{
must.NoError(t, err)
must.Eq(t, &File{
Sections: []Section{
{
{Key: "Version", Value: "65537"},
Expand All @@ -191,14 +191,14 @@ I+M = ToggleInventory

var buf bytes.Buffer
err = file.WriteTo(&buf)
require.NoError(t, err)
require.Equal(t, conf, buf.String())
must.NoError(t, err)
must.EqOp(t, conf, buf.String())

buf.Reset()
file.Sections[0].Set("ServerName", "Test")
err = file.WriteTo(&buf)
require.NoError(t, err)
require.Equal(t, `Version = 65537
must.NoError(t, err)
must.EqOp(t, `Version = 65537
# comment
VideoMode = 1024 768 16
ServerName = Test
Expand Down
4 changes: 2 additions & 2 deletions color/rgb555_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package noxcolor
import (
"testing"

"github.com/stretchr/testify/require"
"github.com/shoenig/test/must"
)

func TestRGB555(t *testing.T) {
for i := 0; i < 0x7FFF; i++ {
c := RGB555(i)
cl := c.ColorNRGBA()
c2 := RGB555Color(cl.R, cl.G, cl.B)
require.Equal(t, c, c2, "0x%x", int(c))
must.EqOp(t, c, c2, must.Sprintf("0x%x", int(c)))
}
}
4 changes: 2 additions & 2 deletions color/rgb565_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package noxcolor
import (
"testing"

"github.com/stretchr/testify/require"
"github.com/shoenig/test/must"
)

func TestRGB565(t *testing.T) {
for i := 0; i < 0xFFFF; i++ {
c := RGB565(i)
cl := c.ColorNRGBA()
c2 := RGB565Color(cl.R, cl.G, cl.B)
require.Equal(t, c, c2, "0x%x", int(c))
must.EqOp(t, c, c2, must.Sprintf("0x%x", int(c)))
}
}
4 changes: 2 additions & 2 deletions color/rgba4444_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package noxcolor
import (
"testing"

"github.com/stretchr/testify/require"
"github.com/shoenig/test/must"
)

func TestRGBA4444(t *testing.T) {
for i := 0; i < 0xFFFF; i++ {
c := RGBA4444(i)
cl := c.ColorNRGBA()
c2 := RGBA4444Color(cl.R, cl.G, cl.B, cl.A)
require.Equal(t, c, c2, "0x%x", int(c))
must.EqOp(t, c, c2, must.Sprintf("0x%x", int(c)))
}
}
8 changes: 4 additions & 4 deletions color/rgba5551_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"image/color"
"testing"

"github.com/stretchr/testify/require"
"github.com/shoenig/test/must"
)

func TestRGBA5551(t *testing.T) {
for i := 0; i < 0xFFFF; i++ {
c := RGBA5551(i)
cl := c.ColorNRGBA()
c2 := RGBA5551Color(cl.R, cl.G, cl.B, cl.A)
require.Equal(t, c, c2, "0x%x", int(c))
must.EqOp(t, c, c2, must.Sprintf("0x%x", int(c)))
}
}

Expand All @@ -31,8 +31,8 @@ func TestRGBA5551Builtin(t *testing.T) {
} {
t.Run(c.name, func(t *testing.T) {
got := m.Convert16(c.exp)
require.Equal(t, c.exp16, got)
require.Equal(t, c.exp, c.model.Convert(got))
must.EqOp(t, c.exp16, got)
must.EqOp(t, c.exp, c.model.Convert(got))
})
}
}
4 changes: 2 additions & 2 deletions console/parsecmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package console
import (
"testing"

"github.com/stretchr/testify/require"
"github.com/shoenig/test/must"
)

func TestDecodeSecretToken(t *testing.T) {
got := EncodeSecret("racoiaws")
require.Equal(t, "0YAKikQs", got)
must.EqOp(t, "0YAKikQs", got)
}
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ require (
github.com/noxworld-dev/noxcrypt v0.0.0-20230831140413-02623e75408e
github.com/noxworld-dev/noxscript/eud/v171 v171.3.1
github.com/noxworld-dev/noxscript/ns v1.0.2
github.com/noxworld-dev/noxscript/ns/v3 v3.4.0
github.com/noxworld-dev/noxscript/ns/v3 v3.4.2
github.com/noxworld-dev/noxscript/ns/v4 v4.14.0
github.com/shoenig/test v1.7.0
github.com/spf13/cobra v1.7.0
github.com/stretchr/testify v1.8.4
github.com/traefik/yaegi v0.15.1
github.com/veandco/go-sdl2 v0.5.0-alpha.4
github.com/yuin/gopher-lua v0.0.0-20220504180219-658193537a64
Expand All @@ -26,10 +26,10 @@ require (
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/crypto v0.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/traefik/yaegi => github.com/dennwc/yaegi v0.14.4-0.20230902105020-22e112bbf6e8
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
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/dennwc/yaegi v0.14.4-0.20230902105020-22e112bbf6e8 h1:P9jSJ3tuBZA0ZVljCc5y6ONgvSEfl3ekgiqqE9qW+kg=
github.com/dennwc/yaegi v0.14.4-0.20230902105020-22e112bbf6e8/go.mod h1:pkOs3wa7+hKuTCqPav6dNWzfV5G5ZYK5hl5F9xBHp6I=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 h1:zDw5v7qm4yH7N8C8uWd+8Ii9rROdgWxQuGoJ9WDXxfk=
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6/go.mod h1:9YTyiznxEY1fVinfM7RvRcjRHbw2xLBJ3AAGIT0I4Nw=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b h1:GgabKamyOYguHqHjSkDACcgoPIz3w0Dis/zJ1wyHHHU=
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b/go.mod h1:tQ2UAYgL5IevRw8kRxooKSPJfGvJ9fJQFa0TUsXzTg8=
github.com/go-gl/mathgl v1.0.0 h1:t9DznWJlXxxjeeKLIdovCOVJQk/GzDEL7h/h+Ro2B68=
github.com/go-gl/mathgl v1.0.0/go.mod h1:yhpkQzEiH9yPyxDUGzkmgScbaBVlhC06qodikEM0ZwQ=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/icza/bitio v1.1.0 h1:ysX4vtldjdi3Ygai5m1cWy4oLkhWTAi+SyO6HC8L9T0=
github.com/icza/bitio v1.1.0/go.mod h1:0jGnlLAx8MKMr9VGnn/4YrvZiprkvBelsVIbA9Jjr9A=
github.com/icza/mighty v0.0.0-20180919140131-cfd07d671de6 h1:8UsGZ2rr2ksmEru6lToqnXgA8Mz1DP11X4zSJ159C3k=
Expand All @@ -21,21 +25,21 @@ github.com/noxworld-dev/noxscript/eud/v171 v171.3.1 h1:KRugWrwLY54qiRucyJn3iqvWr
github.com/noxworld-dev/noxscript/eud/v171 v171.3.1/go.mod h1:Aigh/4MqsXvkPY/2JXXaNZghGK8mScpsip3Kdz6EUxE=
github.com/noxworld-dev/noxscript/ns v1.0.2 h1:PMpKqRi3fEhwAfBM+PZVTopT6o2vL6AmCDQH8zV5QWU=
github.com/noxworld-dev/noxscript/ns v1.0.2/go.mod h1:DobGfGPUycvh7D6hB5mW5gbL1QiRsw7QQiVPJz4wYZ0=
github.com/noxworld-dev/noxscript/ns/v3 v3.4.0 h1:YsKB7XCDH6e8MO1+YY+9kBgZAXAGhOaR8vwT1zdoVeA=
github.com/noxworld-dev/noxscript/ns/v3 v3.4.0/go.mod h1:rank2GpncRp/4Z8O2o/02N7dCavOIsq2XEMxZyhBT70=
github.com/noxworld-dev/noxscript/ns/v3 v3.4.2 h1:cvwGW7Cnx7nIurippYXiG17ft3brxjOtW3TWIiLsZ2s=
github.com/noxworld-dev/noxscript/ns/v3 v3.4.2/go.mod h1:oouTgZPYQ/MeLLkpQsYwU7n+oIwfXB4DryLU0UhSj98=
github.com/noxworld-dev/noxscript/ns/v4 v4.14.0 h1:43GYbBgVfVjqVyPrOBwxsNYf25ZGNF08aIXEslsu6/U=
github.com/noxworld-dev/noxscript/ns/v4 v4.14.0/go.mod h1:l8sd8BvVo6LjzYjzAr7V/nbBkp0B/UMQRWbVTq0U67A=
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/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shoenig/test v1.7.0 h1:eWcHtTXa6QLnBvm0jgEabMRN/uJ4DMV3M8xUGgRkZmk=
github.com/shoenig/test v1.7.0/go.mod h1:UxJ6u/x2v/TNs/LoLxBNJRV9DiwBBKYxXSyczsBHFoI=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/traefik/yaegi v0.15.1 h1:YA5SbaL6HZA0Exh9T/oArRHqGN2HQ+zgmCY7dkoTXu4=
github.com/traefik/yaegi v0.15.1/go.mod h1:AVRxhaI2G+nUsaM1zyktzwXn69G3t/AuTDrCiTds9p0=
github.com/veandco/go-sdl2 v0.5.0-alpha.4 h1:+XyPktayFrjYA6n3qUWiQDw6jOVJye27q8gmXvnYAHQ=
github.com/veandco/go-sdl2 v0.5.0-alpha.4/go.mod h1:OROqMhHD43nT4/i9crJukyVecjPNYYuCofep6SNiAjY=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
12 changes: 6 additions & 6 deletions ifs/normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@ import (
"strings"
"testing"

"github.com/stretchr/testify/require"
"github.com/shoenig/test/must"
)

func TestNormalize(t *testing.T) {
dir, err := os.MkdirTemp("", "nox_fs_")
require.NoError(t, err)
must.NoError(t, err)
defer os.RemoveAll(dir)

dir1 := filepath.Join(dir, "AbC", "def")
err = os.MkdirAll(dir1, 0755)
require.NoError(t, err)
must.NoError(t, err)
file1 := filepath.Join(dir1, "File.txt")

err = os.WriteFile(file1, []byte("data"), 0644)
require.NoError(t, err)
must.NoError(t, err)

require.Equal(t,
must.EqOp(t,
file1,
Normalize(strings.Join([]string{dir, "abc", "Def", "FILE.TXT"}, "\\")),
)
require.Equal(t,
must.EqOp(t,
filepath.Join(dir1, "NotExistent"),
Normalize(strings.Join([]string{dir, "ABC", "DeF", "NotExistent"}, "\\")),
)
Expand Down
12 changes: 6 additions & 6 deletions maps/maprender/maprender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"path/filepath"
"testing"

"github.com/stretchr/testify/require"
"github.com/shoenig/test/must"

"github.com/noxworld-dev/opennox-lib/maps"
"github.com/noxworld-dev/opennox-lib/noxtest"
Expand All @@ -23,31 +23,31 @@ var casesMapDraw = []struct {

func TestDraw(t *testing.T) {
r, err := NewRenderer(noxtest.DataPath(t))
require.NoError(t, err)
must.NoError(t, err)
defer r.Close()
path := noxtest.DataPath(t, maps.Dir)
for _, m := range casesMapDraw {
t.Run(m.Name, func(t *testing.T) {
mp, err := maps.ReadMap(filepath.Join(path, m.Name))
require.NoError(t, err)
must.NoError(t, err)
img, err := r.DrawMap(mp, nil)
noxtest.WritePNG(t, m.Name+".png", img, m.Hash)
require.NoError(t, err)
must.NoError(t, err)
})
}
}

func BenchmarkDraw(b *testing.B) {
b.ReportAllocs()
r, err := NewRenderer(noxtest.DataPath(b))
require.NoError(b, err)
must.NoError(b, err)
defer r.Close()
path := noxtest.DataPath(b, maps.Dir)
b.StopTimer()
for _, m := range casesMapDraw {
b.Run(m.Name, func(b *testing.B) {
mp, err := maps.ReadMap(filepath.Join(path, m.Name))
require.NoError(b, err)
must.NoError(b, err)
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = r.DrawMap(mp, nil)
Expand Down
Loading

0 comments on commit e8abe68

Please sign in to comment.