Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit 56d8c9b

Browse files
committed
[[ Tests ]] Centralise 'errorDialog' handling
1 parent 779c83f commit 56d8c9b

5 files changed

Lines changed: 23 additions & 25 deletions

File tree

docs/testing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ Before running each test command, the test framework inserts a test library stac
7171
- `pTarget` is the object to which `pHandlerName` should be dispatched.
7272
- `pTimeOut` is the amount of milliseconds to continue testing the result of the handler.
7373
- `pParamsArray` is an array of parameters, keyed by the 1-based index of the required parameter to be passed to the handler.
74-
74+
* `TestAssertErrorDialog pDescription, pErrorCode`: Assert that this test triggers an errorDialog message with the given error.
7575
Tests can have additional setup requirements before running, for example loading custom libraries. If the script test contains a handler called `TestSetup`, this will be run prior to running each test command. For example:
7676
````
7777
on TestSetup

tests/_testlib.livecodescript

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,13 +259,21 @@ on TestAssertDoesNotThrow pDescription, pHandler, pTarget, pParam
259259
TestAssert pDescription, tError is empty
260260
end TestAssertDoesNotThrow
261261

262+
local sError
262263
on ErrorDialog pError
263-
TestAssert "test runs without error - " && line 1 of pError \
264-
, false
265-
TestDiagnostic pError
266-
quit 1
264+
put pError into sError
267265
end ErrorDialog
268266

267+
on TestAssertErrorDialog pDescription, pErrorCode
268+
wait for messages
269+
TestAssert pDescription, __TestErrorMatches(sError, pErrorCode)
270+
put empty into sError
271+
end TestAssertErrorDialog
272+
273+
function TestGetUncaughtErrorDialog
274+
return sError
275+
end TestGetUncaughtErrorDialog
276+
269277
function TestGetEngineRepositoryPath
270278
set the itemdelimiter to "/"
271279
return item 1 to -3 of the filename of me

tests/_testrunner.livecodescript

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,14 @@ private command invokeTest pInfo
185185

186186
-- Do common cleanup tasks
187187
dispatch "TestTearDown" to tStackName
188+
189+
-- Check for uncaught errors
190+
local tError
191+
put TestGetUncaughtErrorDialog() into tError
192+
if tError is not empty then
193+
TestAssert "uncaught error dialog", line 1 of tError
194+
TestDiagnostic tError
195+
end if
188196
end invokeTest
189197

190198
-- Add the unit test library stack and the input library to the backscripts

tests/lcs/core/engine/widget.livecodescript

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,16 @@ end TestWidgetBindErrorsDontEscape
4848

4949
//////////
5050

51-
global gLastSentWidgetError
52-
5351
private command _DoTestWidgetScriptObjectAccess pMode
5452
set the testMode of widget "Test" to pMode
5553

5654
export widget "Test" to array tVar
5755

58-
put empty into gLastSentWidgetError
59-
wait for messages
60-
61-
TestAssert "no script access allowed for" && pMode, gLastSentWidgetError contains "script access not allowed"
56+
TestAssertErrorDialog "no script access allowed for" && pMode, \
57+
"EE_EXTENSION_ERROR_DOMAIN"
6258
end _DoTestWidgetScriptObjectAccess
6359

6460
on TestWidgetScriptObjectAccess
65-
set the lockErrorDialogs to true
6661
create stack "WidgetScriptAccessTest"
6762
set the defaultStack to "WidgetScriptAccessTest"
6863

@@ -75,9 +70,3 @@ on TestWidgetScriptObjectAccess
7570

7671
delete stack "WidgetScriptAccessTest"
7772
end TestWidgetScriptObjectAccess
78-
79-
//////////
80-
81-
on errorDialog pError
82-
put pError into gLastSentWidgetError
83-
end errorDialog

tests/lcs/core/interface/image-undo.livecodescript

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,6 @@ on TestRotateImageWorks
7676
TestAssert "check if undo worked", the prop of this card is not empty
7777
end TestRotateImageWorks
7878

79-
global gLastSentImageError
80-
81-
on errorDialog pError
82-
put pError into gLastSentImageError
83-
end errorDialog
84-
85-
8679
on TestSetTextLockThrows
8780
create stack
8881
set the defaultStack to the short name of it

0 commit comments

Comments
 (0)