Skip to content

Commit c8e99c0

Browse files
Tests: Let --only specify a pattern; helpers for window grow/move
1 parent e9a4806 commit c8e99c0

File tree

5 files changed

+42
-10
lines changed

5 files changed

+42
-10
lines changed

bin/mametest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#
77
# Options
88
#
9-
# --only NAME Run only the named test step
9+
# --only PATTERN Run only matching named test steps (wildcards * and ?)
1010
# --visible Don't run headless (i.e. do present video)
1111
# --audible Don't run silent (i.e. do present audio)
1212
# --nosnaps Don't show snapshots once tests are complete

tests/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ bin/mametest tests/SCRIPTNAME.lua
1616

1717
Options:
1818

19-
* `--only NAME` - run only the named test step; useful for fast iteration
19+
* `--only PATTERN` - run only matching named test step (`*` and `?` are wildcards); useful for fast iteration
2020
* `--console` - don't ask MAME to run the script (but do load its config, see below), launch the Lua console instead
2121
* `--visible` - show the emulator window (default is headless)
2222
* `--audible` - play the emulator audio (default is silent)

tests/date_and_time.lua

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,13 +327,8 @@ test.Step(
327327
-- Show window and resize/move it
328328
a2d.OpenPath("/RAM1")
329329
a2d.InvokeMenuItem(a2d.VIEW_MENU, a2d.VIEW_BY_NAME)
330-
a2d.OAShortcut("G") -- grow window
331-
for i=1,35 do apple2.RightArrowKey() end
332-
apple2.ReturnKey()
333-
a2d.OAShortcut("M") -- move window
334-
for i=1,25 do apple2.DownArrowKey() end
335-
apple2.ReturnKey()
336-
a2d.WaitForRepaint()
330+
a2d.GrowWindowBy(250,0)
331+
a2d.MoveWindowBy(0,100)
337332
test.Snap("verify date is shown in full")
338333

339334
-- Use Date & Time to set date

tests/lib/a2d.lua

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ function a2d.InMouseKeysMode(func)
338338
ButtonUp = a2d.MouseKeysButtonUp,
339339
Click = a2d.MouseKeysClick,
340340
DoubleClick = a2d.MouseKeysDoubleClick,
341+
OAClick = a2d.MouseKeysOAClick,
341342

342343
Up = a2d.MouseKeysUp,
343344
Down = a2d.MouseKeysDown,
@@ -366,6 +367,14 @@ function a2d.MouseKeysClick()
366367
emu.wait(1/60)
367368
end
368369

370+
function a2d.MouseKeysOAClick()
371+
apple2.PressOA()
372+
emu.wait(1/60)
373+
a2d.MouseKeysClick()
374+
emu.wait(1/60)
375+
apple2.ReleaseOA()
376+
end
377+
369378
function a2d.MouseKeysUp(n)
370379
for i=1,n do
371380
apple2.UpArrowKey()
@@ -427,6 +436,20 @@ function a2d.MouseKeysMoveByApproximately(x,y)
427436
end
428437
end
429438

439+
function a2d.MoveWindowBy(x, y)
440+
a2d.OAShortcut("M")
441+
a2d.MouseKeysMoveByApproximately(x,y)
442+
apple2.ReturnKey()
443+
a2d.WaitForRepaint()
444+
end
445+
446+
function a2d.GrowWindowBy(x, y)
447+
a2d.OAShortcut("G")
448+
a2d.MouseKeysMoveByApproximately(x,y)
449+
apple2.ReturnKey()
450+
a2d.WaitForRepaint()
451+
end
452+
430453
--------------------------------------------------
431454
-- Modifier Key Combos
432455
--------------------------------------------------

tests/lib/test.lua

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77
local test = {}
88

99
local test_name = emu.subst_env("$TEST_NAME")
10+
-- Convert from "wildcard" pattern (with * and ?) to Lua pattern
11+
local test_pattern = "^" ..
12+
string.gsub(
13+
test_name, "([%^$()%%.%[%]*+%-?])", -- pattern special characters
14+
function(s)
15+
if s == "*" then
16+
return ".*"
17+
elseif s == "?" then
18+
return "."
19+
else
20+
return "%" .. s
21+
end
22+
end) .. "$"
23+
1024
test.count = 0
1125

1226
local snapnum = -1
@@ -23,7 +37,7 @@ end
2337

2438
-- test.Step("do a thing", function() ... end)
2539
function test.Step(title, func)
26-
if test_name ~= "" and test_name ~= title then
40+
if test_name ~= "" and not string.match(title, test_pattern) then
2741
return
2842
end
2943
test.count = test.count+1

0 commit comments

Comments
 (0)