mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +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"
|
||||
)
|
||||
|
||||
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) {
|
||||
testflock.Lock()
|
||||
defer testflock.Unlock()
|
||||
|
||||
code := 0
|
||||
// Run an Ebiten process so that (*Image).At is available.
|
||||
regularTermination := errors.New("regular termination")
|
||||
f := func(screen *ebiten.Image) error {
|
||||
code = m.Run()
|
||||
return regularTermination
|
||||
g := &game{
|
||||
m: m,
|
||||
}
|
||||
if err := ebiten.Run(f, 320, 240, 1, "Test"); err != nil && err != regularTermination {
|
||||
if err := ebiten.RunGame(g); err != nil && err != regularTermination {
|
||||
panic(err)
|
||||
}
|
||||
os.Exit(code)
|
||||
os.Exit(g.code)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user