mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
buffered: Use RunGame for tests
This commit is contained in:
parent
16280e9a5a
commit
ab94cebd02
@ -34,6 +34,31 @@ func runOnMainThread(f func()) {
|
||||
<-ch
|
||||
}
|
||||
|
||||
var regularTermination = errors.New("regular termination")
|
||||
|
||||
type game struct {
|
||||
m *testing.M
|
||||
endCh chan struct{}
|
||||
code int
|
||||
}
|
||||
|
||||
func (g *game) Update(*ebiten.Image) error {
|
||||
select {
|
||||
case f := <-mainCh:
|
||||
f()
|
||||
case <-g.endCh:
|
||||
return regularTermination
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (*game) Draw(*ebiten.Image) {
|
||||
}
|
||||
|
||||
func (*game) Layout(int, int) (int, int) {
|
||||
return 320, 240
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
codeCh := make(chan int)
|
||||
endCh := make(chan struct{})
|
||||
@ -44,16 +69,11 @@ func TestMain(m *testing.M) {
|
||||
close(codeCh)
|
||||
}()
|
||||
|
||||
rt := errors.New("regular termination")
|
||||
if err := ebiten.Run(func(*ebiten.Image) error {
|
||||
select {
|
||||
case f := <-mainCh:
|
||||
f()
|
||||
case <-endCh:
|
||||
return rt
|
||||
g := &game{
|
||||
m: m,
|
||||
endCh: endCh,
|
||||
}
|
||||
return nil
|
||||
}, 320, 240, 1, ""); err != nil && err != rt {
|
||||
if err := ebiten.RunGame(g); err != nil && err != regularTermination {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user