@@ -7,7 +7,7 @@ local vfs = require('openmw.vfs')
7
7
local world = require (' openmw.world' )
8
8
local I = require (' openmw.interfaces' )
9
9
10
- local function testTimers ()
10
+ testing . registerGlobalTest ( ' timers ' , function ()
11
11
testing .expectAlmostEqual (core .getGameTimeScale (), 30 , ' incorrect getGameTimeScale() result' )
12
12
testing .expectAlmostEqual (core .getSimulationTimeScale (), 1 , ' incorrect getSimulationTimeScale result' )
13
13
@@ -39,9 +39,10 @@ local function testTimers()
39
39
testing .expectGreaterOrEqual (ts1 , 0.5 , ' async:newSimulationTimer failed' )
40
40
testing .expectGreaterOrEqual (th2 , 72 , ' async:newUnsavableGameTimer failed' )
41
41
testing .expectGreaterOrEqual (ts2 , 1 , ' async:newUnsavableSimulationTimer failed' )
42
- end
42
+ end )
43
43
44
- local function testTeleport ()
44
+ testing .registerGlobalTest (' teleport' , function ()
45
+ local player = world .players [1 ]
45
46
player :teleport (' ' , util .vector3 (100 , 50 , 500 ), util .transform .rotateZ (math.rad (90 )))
46
47
coroutine.yield ()
47
48
testing .expect (player .cell .isExterior , ' teleport to exterior failed' )
@@ -71,16 +72,16 @@ local function testTeleport()
71
72
testing .expectEqualWithDelta (player .position .x , 50 , 1 , ' incorrect position after teleporting' )
72
73
testing .expectEqualWithDelta (player .position .y , - 100 , 1 , ' incorrect position after teleporting' )
73
74
testing .expectEqualWithDelta (player .rotation :getYaw (), math.rad (- 90 ), 0.05 , ' teleporting changes rotation' )
74
- end
75
+ end )
75
76
76
- local function testGetGMST ()
77
+ testing . registerGlobalTest ( ' getGMST ' , function ()
77
78
testing .expectEqual (core .getGMST (' non-existed gmst' ), nil )
78
79
testing .expectEqual (core .getGMST (' Water_RippleFrameCount' ), 4 )
79
80
testing .expectEqual (core .getGMST (' Inventory_DirectionalDiffuseR' ), 0.5 )
80
81
testing .expectEqual (core .getGMST (' Level_Up_Level2' ), ' something' )
81
- end
82
+ end )
82
83
83
- local function testMWScript ()
84
+ testing . registerGlobalTest ( ' MWScript ' , function ()
84
85
local variableStoreCount = 18
85
86
local variableStore = world .mwscript .getGlobalVariables (player )
86
87
testing .expectEqual (variableStoreCount , # variableStore )
@@ -100,7 +101,7 @@ local function testMWScript()
100
101
indexCheck = indexCheck + 1
101
102
end
102
103
testing .expectEqual (variableStoreCount , indexCheck )
103
- end
104
+ end )
104
105
105
106
local function testRecordStore (store , storeName , skipPairs )
106
107
testing .expect (store .records )
@@ -121,7 +122,7 @@ local function testRecordStore(store, storeName, skipPairs)
121
122
testing .expectEqual (status , true , storeName )
122
123
end
123
124
124
- local function testRecordStores ()
125
+ testing . registerGlobalTest ( ' record stores ' , function ()
125
126
for key , type in pairs (types ) do
126
127
if type .records then
127
128
testRecordStore (type , key )
@@ -140,9 +141,9 @@ local function testRecordStores()
140
141
testRecordStore (types .NPC .classes , " classes" )
141
142
testRecordStore (types .NPC .races , " races" )
142
143
testRecordStore (types .Player .birthSigns , " birthSigns" )
143
- end
144
+ end )
144
145
145
- local function testRecordCreation ()
146
+ testing . registerGlobalTest ( ' record creation ' , function ()
146
147
local newLight = {
147
148
isCarriable = true ,
148
149
isDynamic = true ,
@@ -165,9 +166,9 @@ local function testRecordCreation()
165
166
for key , value in pairs (newLight ) do
166
167
testing .expectEqual (record [key ], value )
167
168
end
168
- end
169
+ end )
169
170
170
- local function testUTF8Chars ()
171
+ testing . registerGlobalTest ( ' UTF-8 characters ' , function ()
171
172
testing .expectEqual (utf8.codepoint (" 😀" ), 0x1F600 )
172
173
173
174
local chars = {}
@@ -192,9 +193,9 @@ local function testUTF8Chars()
192
193
testing .expectEqual (utf8.codepoint (char ), codepoint )
193
194
testing .expectEqual (utf8.len (char ), 1 )
194
195
end
195
- end
196
+ end )
196
197
197
- local function testUTF8Strings ()
198
+ testing . registerGlobalTest ( ' UTF-8 strings ' , function ()
198
199
local utf8str = " Hello, 你好, 🌎!"
199
200
200
201
local str = " "
@@ -205,9 +206,9 @@ local function testUTF8Strings()
205
206
206
207
testing .expectEqual (utf8.len (utf8str ), 13 )
207
208
testing .expectEqual (utf8.offset (utf8str , 9 ), 11 )
208
- end
209
+ end )
209
210
210
- local function testMemoryLimit ()
211
+ testing . registerGlobalTest ( ' memory limit ' , function ()
211
212
local ok , err = pcall (function ()
212
213
local t = {}
213
214
local n = 1
@@ -218,14 +219,16 @@ local function testMemoryLimit()
218
219
end )
219
220
testing .expectEqual (ok , false , ' Script reaching memory limit should fail' )
220
221
testing .expectEqual (err , ' not enough memory' )
221
- end
222
+ end )
222
223
223
224
local function initPlayer ()
225
+ local player = world .players [1 ]
224
226
player :teleport (' ' , util .vector3 (4096 , 4096 , 1745 ), util .transform .identity )
225
227
coroutine.yield ()
228
+ return player
226
229
end
227
230
228
- local function testVFS ()
231
+ testing . registerGlobalTest ( ' vfs ' , function ()
229
232
local file = ' test_vfs_dir/lines.txt'
230
233
local nosuchfile = ' test_vfs_dir/nosuchfile'
231
234
testing .expectEqual (vfs .fileExists (file ), true , ' lines.txt should exist' )
@@ -269,12 +272,11 @@ local function testVFS()
269
272
for _ ,v in pairs (expectedLines ) do
270
273
testing .expectEqual (getLine (), v )
271
274
end
272
- end
275
+ end )
273
276
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`' )
278
280
testing .expectEqual (I .Crimes == nil , false , ' Crimes interface should be available in global contexts' )
279
281
280
282
-- Reset crime level to have a clean slate
@@ -292,82 +294,41 @@ local function testCommitCrime()
292
294
types .Player .setCrimeLevel (player , 0 )
293
295
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" )
294
296
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 )
296
298
297
- local function testRecordModelProperty ()
298
- initPlayer ()
299
+ testing .registerGlobalTest (' record model property' , function ()
299
300
local player = world .players [1 ]
300
301
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 )
301
309
end
302
310
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 )
366
328
367
329
return {
368
330
engineHandlers = {
369
- onUpdate = testing .testRunner (tests ),
370
- onPlayerAdded = function (p ) player = p end ,
331
+ onUpdate = testing .updateGlobal ,
371
332
},
372
- eventHandlers = testing .eventHandlers ,
333
+ eventHandlers = testing .globalEventHandlers ,
373
334
}
0 commit comments