Devtest: Fix crash in player unittest (#9937)
authorWuzzy <wuzzy2@mail.ru>
Tue, 26 May 2020 17:49:02 +0000 (19:49 +0200)
committerGitHub <noreply@github.com>
Tue, 26 May 2020 17:49:02 +0000 (19:49 +0200)
Happened if player unittests run when player has exactly 3 HP

games/devtest/mods/unittests/player.lua

index 10781a95f8f48ee3cc759995591a0ef09cff7c25..4a681310dc0acd3402e9e7de8bb96a366b867cc0 100644 (file)
@@ -3,6 +3,9 @@
 --
 local expect = nil
 local function run_hpchangereason_tests(player)
+       local old_hp = player:get_hp()
+
+       player:set_hp(20)
        expect = { type = "set_hp", from = "mod" }
        player:set_hp(3)
        assert(expect == nil)
@@ -15,7 +18,7 @@ local function run_hpchangereason_tests(player)
        player:set_hp(10, { type = "fall", df = 3458973454 })
        assert(expect == nil)
 
-       player:set_hp(20)
+       player:set_hp(old_hp)
 end
 
 local function run_player_meta_tests(player)