Skip to content

Commit 908faa5

Browse files
Tests: Verify alerts automagically; report test failure file/line
1 parent 39d5b4f commit 908faa5

File tree

10 files changed

+78
-43
lines changed

10 files changed

+78
-43
lines changed

tests/alerts.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ test.Step(
1212
a2d.RenamePath("/A2.DESKTOP/READ.ME", "README")
1313
a2dtest.ExpectNothingHappened(function()
1414
a2d.OAShortcut("1")
15-
test.Snap("verify alert shown")
15+
a2dtest.ExpectAlertShowing()
1616
apple2.EscapeKey()
1717
a2d.WaitForRepaint()
1818
end)
@@ -28,7 +28,7 @@ test.Step(
2828
a2dtest.ExpectNothingHappened(function()
2929
apple2.Type("1")
3030
a2d.DialogOK()
31-
test.Snap("verify alert shown")
31+
a2dtest.ExpectAlertShowing()
3232
apple2.EscapeKey()
3333
a2d.WaitForRepaint()
3434
end)
@@ -57,10 +57,10 @@ test.Step(
5757
a2d.DialogOK() -- confirm overwrite
5858
emu.wait(10) -- wait for copy to complete
5959

60-
test.Snap("verify alert shown")
60+
a2dtest.ExpectAlertShowing()
6161
apple2.EscapeKey()
6262
a2d.WaitForRepaint()
63-
test.Snap("verify alert dismissed")
63+
a2dtest.ExpectAlertNotShowing()
6464

6565
a2d.OAShortcut("Q")
6666
a2d.WaitForRestart()

tests/apple_menu.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ test.Step(
5555
local current = drive.filename
5656
drive:unload()
5757
a2d.InvokeMenuItem(a2d.APPLE_MENU, a2d.CALCULATOR)
58-
test.Snap("verify alert shown")
58+
a2dtest.ExpectAlertShowing()
5959
drive:load(current)
6060
a2d.DialogOK()
6161
test.ExpectEquals(a2dtest.GetFrontWindowTitle(), "Calc", "Calculator should be open")
@@ -69,7 +69,7 @@ test.Step(
6969
local current = drive.filename
7070
drive:unload()
7171
a2d.InvokeMenuItem(a2d.APPLE_MENU, a2d.CONTROL_PANELS)
72-
test.Snap("verify alert shown")
72+
a2dtest.ExpectAlertShowing()
7373
drive:load(current)
7474
a2d.DialogOK()
7575
test.ExpectEqualsIgnoreCase(a2dtest.GetFrontWindowTitle(), "CONTROL.PANELS", "Control Panels window should be open")

tests/change_type.lua

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ test.Step(
1414
apple2.DeleteKey()
1515
apple2.Type("06")
1616
a2d.DialogOK()
17-
test.Snap("verify alert shown")
17+
a2dtest.ExpectAlertShowing()
1818
a2d.DialogOK()
1919
end)
2020

@@ -30,7 +30,7 @@ test.Step(
3030
apple2.DeleteKey()
3131
apple2.Type("8000")
3232
a2d.DialogOK()
33-
test.Snap("verify no alert shown")
33+
a2dtest.ExpectAlertNotShowing()
3434
end)
3535

3636
test.Step(
@@ -44,7 +44,7 @@ test.Step(
4444
apple2.DeleteKey()
4545
apple2.Type("06")
4646
a2d.DialogOK()
47-
test.Snap("verify alert shown")
47+
a2dtest.ExpectAlertShowing()
4848
a2d.DialogOK()
4949
test.Snap("verify only non-folders are modified")
5050
end)
@@ -63,7 +63,7 @@ test.Step(
6363
apple2.DeleteKey()
6464
apple2.Type("8000")
6565
a2d.DialogOK()
66-
test.Snap("verify no alert shown")
66+
a2dtest.ExpectAlertNotShowing()
6767
end)
6868

6969
test.Step(
@@ -75,7 +75,7 @@ test.Step(
7575
apple2.DeleteKey()
7676
apple2.Type("0F")
7777
a2d.DialogOK()
78-
test.Snap("verify alert shown")
78+
a2dtest.ExpectAlertShowing()
7979
a2d.DialogOK()
8080
end)
8181

@@ -88,12 +88,12 @@ test.Step(
8888
apple2.DeleteKey()
8989
apple2.Type("0F")
9090
a2d.DialogOK()
91-
test.Snap("verify alert shown")
91+
a2dtest.ExpectAlertShowing()
9292
a2d.DialogOK()
9393
end)
9494

9595
test.Step(
96-
"Single error when modifying folder types",
96+
"Single alert when modifying folder types",
9797
function()
9898
a2d.OpenPath("/TESTS/FILE.TYPES/FOLDER")
9999
a2d.SelectAll()
@@ -102,7 +102,7 @@ test.Step(
102102
apple2.DeleteKey()
103103
apple2.Type("06")
104104
a2d.DialogOK()
105-
test.Snap("verify alert shown")
105+
a2dtest.ExpectAlertShowing()
106106
a2d.DialogOK()
107-
test.Snap("only a single alert was shown")
107+
a2dtest.ExpectAlertNotShowing()
108108
end)

tests/check_all_drives.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ test.Step(
1010
function()
1111
a2d.InvokeMenuItem(a2d.SPECIAL_MENU, a2d.SPECIAL_CHECK_ALL_DRIVES)
1212
a2d.WaitForRepaint()
13-
test.Snap("verify no alert shown")
13+
a2dtest.ExpectAlertNotShowing()
1414
end)

tests/control_panel.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ test.Step(
4343

4444
a2d.CloseWindow()
4545
a2d.WaitForRepaint()
46-
test.Snap("verify no prompt to save")
46+
a2dtest.ExpectAlertNotShowing()
4747

4848
drive:load(current)
4949
a2d.CloseAllWindows()
@@ -61,7 +61,7 @@ test.Step(
6161

6262
a2d.CloseWindow()
6363
a2d.WaitForRepaint()
64-
test.Snap("verify prompt to save")
64+
a2dtest.ExpectAlertShowing()
6565
a2d.DialogCancel()
6666

6767
drive:load(current)

tests/investigations.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ test.Step(
3939
drive:unload()
4040

4141
a2d.OpenPath("/FLOPPY1")
42-
test.Snap("verify alert shown")
42+
a2dtest.ExpectAlertShown()
4343
apple2.EscapeKey()
4444

4545
--[[
@@ -53,7 +53,7 @@ test.Step(
5353
CPU seems to still be chugging along, albeit in $C8xx space
5454
]]--
5555

56-
test.Snap("verify alert dismissed")
56+
a2dtest.ExpectAlertNotShown()
5757
emu.wait(60)
5858
test.Snap("Waited a long time")
5959
apple2.Type("TRASH")

tests/lib/a2dtest.lua

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function a2dtest.ExpectNothingHappened(func)
2727
local bytes = apple2.SnapshotDHR()
2828
func()
2929
EraseClock()
30-
test.Expect(apple2.CompareDHR(bytes), "nothing should have changed", {snap=true})
30+
test.Expect(apple2.CompareDHR(bytes), "nothing should have changed", {snap=true}, 1)
3131
end
3232

3333
--------------------------------------------------
@@ -45,24 +45,24 @@ local function RepaintFraction()
4545
end
4646

4747
function a2dtest.ExpectFullRepaint(func)
48-
a2dtest.ExpectRepaintFraction(0.9, 1.0, func, "should be full repaint")
48+
a2dtest.ExpectRepaintFraction(0.9, 1.0, func, "should be full repaint", 1)
4949
end
5050

5151
function a2dtest.ExpectMinimalRepaint(func)
52-
a2dtest.ExpectRepaintFraction(0, 0.5, func, "should be minimal repaint")
52+
a2dtest.ExpectRepaintFraction(0, 0.5, func, "should be minimal repaint", 1)
5353
end
5454

5555
function a2dtest.ExpectNoRepaint(func)
56-
a2dtest.ExpectRepaintFraction(0, 0.01, func, "should not have repainted")
56+
a2dtest.ExpectRepaintFraction(0, 0.01, func, "should not have repainted", 1)
5757
end
5858

59-
function a2dtest.ExpectRepaintFraction(min, max, func, message)
59+
function a2dtest.ExpectRepaintFraction(min, max, func, message, level)
6060
apple2.DHRDarkness()
6161
func()
6262
local fraction = RepaintFraction()
6363
test.Expect(min <= fraction and fraction <= max,
6464
string.format("%s - diff about %d%%", message, math.floor(fraction * 100)),
65-
{snap=true})
65+
{snap=true}, level and level+1 or 1)
6666
end
6767

6868
--------------------------------------------------
@@ -119,4 +119,29 @@ end
119119

120120
--------------------------------------------------
121121

122+
-- This scans for the left side of the alert bitmap at expected screen address
123+
function a2dtest.IsAlertShowing()
124+
local bytes = {0x7F,0x7F,0x7F,0x3F,0x00,0x00,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x4F,0x0F,0x3F,0x4F,0x0F,0x3F,0x4F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x7F,0x0F,0x3F,0x1F,0x00,0x3F,0x7F,0x01,0x3F,0x7F,0x01,0x3F,0x07,0x70,0x3F,0x7F,0x01,0x3F,0x7F,0x01,0x3F,0x00,0x00,0x7F,0x7F,0x7F}
125+
local index = 1
126+
for row = 75,100 do
127+
for col = 12,14 do
128+
if bytes[index] ~= apple2.GetDoubleHiresByte(row,col) then
129+
return false
130+
end
131+
index = index + 1
132+
end
133+
end
134+
return true
135+
end
136+
137+
function a2dtest.ExpectAlertShowing()
138+
test.Expect(a2dtest.IsAlertShowing(), "an alert should be showing", nil, 1)
139+
end
140+
141+
function a2dtest.ExpectAlertNotShowing()
142+
test.Expect(not a2dtest.IsAlertShowing(), "an alert should not be showing", nil, 1)
143+
end
144+
145+
--------------------------------------------------
146+
122147
return a2dtest

tests/lib/test.lua

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,21 @@ end
8080
-- Expectations
8181
--------------------------------------------------
8282

83-
function test.Expect(expr, message, options)
83+
local function inc(level)
84+
if level then
85+
return level + 1
86+
else
87+
return 1
88+
end
89+
end
90+
91+
92+
function test.Expect(expr, message, options, level)
8493
if not expr then
8594
if options and options.snap then
8695
test.Snap("FAILURE - " .. message)
8796
end
88-
error("Expectation failure: " .. message)
97+
error("Expectation failure: " .. message, inc(inc(level)))
8998
end
9099
end
91100

@@ -99,24 +108,24 @@ local function format(value)
99108
end
100109
end
101110

102-
function test.ExpectEquals(actual, expected, message, options)
103-
test.Expect(actual == expected, message .. " - actual " .. format(actual) .. " should equal " .. format(expected), options)
111+
function test.ExpectEquals(actual, expected, message, options, level)
112+
test.Expect(actual == expected, message .. " - actual " .. format(actual) .. " should equal " .. format(expected), options, inc(level))
104113
end
105114

106-
function test.ExpectEqualsIgnoreCase(actual, expected, message, options)
107-
test.Expect(actual:lower() == expected:lower(), message .. " - actual " .. format(actual) .. " should equal " .. format(expected), options)
115+
function test.ExpectEqualsIgnoreCase(actual, expected, message, options, level)
116+
test.Expect(actual:lower() == expected:lower(), message .. " - actual " .. format(actual) .. " should equal " .. format(expected), options, inc(level))
108117
end
109118

110-
function test.ExpectNotEquals(actual, expected, message, options)
111-
test.Expect(actual ~= expected, message .. " - actual " .. format(actual) .. " should not equal " .. format(expected), options)
119+
function test.ExpectNotEquals(actual, expected, message, options, level)
120+
test.Expect(actual ~= expected, message .. " - actual " .. format(actual) .. " should not equal " .. format(expected), options, inc(level))
112121
end
113122

114-
function test.ExpectLessThan(a, b, message, options)
115-
test.Expect(a < b, message .. " - actual " .. format(a) .. " should be < " .. format(b), options)
123+
function test.ExpectLessThan(a, b, message, options, level)
124+
test.Expect(a < b, message .. " - actual " .. format(a) .. " should be < " .. format(b), options, inc(level))
116125
end
117126

118-
function test.ExpectLessThanOrEqual(a, b, message, options)
119-
test.Expect(a <= b, message .. " - actual " .. format(a) .. " should be <= " .. format(b), options)
127+
function test.ExpectLessThanOrEqual(a, b, message, options, level)
128+
test.Expect(a <= b, message .. " - actual " .. format(a) .. " should be <= " .. format(b), options, inc(level))
120129
end
121130

122131
--------------------------------------------------

tests/menus.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,8 @@ end)
284284
test.Step(
285285
"Control-Shift-2 doesn't show first menu item without shortcut",
286286
function()
287-
apple2.ControlKey("@")
288-
a2d.WaitForRepaint()
289-
test.Snap("verify About dialog not showing")
287+
a2dtest.ExpectNothingHappened(function()
288+
apple2.ControlKey("@")
289+
a2d.WaitForRepaint()
290+
end)
290291
end)

tests/screen_savers.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ test.Step(
7171
"Analog Clock shows alert if there is no system clock",
7272
function()
7373
a2d.OpenPath("/A2.DESKTOP/APPLE.MENU/SCREEN.SAVERS/ANALOG.CLOCK")
74-
test.Snap("verify alert shown")
74+
a2dtest.ExpectAlertShowing()
7575
a2d.DialogOK()
7676
a2d.CloseAllWindows()
7777
end)
@@ -80,7 +80,7 @@ test.Step(
8080
"Digital Clock shows alert if there is no system clock",
8181
function()
8282
a2d.OpenPath("/A2.DESKTOP/APPLE.MENU/SCREEN.SAVERS/DIGITAL.CLOCK")
83-
test.Snap("verify alert shown")
83+
a2dtest.ExpectAlertShowing()
8484
a2d.DialogOK()
8585
a2d.CloseAllWindows()
8686
end)

0 commit comments

Comments
 (0)