Add unit test support
parent
b33c9fe49a
commit
602c24ddf1
|
@ -1,45 +1,4 @@
|
|||
lobby = {}
|
||||
lobby.map = {} --Holds number of players in a level.
|
||||
lobby.voted = {} --Holds player names, and if they have voted.
|
||||
lobby.votes = {}
|
||||
lobby.suspect = {} --Holds number of votes a player has marking them as suspect
|
||||
lobby.game = {} --Holds player names and what map they are on.
|
||||
lobby.xp = {} --The current XP amount for each level.
|
||||
lobby.traitors = {} --
|
||||
lobby.corpses = {}
|
||||
lobby.vote_timer = {}
|
||||
lobby.spawn_pos = {x=29996, y=-4.5, z=30041.5}
|
||||
lobby.spawn_pos = minetest.setting_get_pos('traitor_lobby_spawn') or lobby.spawn_pos
|
||||
lobby.stat = {}
|
||||
--Yes I know these table names are not very clear.
|
||||
|
||||
--[[
|
||||
Saving data:
|
||||
local data = {}
|
||||
data.level_pos = {x = pos_x, y = pos_y, z = pos_z}
|
||||
data.xp = tonumber(fields.xp)
|
||||
lobby.savedata.IDs[map_id] = true
|
||||
lobby.savedata.data[map_id] = data
|
||||
lobby.savedata.stats[map_id] = stats
|
||||
|
||||
----
|
||||
Retriving data:
|
||||
local game_data = lobby.savedata.data[map_id]
|
||||
local game_pos = game_data['level_pos']
|
||||
|
||||
player_attributes:set_string('mode', 'builder')
|
||||
This is set anytime a player goes to a level they have build access on.
|
||||
|
||||
player_attributes:set_string('mode', 'player')
|
||||
This is set when a player is playing a level with other people, as it's meant to be played.
|
||||
|
||||
player_attributes:set_string('mode', 'solo')
|
||||
This is set when a player plays a level solo, usually to earn XP, but could also be to explore levels.
|
||||
|
||||
player_attributes:set_string('mode', 'ghost')
|
||||
This is set when a player, playing with others, dies on a level.
|
||||
]]
|
||||
|
||||
dofile(minetest.get_modpath('lobby')..'/lobby.lua')
|
||||
dofile(minetest.get_modpath('lobby')..'/buttons.lua')
|
||||
dofile(minetest.get_modpath('lobby')..'/chat_commands.lua')
|
||||
dofile(minetest.get_modpath('lobby')..'/chat.lua')
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
lobby = {}
|
||||
lobby.map = {} --Holds number of players in a level.
|
||||
lobby.voted = {} --Holds player names, and if they have voted.
|
||||
lobby.votes = {}
|
||||
lobby.suspect = {} --Holds number of votes a player has marking them as suspect
|
||||
lobby.game = {} --Holds player names and what map they are on.
|
||||
lobby.xp = {} --The current XP amount for each level.
|
||||
lobby.traitors = {} --
|
||||
lobby.corpses = {}
|
||||
lobby.vote_timer = {}
|
||||
lobby.spawn_pos = {x=29996, y=-4.5, z=30041.5}
|
||||
lobby.spawn_pos = minetest.setting_get_pos('traitor_lobby_spawn') or lobby.spawn_pos
|
||||
lobby.stat = {}
|
||||
--Yes I know these table names are not very clear.
|
||||
|
||||
--[[
|
||||
Saving data:
|
||||
local data = {}
|
||||
data.level_pos = {x = pos_x, y = pos_y, z = pos_z}
|
||||
data.xp = tonumber(fields.xp)
|
||||
lobby.savedata.IDs[map_id] = true
|
||||
lobby.savedata.data[map_id] = data
|
||||
lobby.savedata.stats[map_id] = stats
|
||||
|
||||
----
|
||||
Retriving data:
|
||||
local game_data = lobby.savedata.data[map_id]
|
||||
local game_pos = game_data['level_pos']
|
||||
|
||||
player_attributes:set_string('mode', 'builder')
|
||||
This is set anytime a player goes to a level they have build access on.
|
||||
|
||||
player_attributes:set_string('mode', 'player')
|
||||
This is set when a player is playing a level with other people, as it's meant to be played.
|
||||
|
||||
player_attributes:set_string('mode', 'solo')
|
||||
This is set when a player plays a level solo, usually to earn XP, but could also be to explore levels.
|
||||
|
||||
player_attributes:set_string('mode', 'ghost')
|
||||
This is set when a player, playing with others, dies on a level.
|
||||
]]
|
||||
|
|
@ -0,0 +1 @@
|
|||
mtmock.conf
|
|
@ -0,0 +1,16 @@
|
|||
This directory contains tests for the traitor game. Currently the test
|
||||
code requires the following:
|
||||
- Lua (or luajit) standalone executable
|
||||
|
||||
If you haven't already done so, first create a file "mtmock.conf" in
|
||||
this directory before you can use the tests. This file contains
|
||||
some essential directories used for the minetest mock.
|
||||
|
||||
The genconf.sh script might be able to create a valid mtmock.conf
|
||||
for you.
|
||||
|
||||
Once you have a working mtmock.conf, execute the tests by running
|
||||
"lua all-tests.lua" (or "luajit all-tests.sh").
|
||||
|
||||
You can use "lua all-tests.lua -h" to list all available cmdline parameters.
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
lu = require('luaunit/luaunit')
|
||||
mtmock = require('mtmock')
|
||||
|
||||
dofile(mtmock.MODDIR .. 'lobby/lobby.lua')
|
||||
dofile(mtmock.MODDIR .. 'lobby/chat.lua')
|
||||
dofile(mtmock.MODDIR .. 'lobby/stats.lua')
|
||||
|
||||
-- test stats.lua
|
||||
TestStats = {}
|
||||
function TestStats:setUp()
|
||||
lobby.savedata = {}
|
||||
lobby.savedata.stats = {}
|
||||
end
|
||||
|
||||
function TestStats:testUpdateStatsSolo1()
|
||||
lobby.update_stats('0', 'solo', 'traitor', 1)
|
||||
lu.assertNotNil(lobby.savedata)
|
||||
lu.assertNotNil(lobby.savedata.stats)
|
||||
stats = lobby.savedata.stats['0']
|
||||
lu.assertNotNil(stats)
|
||||
lu.assertEquals(stats.solo_play, 1)
|
||||
lu.assertEquals(stats.multi_play, 0)
|
||||
lu.assertEquals(stats.winner_traitor, 1)
|
||||
lu.assertEquals(stats.winner_team, 0)
|
||||
lu.assertEquals(stats.max_players, 1)
|
||||
lu.assertEquals(stats.player_count, 1)
|
||||
end
|
||||
--[[ TestStats ]]--
|
||||
|
||||
os.exit(lu.LuaUnit.run())
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
## Creates an initial mtmock.conf and tries to set the
|
||||
## SCRIPTDIR and WORLDDIR members.
|
||||
SCRIPTDIRS="/usr/share/games/minetest/builtin /usr/share/minetest/builtin"
|
||||
WORLDDIRS=$HOME/.minetest/worlds
|
||||
|
||||
for sd in ${SCRIPTDIRS}; do
|
||||
if [ -d $sd ]; then
|
||||
SCRIPTDIR=$sd
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
for wd in ${WORLDDIRS}; do
|
||||
if [ -d $wd ]; then
|
||||
WORLDDIR=$wd
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "${SCRIPTDIR}" ]; then
|
||||
echo "*** $(basename $0): cannot find minetest LUA script directory" >>/dev/stderr
|
||||
exit 1
|
||||
elif [ -z "${WORLDDIR}" ]; then
|
||||
echo "*** $(basename $0): cannot find minetest world directory" >>/dev/stderr
|
||||
exit 2
|
||||
fi
|
||||
|
||||
cat >mtmock.conf <<-EOF
|
||||
-- path to minetest's builtin LUA scrips
|
||||
mtmock.SCRIPTDIR='${SCRIPTDIR}/'
|
||||
|
||||
-- path to minetest's worlds
|
||||
mtmock.WORLDDIR='${WORLDDIR}/'
|
||||
|
||||
-- path to mods
|
||||
mtmock.MODDIR='$(realpath ../mods)/'
|
||||
EOF
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
This software is distributed under the BSD License.
|
||||
|
||||
Copyright (c) 2005-2018, Philippe Fremy <phil at freehackers dot org>
|
||||
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,45 @@
|
|||
mtmock = {}
|
||||
mtmock.settings = {}
|
||||
dofile('mtmock.conf')
|
||||
|
||||
-- bind minetest and core aliases and
|
||||
-- work with minetest alias from here on
|
||||
minetest = mtmock
|
||||
core = mtmock
|
||||
|
||||
function core.get_builtin_path()
|
||||
return core.SCRIPTDIR
|
||||
end
|
||||
|
||||
-- load MT's serialize functions
|
||||
dofile(core.get_builtin_path() .. 'common/serialize.lua')
|
||||
|
||||
minetest.connected_players = {}
|
||||
minetest.worldpath = mtmock.WORLDDIR
|
||||
|
||||
function minetest.get_worldpath()
|
||||
return minetest.worldpath
|
||||
end
|
||||
|
||||
function minetest.get_connected_players()
|
||||
return minetest.connected_players
|
||||
end
|
||||
|
||||
function minetest.log(type, msg)
|
||||
end
|
||||
|
||||
function minetest.register_on_chat_message(fun)
|
||||
end
|
||||
|
||||
function minetest.register_chatcommand(cmd, def)
|
||||
end
|
||||
|
||||
function minetest.setting_get_pos(setting)
|
||||
if mtmock.settings[setting] then
|
||||
return mtmock.settings[setting]
|
||||
else
|
||||
return nil
|
||||
end
|
||||
end
|
||||
|
||||
return mtmock
|
Loading…
Reference in New Issue