mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 18:52:44 +01:00
testing: Use RunGame
This commit is contained in:
parent
47d5c3b5e1
commit
16280e9a5a
@ -23,19 +23,35 @@ import (
|
|||||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var regularTermination = errors.New("regular termination")
|
||||||
|
|
||||||
|
type game struct {
|
||||||
|
m *testing.M
|
||||||
|
code int
|
||||||
|
}
|
||||||
|
|
||||||
|
func (g *game) Update(*ebiten.Image) error {
|
||||||
|
g.code = g.m.Run()
|
||||||
|
return regularTermination
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*game) Draw(*ebiten.Image) {
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*game) Layout(int, int) (int, int) {
|
||||||
|
return 320, 240
|
||||||
|
}
|
||||||
|
|
||||||
func MainWithRunLoop(m *testing.M) {
|
func MainWithRunLoop(m *testing.M) {
|
||||||
testflock.Lock()
|
testflock.Lock()
|
||||||
defer testflock.Unlock()
|
defer testflock.Unlock()
|
||||||
|
|
||||||
code := 0
|
|
||||||
// Run an Ebiten process so that (*Image).At is available.
|
// Run an Ebiten process so that (*Image).At is available.
|
||||||
regularTermination := errors.New("regular termination")
|
g := &game{
|
||||||
f := func(screen *ebiten.Image) error {
|
m: m,
|
||||||
code = m.Run()
|
|
||||||
return regularTermination
|
|
||||||
}
|
}
|
||||||
if err := ebiten.Run(f, 320, 240, 1, "Test"); err != nil && err != regularTermination {
|
if err := ebiten.RunGame(g); err != nil && err != regularTermination {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
os.Exit(code)
|
os.Exit(g.code)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user