Skip to content

Commit

Permalink
Merge pull request #109 from cuberite/Tests
Browse files Browse the repository at this point in the history
Started working for scenario tests for CuberitePluginChecker
  • Loading branch information
NiLSPACE authored Aug 4, 2024
2 parents f72e30a + b2f18a3 commit 72ab743
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 14 deletions.
17 changes: 14 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,25 @@ jobs:

- name: Install Lua
run: |
sudo apt install lua5.1 luarocks
sudo apt install lua5.1 luarocks libsqlite3-dev
sudo luarocks install luafilesystem
sudo luarocks install lsqlite3
sudo luarocks install luasocket
sudo luarocks install luacheck
sudo luarocks install luasec OPENSSL_LIBDIR=/usr/lib/x86_64-linux-gnu
- name: Set up environment
run: |
wget -O .luacheckrc 'https://ci.appveyor.com/api/projects/cuberite/cuberite/artifacts/.luacheckrc?job=Windows-x64&pr=false&branch=master'
wget -O ../InfoReg.lua https://raw.githubusercontent.com/cuberite/cuberite/master/Server/Plugins/InfoReg.lua
mkdir ~/AutoAPI
wget -O ~/AutoAPI.zip --no-check-certificate 'https://ci.appveyor.com/api/projects/cuberite/cuberite/artifacts/AutoAPI.zip?job=Windows-x64&pr=false&branch=master'
unzip ~/AutoAPI.zip -d ~/AutoAPI
wget -O ~/ManualAPI.zip --no-check-certificate 'https://ci.appveyor.com/api/projects/cuberite/cuberite/artifacts/ManualAPI.zip?job=Windows-x64&pr=false&branch=master'
unzip ~/ManualAPI.zip -d ~
git clone https://github.com/cuberite/CuberitePluginChecker ~/Checker
wget -O .luacheckrc --no-check-certificate 'https://ci.appveyor.com/api/projects/cuberite/cuberite/artifacts/.luacheckrc?job=Windows-x64&pr=false&branch=master'
- name: Run tests
run: |
luacheck . --codes
cd ~/Checker && lua CuberitePluginChecker.lua -p $GITHUB_WORKSPACE -a ~/AutoAPI -e ~/ManualAPI.lua -i APIImpl/All.lua -s $GITHUB_WORKSPACE/Tests/selection.lua -g
cd $GITHUB_WORKSPACE && luacheck . --codes --exclude-files Tests/*
4 changes: 4 additions & 0 deletions Classes/PlayerState.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,7 @@ end
-- Register the hooks needed:
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_DESTROYED, OnPlayerDestroyed)
cPluginManager:AddHook(cPluginManager.HOOK_PLUGIN_MESSAGE, OnPluginMessage)




8 changes: 5 additions & 3 deletions Classes/ToolRegistrator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ end


-- Register the hooks needed:
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, RightClickToolsHook);
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, LeftClickToolsHook);
cPluginManager.AddHook(cPluginManager.HOOK_PLAYER_ANIMATION, LeftClickToolsAnimationHook);
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_RIGHT_CLICK, RightClickToolsHook);
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_LEFT_CLICK, LeftClickToolsHook);
cPluginManager:AddHook(cPluginManager.HOOK_PLAYER_ANIMATION, LeftClickToolsAnimationHook);


2 changes: 1 addition & 1 deletion Commands/Special.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ end
function HandleWorldEditVersionCommand(a_Split, a_Player)
-- /we version

a_Player:SendMessage(cChatColor.LightPurple .. "This is version " .. PLUGIN:GetVersion())
a_Player:SendMessage(cChatColor.LightPurple .. "This is version " .. cPluginManager:GetCurrentPlugin():GetVersion())
return true
end

Expand Down
2 changes: 1 addition & 1 deletion Config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ g_Config = {}
-- Create an environment for the config loader where the admin can use item names directly without quotes.
local g_LoaderEnv = {}
for Key, Value in pairs(_G) do
if (Key:match("E_.*")) then
if (Key:match("^E_.*")) then
g_LoaderEnv[ItemTypeToString(Value)] = Value
end
end
Expand Down
46 changes: 46 additions & 0 deletions Tests/selection.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- selection.lua

-- These files are used with the CuberitePluginChecker script.
-- This test tests the selection and actions on the selection.
-- Usage: lua CuberitePluginChecker.lua -a AutoAPI -e ManualAPI.lua -i APIImpl/All.lua -p <WorldEditPath> -s <WorldEditPath>/selection.lua -f ^E_





scenario
{
redirectPluginFiles
{
-- Redirect the default config file.
-- This disables the update check and also works around a bug in the simulator which causes block/item enums to not be in the global environment.
["config.cfg"] = "test.config.cfg"
},
world
{
name = "world"
},
initializePlugin(),
connectPlayer
{
name = "TestUser"
},
playerCommand
{
playerName = "TestUser",
command = "//pos1",
},
playerCommand
{
playerName = "TestUser",
command = "//pos2",
},
playerCommand
{
playerName = "TestUser",
command = "//set 0",
},
}



52 changes: 52 additions & 0 deletions Tests/test.config.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
WandItem = 271,
Limits =
{
ButcherRadius = -1,
MaxBrushRadius = 5,
DisallowedBlocks = {6, 7, 14, 15, 16, 26, 27, 28, 29, 39, 31, 32, 33, 34, 36, 37, 38, 39, 40, 46, 50, 51, 56, 59, 69, 73, 74, 75, 76, 77, 81, 83},
},

Defaults =
{
ButcherRadius = 20,
},

NavigationWand =
{
Item = 345,
MaxDistance = 120,
TeleportNoHit = true,
},

Scripting =
{
-- If true it logs an error when a craftscript failed
Debug = false,

-- The amount of seconds that a script may be active. Any longer and the script will be aborted.
-- If negative the time a script can run is unlimited.
MaxExecutionTime = 5,
},

Schematics =
{
OverrideExistingFiles = true,
},

Updates =
{
CheckForUpdates = false,
NumAttempts = 3,
ShowMessageWhenUpToDate = true,
DownloadNewerVersion = true,
},

Storage =
{
-- If set to true the selection of a player will be remembered once he leaves.
RememberPlayerSelection = true,

-- If WorldEdit needs to change a format in the database the database will be backuped first before changing.
-- This doesn't mean when adding or removing data the database will be backed up. Only when the used database is outdated.
BackupDatabaseWhenUpdating = true,
}
13 changes: 7 additions & 6 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


-- First of all load all the library expansions
dofolder(cPluginManager:GetCurrentPlugin():GetLocalFolder() .. "/LibrariesExpansion")
dofolder(cPluginManager:Get():GetCurrentPlugin():GetLocalFolder() .. "/LibrariesExpansion")



Expand All @@ -18,6 +18,7 @@ dofolder(cPluginManager:GetCurrentPlugin():GetLocalFolder() .. "/LibrariesExpans
g_ExcludedFolders = table.todictionary{
"craftscripts",
"LibrariesExpansion",
"Tests",
".",
"..",
}
Expand All @@ -27,7 +28,7 @@ g_ExcludedFolders = table.todictionary{


-- Load all the folders
local WorldEditPath = cPluginManager:GetCurrentPlugin():GetLocalFolder()
local WorldEditPath = cPluginManager:Get():GetCurrentPlugin():GetLocalFolder()
for _, Folder in ipairs(cFile:GetFolderContents(WorldEditPath)) do repeat
local Path = WorldEditPath .. "/" .. Folder
if (not cFile:IsFolder(Path)) then
Expand All @@ -41,13 +42,13 @@ for _, Folder in ipairs(cFile:GetFolderContents(WorldEditPath)) do repeat
dofolder(Path)
until true end

PLUGIN = nil




function Initialize(a_Plugin)
PLUGIN = a_Plugin
PLUGIN:SetName(g_PluginInfo.Name)
PLUGIN:SetVersion(g_PluginInfo.Version)
a_Plugin:SetName(g_PluginInfo.Name)
a_Plugin:SetVersion(g_PluginInfo.Version)

InitializeConfiguration(a_Plugin:GetLocalFolder() .. "/config.cfg")

Expand Down

0 comments on commit 72ab743

Please sign in to comment.