Skip to content

Commit

Permalink
test: Move feature tests to test dir
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Aug 25, 2024
1 parent b7699f9 commit 97f7697
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 132 deletions.
4 changes: 2 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "internal/console/nes-test-roms"]
path = internal/console/nes-test-roms
[submodule "test/roms"]
path = test/roms
url = https://github.com/christopherpow/nes-test-roms.git
8 changes: 4 additions & 4 deletions internal/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
)

type Console struct {
config *config.Config
Config *config.Config `msgpack:"-"`

CPU *cpu.CPU
Bus *bus.Bus
Expand All @@ -61,7 +61,7 @@ type Console struct {

func New(conf *config.Config, cart *cartridge.Cartridge) (*Console, error) {
console := Console{
config: conf,
Config: conf,
Cartridge: cart,
rate: 1,

Expand Down Expand Up @@ -129,7 +129,7 @@ func (c *Console) Close() error {
if c.autosave != nil {
c.autosave.Stop()
}
if c.config.State.Resume {
if c.Config.State.Resume {
errs = append(errs, c.SaveStateNum(AutoSaveNum, false))
}
errs = append(errs, c.SaveSRAM())
Expand Down Expand Up @@ -220,7 +220,7 @@ func (c *Console) Update() error {
if err := c.SaveSRAM(); err != nil {
slog.Error("Auto-save failed", "error", err)
}
if c.config.State.Resume {
if c.Config.State.Resume {
if err := c.SaveStateNum(AutoSaveNum, false); err != nil {
slog.Error("State auto-save failed", "error", err)
}
Expand Down
49 changes: 0 additions & 49 deletions internal/console/console_helpers_test.go

This file was deleted.

40 changes: 0 additions & 40 deletions internal/console/console_test.go

This file was deleted.

26 changes: 13 additions & 13 deletions internal/console/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import (
func (c *Console) CheckInput() {
c.Bus.UpdateInput()

if duration := inpututil.KeyPressDuration(ebiten.Key(c.config.Input.Reset)); duration != 0 {
if duration == c.config.Input.ResetHoldFrames() {
if duration := inpututil.KeyPressDuration(ebiten.Key(c.Config.Input.Reset)); duration != 0 {
if duration == c.Config.Input.ResetHoldFrames() {
c.Reset()
}
}

if inpututil.IsKeyJustPressed(ebiten.Key(c.config.Input.FastForward)) {
if inpututil.IsKeyJustPressed(ebiten.Key(c.Config.Input.FastForward)) {
if c.player != nil {
c.player.SetVolume(c.config.Audio.Volume / 2)
c.player.SetVolume(c.Config.Audio.Volume / 2)
}
c.SetRate(c.config.Input.FastForwardRate)
} else if inpututil.IsKeyJustReleased(ebiten.Key(c.config.Input.FastForward)) {
c.SetRate(c.Config.Input.FastForwardRate)
} else if inpututil.IsKeyJustReleased(ebiten.Key(c.Config.Input.FastForward)) {
c.SetRate(1)
if c.player != nil {
c.player.SetVolume(c.config.Audio.Volume)
c.player.SetVolume(c.Config.Audio.Volume)
}
}

Expand Down Expand Up @@ -57,17 +57,17 @@ func (c *Console) CheckInput() {
}
}

if inpututil.IsKeyJustPressed(ebiten.Key(c.config.Input.Screenshot)) {
if inpututil.IsKeyJustPressed(ebiten.Key(c.Config.Input.Screenshot)) {
c.willScreenshot = true
}
}

if inpututil.IsKeyJustPressed(ebiten.Key(c.config.Input.Fullscreen)) {
if inpututil.IsKeyJustPressed(ebiten.Key(c.Config.Input.Fullscreen)) {
ebiten.SetFullscreen(!ebiten.IsFullscreen())
}

if inpututil.IsKeyJustPressed(ebiten.Key(c.config.Input.State1Save)) {
if ebiten.IsKeyPressed(ebiten.Key(c.config.Input.StateUndoModifier)) {
if inpututil.IsKeyJustPressed(ebiten.Key(c.Config.Input.State1Save)) {
if ebiten.IsKeyPressed(ebiten.Key(c.Config.Input.StateUndoModifier)) {
if err := c.UndoSaveState(); err == nil {
slog.Info("Undo save state")
} else {
Expand All @@ -80,8 +80,8 @@ func (c *Console) CheckInput() {
}
}

if inpututil.IsKeyJustPressed(ebiten.Key(c.config.Input.State1Load)) {
if ebiten.IsKeyPressed(ebiten.Key(c.config.Input.StateUndoModifier)) {
if inpututil.IsKeyJustPressed(ebiten.Key(c.Config.Input.State1Load)) {
if ebiten.IsKeyPressed(ebiten.Key(c.Config.Input.StateUndoModifier)) {
if err := c.UndoLoadState(); err == nil {
slog.Info("Undo load state")
} else {
Expand Down
4 changes: 2 additions & 2 deletions internal/console/savestate_all.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (c *Console) LoadState(r io.Reader) error {
var ErrNoPreviousState = errors.New("no previous state available")

func (c *Console) CreateUndoSaveState(oldState []byte) error {
if len(c.undoSaveStates) >= c.config.State.UndoStateCount {
if len(c.undoSaveStates) >= c.Config.State.UndoStateCount {
c.undoSaveStates = slices.Delete(c.undoSaveStates, 0, 1)
}
c.undoSaveStates = append(c.undoSaveStates, oldState)
Expand Down Expand Up @@ -94,7 +94,7 @@ func (c *Console) CreateUndoLoadState() error {
return err
}

if len(c.undoLoadStates) >= c.config.State.UndoStateCount {
if len(c.undoLoadStates) >= c.Config.State.UndoStateCount {
c.undoLoadStates = slices.Delete(c.undoLoadStates, 0, 1)
}
c.undoLoadStates = append(c.undoLoadStates, buf.Bytes())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package console
package test

import (
"bytes"
"io"
"regexp"

"github.com/gabe565/gones/internal/console"
)

type Status int16
Expand All @@ -28,7 +30,7 @@ func BlarggCallback(b *ConsoleTest) error {
b.ResetIn = 6
b.Console.Bus.WriteMem(0x6000, byte(StatusRunning))
default:
return ErrExit
return console.ErrExit
}
return nil
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package console
package test

import (
_ "embed"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

//go:embed nes-test-roms/apu_reset/4015_cleared.nes
//go:embed roms/apu_reset/4015_cleared.nes
var blarggAPURst4015Clr string

func Test_blarggAPURst4015Clr(t *testing.T) {
Expand All @@ -23,7 +23,7 @@ func Test_blarggAPURst4015Clr(t *testing.T) {
assert.EqualValues(t, "4015_cleared\n\nPassed", GetBlarggMessage(test))
}

//go:embed nes-test-roms/apu_reset/irq_flag_cleared.nes
//go:embed roms/apu_reset/irq_flag_cleared.nes
var blarggIRQClr string

func Test_blarggIRQClr(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package console
package test

import (
_ "embed"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

//go:embed nes-test-roms/instr_test-v5/all_instrs.nes
//go:embed roms/instr_test-v5/all_instrs.nes
var blarggInstrTest string

func Test_blarggCPUTest(t *testing.T) {
Expand All @@ -23,7 +23,7 @@ func Test_blarggCPUTest(t *testing.T) {
assert.EqualValues(t, "All 16 tests passed", GetBlarggMessage(test))
}

//go:embed nes-test-roms/cpu_timing_test6/cpu_timing_test.nes
//go:embed roms/cpu_timing_test6/cpu_timing_test.nes
var blarggCPUTimingTest string

const blarggCPUTimingSuccess = `6502 TIMING TEST (16 SECONDS)
Expand All @@ -43,7 +43,7 @@ func Test_blarggCPUTiming(t *testing.T) {
assert.EqualValues(t, blarggCPUTimingSuccess, err.Error())
}

//go:embed nes-test-roms/branch_timing_tests/1.Branch_Basics.nes
//go:embed roms/branch_timing_tests/1.Branch_Basics.nes
var blarggBranchTimingBasicsTest string

func Test_blarggBranchTimingBasics(t *testing.T) {
Expand All @@ -59,7 +59,7 @@ func Test_blarggBranchTimingBasics(t *testing.T) {
assert.EqualValues(t, "BRANCH TIMING BASICS\nPASSED", err.Error())
}

//go:embed nes-test-roms/branch_timing_tests/2.Backward_Branch.nes
//go:embed roms/branch_timing_tests/2.Backward_Branch.nes
var blarggBranchTimingBackwardTest string

func Test_blarggBranchTimingBackward(t *testing.T) {
Expand All @@ -75,7 +75,7 @@ func Test_blarggBranchTimingBackward(t *testing.T) {
assert.EqualValues(t, "BACKWARD BRANCH TIMING\nPASSED", err.Error())
}

//go:embed nes-test-roms/branch_timing_tests/3.Forward_Branch.nes
//go:embed roms/branch_timing_tests/3.Forward_Branch.nes
var blarggBranchTimingForwardTest string

func Test_blarggBranchTimingForward(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package console
package test

import (
_ "embed"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

//go:embed nes-test-roms/oam_read/oam_read.nes
//go:embed roms/oam_read/oam_read.nes
var oamRead string

const oamReadSuccess = `----------------
Expand Down Expand Up @@ -44,7 +44,7 @@ func Test_oamRead(t *testing.T) {
assert.EqualValues(t, oamReadSuccess, GetBlarggMessage(test))
}

//go:embed nes-test-roms/oam_stress/oam_stress.nes
//go:embed roms/oam_stress/oam_stress.nes
var oamStress string

const oamStressSuccess = `----------------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package console
package test

import (
_ "embed"
Expand All @@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
)

//go:embed nes-test-roms/ppu_open_bus/ppu_open_bus.nes
//go:embed roms/ppu_open_bus/ppu_open_bus.nes
var blarggPPUOpenBus string

func Test_blarggPPUOpenBus(t *testing.T) {
Expand All @@ -23,7 +23,7 @@ func Test_blarggPPUOpenBus(t *testing.T) {
assert.EqualValues(t, "ppu_open_bus\n\nPassed", GetBlarggMessage(test))
}

//go:embed nes-test-roms/ppu_vbl_nmi/ppu_vbl_nmi.nes
//go:embed roms/ppu_vbl_nmi/ppu_vbl_nmi.nes
var blarggPPUVblNMI string

const blarggPPUVblNMISuccess = `08 07
Expand Down
Loading

0 comments on commit 97f7697

Please sign in to comment.