mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Add testing package
This commit is contained in:
parent
9302160486
commit
47d5c3b5e1
@ -15,32 +15,17 @@
|
||||
package graphicscommand_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"image/color"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
. "github.com/hajimehoshi/ebiten/internal/graphicscommand"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
t "github.com/hajimehoshi/ebiten/internal/testing"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
testflock.Lock()
|
||||
defer testflock.Unlock()
|
||||
|
||||
code := 0
|
||||
regularTermination := errors.New("regular termination")
|
||||
f := func(screen *ebiten.Image) error {
|
||||
code = m.Run()
|
||||
return regularTermination
|
||||
}
|
||||
if err := ebiten.Run(f, 320, 240, 1, "Test"); err != nil && err != regularTermination {
|
||||
panic(err)
|
||||
}
|
||||
os.Exit(code)
|
||||
t.MainWithRunLoop(m)
|
||||
}
|
||||
|
||||
func quadVertices(w, h float32) []float32 {
|
||||
|
@ -15,34 +15,19 @@
|
||||
package restorable_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"image"
|
||||
"image/color"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
. "github.com/hajimehoshi/ebiten/internal/restorable"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
t "github.com/hajimehoshi/ebiten/internal/testing"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
testflock.Lock()
|
||||
defer testflock.Unlock()
|
||||
|
||||
EnableRestoringForTesting()
|
||||
code := 0
|
||||
regularTermination := errors.New("regular termination")
|
||||
f := func(screen *ebiten.Image) error {
|
||||
code = m.Run()
|
||||
return regularTermination
|
||||
}
|
||||
if err := ebiten.Run(f, 320, 240, 1, "Test"); err != nil && err != regularTermination {
|
||||
panic(err)
|
||||
}
|
||||
os.Exit(code)
|
||||
t.MainWithRunLoop(m)
|
||||
}
|
||||
|
||||
func pixelsToColor(p *Pixels, i, j int) color.RGBA {
|
||||
|
@ -15,33 +15,18 @@
|
||||
package shareable_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"image/color"
|
||||
"os"
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/driver"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
. "github.com/hajimehoshi/ebiten/internal/shareable"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
t "github.com/hajimehoshi/ebiten/internal/testing"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
testflock.Lock()
|
||||
defer testflock.Unlock()
|
||||
|
||||
code := 0
|
||||
regularTermination := errors.New("regular termination")
|
||||
f := func(screen *ebiten.Image) error {
|
||||
code = m.Run()
|
||||
return regularTermination
|
||||
}
|
||||
if err := ebiten.Run(f, 320, 240, 1, "Test"); err != nil && err != regularTermination {
|
||||
panic(err)
|
||||
}
|
||||
os.Exit(code)
|
||||
t.MainWithRunLoop(m)
|
||||
}
|
||||
|
||||
func quadVertices(sw, sh, x, y int, scalex float32) []float32 {
|
||||
|
41
internal/testing/testing.go
Normal file
41
internal/testing/testing.go
Normal file
@ -0,0 +1,41 @@
|
||||
// Copyright 2020 The Ebiten Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package testing
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
)
|
||||
|
||||
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
|
||||
}
|
||||
if err := ebiten.Run(f, 320, 240, 1, "Test"); err != nil && err != regularTermination {
|
||||
panic(err)
|
||||
}
|
||||
os.Exit(code)
|
||||
}
|
@ -15,33 +15,18 @@
|
||||
package text_test
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"image/color"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/hajimehoshi/bitmapfont"
|
||||
|
||||
"github.com/hajimehoshi/ebiten"
|
||||
"github.com/hajimehoshi/ebiten/internal/testflock"
|
||||
t "github.com/hajimehoshi/ebiten/internal/testing"
|
||||
. "github.com/hajimehoshi/ebiten/text"
|
||||
)
|
||||
|
||||
func TestMain(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
|
||||
}
|
||||
if err := ebiten.Run(f, 320, 240, 1, "Test"); err != nil && err != regularTermination {
|
||||
panic(err)
|
||||
}
|
||||
os.Exit(code)
|
||||
t.MainWithRunLoop(m)
|
||||
}
|
||||
|
||||
func TestTextColor(t *testing.T) {
|
||||
|
Loading…
Reference in New Issue
Block a user