Created
June 1, 2020 01:11
-
-
Save hajimehoshi/8de6488aa86761de0849544414e57855 to your computer and use it in GitHub Desktop.
Ebiten loop in tests
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 mainWithEbiten(m *testing.M) { | |
g := &game{ | |
m: m, | |
} | |
if err := ebiten.RunGame(g); err != nil && err != regularTermination { | |
panic(err) | |
} | |
os.Exit(g.code) | |
} | |
func TestMain(m *testing.M) { | |
// Run Ebiten's main loop for rendering. | |
mainWithEbiten(m) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment