Skip to content

Instantly share code, notes, and snippets.

@hajimehoshi
Created June 1, 2020 01:11
Show Gist options
  • Save hajimehoshi/8de6488aa86761de0849544414e57855 to your computer and use it in GitHub Desktop.
Save hajimehoshi/8de6488aa86761de0849544414e57855 to your computer and use it in GitHub Desktop.
Ebiten loop in tests
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