@@ -7,7 +7,7 @@ local vfs = require('openmw.vfs')
77local world = require (' openmw.world' )
88local I = require (' openmw.interfaces' )
99
10- local function testTimers ()
10+ testing . registerGlobalTest ( ' timers ' , function ()
1111 testing .expectAlmostEqual (core .getGameTimeScale (), 30 , ' incorrect getGameTimeScale() result' )
1212 testing .expectAlmostEqual (core .getSimulationTimeScale (), 1 , ' incorrect getSimulationTimeScale result' )
1313
@@ -39,9 +39,10 @@ local function testTimers()
3939 testing .expectGreaterOrEqual (ts1 , 0.5 , ' async:newSimulationTimer failed' )
4040 testing .expectGreaterOrEqual (th2 , 72 , ' async:newUnsavableGameTimer failed' )
4141 testing .expectGreaterOrEqual (ts2 , 1 , ' async:newUnsavableSimulationTimer failed' )
42- end
42+ end )
4343
44- local function testTeleport ()
44+ testing .registerGlobalTest (' teleport' , function ()
45+ local player = world .players [1 ]
4546 player :teleport (' ' , util .vector3 (100 , 50 , 500 ), util .transform .rotateZ (math.rad (90 )))
4647 coroutine.yield ()
4748 testing .expect (player .cell .isExterior , ' teleport to exterior failed' )
@@ -71,16 +72,16 @@ local function testTeleport()
7172 testing .expectEqualWithDelta (player .position .x , 50 , 1 , ' incorrect position after teleporting' )
7273 testing .expectEqualWithDelta (player .position .y , - 100 , 1 , ' incorrect position after teleporting' )
7374 testing .expectEqualWithDelta (player .rotation :getYaw (), math.rad (- 90 ), 0.05 , ' teleporting changes rotation' )
74- end
75+ end )
7576
76- local function testGetGMST ()
77+ testing . registerGlobalTest ( ' getGMST ' , function ()
7778 testing .expectEqual (core .getGMST (' non-existed gmst' ), nil )
7879 testing .expectEqual (core .getGMST (' Water_RippleFrameCount' ), 4 )
7980 testing .expectEqual (core .getGMST (' Inventory_DirectionalDiffuseR' ), 0.5 )
8081 testing .expectEqual (core .getGMST (' Level_Up_Level2' ), ' something' )
81- end
82+ end )
8283
83- local function testMWScript ()
84+ testing . registerGlobalTest ( ' MWScript ' , function ()
8485 local variableStoreCount = 18
8586 local variableStore = world .mwscript .getGlobalVariables (player )
8687 testing .expectEqual (variableStoreCount , # variableStore )
@@ -100,7 +101,7 @@ local function testMWScript()
100101 indexCheck = indexCheck + 1
101102 end
102103 testing .expectEqual (variableStoreCount , indexCheck )
103- end
104+ end )
104105
105106local function testRecordStore (store , storeName , skipPairs )
106107 testing .expect (store .records )
@@ -121,7 +122,7 @@ local function testRecordStore(store, storeName, skipPairs)
121122 testing .expectEqual (status , true , storeName )
122123end
123124
124- local function testRecordStores ()
125+ testing . registerGlobalTest ( ' record stores ' , function ()
125126 for key , type in pairs (types ) do
126127 if type .records then
127128 testRecordStore (type , key )
@@ -140,9 +141,9 @@ local function testRecordStores()
140141 testRecordStore (types .NPC .classes , " classes" )
141142 testRecordStore (types .NPC .races , " races" )
142143 testRecordStore (types .Player .birthSigns , " birthSigns" )
143- end
144+ end )
144145
145- local function testRecordCreation ()
146+ testing . registerGlobalTest ( ' record creation ' , function ()
146147 local newLight = {
147148 isCarriable = true ,
148149 isDynamic = true ,
@@ -165,9 +166,9 @@ local function testRecordCreation()
165166 for key , value in pairs (newLight ) do
166167 testing .expectEqual (record [key ], value )
167168 end
168- end
169+ end )
169170
170- local function testUTF8Chars ()
171+ testing . registerGlobalTest ( ' UTF-8 characters ' , function ()
171172 testing .expectEqual (utf8.codepoint (" 😀" ), 0x1F600 )
172173
173174 local chars = {}
@@ -192,9 +193,9 @@ local function testUTF8Chars()
192193 testing .expectEqual (utf8.codepoint (char ), codepoint )
193194 testing .expectEqual (utf8.len (char ), 1 )
194195 end
195- end
196+ end )
196197
197- local function testUTF8Strings ()
198+ testing . registerGlobalTest ( ' UTF-8 strings ' , function ()
198199 local utf8str = " Hello, 你好, 🌎!"
199200
200201 local str = " "
@@ -205,9 +206,9 @@ local function testUTF8Strings()
205206
206207 testing .expectEqual (utf8.len (utf8str ), 13 )
207208 testing .expectEqual (utf8.offset (utf8str , 9 ), 11 )
208- end
209+ end )
209210
210- local function testMemoryLimit ()
211+ testing . registerGlobalTest ( ' memory limit ' , function ()
211212 local ok , err = pcall (function ()
212213 local t = {}
213214 local n = 1
@@ -218,14 +219,16 @@ local function testMemoryLimit()
218219 end )
219220 testing .expectEqual (ok , false , ' Script reaching memory limit should fail' )
220221 testing .expectEqual (err , ' not enough memory' )
221- end
222+ end )
222223
223224local function initPlayer ()
225+ local player = world .players [1 ]
224226 player :teleport (' ' , util .vector3 (4096 , 4096 , 1745 ), util .transform .identity )
225227 coroutine.yield ()
228+ return player
226229end
227230
228- local function testVFS ()
231+ testing . registerGlobalTest ( ' vfs ' , function ()
229232 local file = ' test_vfs_dir/lines.txt'
230233 local nosuchfile = ' test_vfs_dir/nosuchfile'
231234 testing .expectEqual (vfs .fileExists (file ), true , ' lines.txt should exist' )
@@ -269,12 +272,11 @@ local function testVFS()
269272 for _ ,v in pairs (expectedLines ) do
270273 testing .expectEqual (getLine (), v )
271274 end
272- end
275+ end )
273276
274- local function testCommitCrime ()
275- initPlayer ()
276- local player = world .players [1 ]
277- testing .expectEqual (player == nil , false , ' A viable player reference should exist to run `testCommitCrime`' )
277+ testing .registerGlobalTest (' commit crime' , function ()
278+ local player = initPlayer ()
279+ testing .expectEqual (player == nil , false , ' A viable player reference should exist to run `commit crime`' )
278280 testing .expectEqual (I .Crimes == nil , false , ' Crimes interface should be available in global contexts' )
279281
280282 -- Reset crime level to have a clean slate
@@ -292,82 +294,41 @@ local function testCommitCrime()
292294 types .Player .setCrimeLevel (player , 0 )
293295 testing .expectEqual (I .Crimes .commitCrime (player , { victim = victim , type = types .Player .OFFENSE_TYPE .Theft , arg = 50 }).wasCrimeSeen , true , " Running a crime with a valid victim should notify them when the player is not sneaking, even if it's not explicitly passed in" )
294296 testing .expectEqual (types .Player .getCrimeLevel (player ), 0 , " Crime level should not change if the victim's alarm value is low and there's no other witnesses" )
295- end
297+ end )
296298
297- local function testRecordModelProperty ()
298- initPlayer ()
299+ testing .registerGlobalTest (' record model property' , function ()
299300 local player = world .players [1 ]
300301 testing .expectEqual (types .NPC .record (player ).model , ' meshes/basicplayer.dae' )
302+ end )
303+
304+ local function registerPlayerTest (name )
305+ testing .registerGlobalTest (name , function ()
306+ local player = initPlayer ()
307+ testing .runLocalTest (player , name )
308+ end )
301309end
302310
303- tests = {
304- {' timers' , testTimers },
305- {' rotating player with controls.yawChange should change rotation' , function ()
306- initPlayer ()
307- testing .runLocalTest (player , ' playerYawRotation' )
308- end },
309- {' rotating player with controls.pitchChange should change rotation' , function ()
310- initPlayer ()
311- testing .runLocalTest (player , ' playerPitchRotation' )
312- end },
313- {' rotating player with controls.pitchChange and controls.yawChange should change rotation' , function ()
314- initPlayer ()
315- testing .runLocalTest (player , ' playerPitchAndYawRotation' )
316- end },
317- {' rotating player should not lead to nan rotation' , function ()
318- initPlayer ()
319- testing .runLocalTest (player , ' playerRotation' )
320- end },
321- {' playerForwardRunning' , function ()
322- initPlayer ()
323- testing .runLocalTest (player , ' playerForwardRunning' )
324- end },
325- {' playerDiagonalWalking' , function ()
326- initPlayer ()
327- testing .runLocalTest (player , ' playerDiagonalWalking' )
328- end },
329- {' findPath' , function ()
330- initPlayer ()
331- testing .runLocalTest (player , ' findPath' )
332- end },
333- {' findRandomPointAroundCircle' , function ()
334- initPlayer ()
335- testing .runLocalTest (player , ' findRandomPointAroundCircle' )
336- end },
337- {' castNavigationRay' , function ()
338- initPlayer ()
339- testing .runLocalTest (player , ' castNavigationRay' )
340- end },
341- {' findNearestNavMeshPosition' , function ()
342- initPlayer ()
343- testing .runLocalTest (player , ' findNearestNavMeshPosition' )
344- end },
345- {' teleport' , testTeleport },
346- {' getGMST' , testGetGMST },
347- {' recordStores' , testRecordStores },
348- {' recordCreation' , testRecordCreation },
349- {' utf8Chars' , testUTF8Chars },
350- {' utf8Strings' , testUTF8Strings },
351- {' mwscript' , testMWScript },
352- {' testMemoryLimit' , testMemoryLimit },
353- {' playerMemoryLimit' , function ()
354- initPlayer ()
355- testing .runLocalTest (player , ' playerMemoryLimit' )
356- end },
357- {' player with equipped weapon on attack should damage health of other actors' , function ()
358- initPlayer ()
359- world .createObject (' basic_dagger1h' , 1 ):moveInto (player )
360- testing .runLocalTest (player , ' playerWeaponAttack' )
361- end },
362- {' vfs' , testVFS },
363- {' testCommitCrime' , testCommitCrime },
364- {' recordModelProperty' , testRecordModelProperty },
365- }
311+ registerPlayerTest (' player yaw rotation' )
312+ registerPlayerTest (' player pitch rotation' )
313+ registerPlayerTest (' player pitch and yaw rotation' )
314+ registerPlayerTest (' player rotation' )
315+ registerPlayerTest (' player forward running' )
316+ registerPlayerTest (' player diagonal walking' )
317+ registerPlayerTest (' findPath' )
318+ registerPlayerTest (' findRandomPointAroundCircle' )
319+ registerPlayerTest (' castNavigationRay' )
320+ registerPlayerTest (' findNearestNavMeshPosition' )
321+ registerPlayerTest (' player memory limit' )
322+
323+ testing .registerGlobalTest (' player weapon attack' , function ()
324+ local player = initPlayer ()
325+ world .createObject (' basic_dagger1h' , 1 ):moveInto (player )
326+ testing .runLocalTest (player , ' player weapon attack' )
327+ end )
366328
367329return {
368330 engineHandlers = {
369- onUpdate = testing .testRunner (tests ),
370- onPlayerAdded = function (p ) player = p end ,
331+ onUpdate = testing .updateGlobal ,
371332 },
372- eventHandlers = testing .eventHandlers ,
333+ eventHandlers = testing .globalEventHandlers ,
373334}
0 commit comments