Skip to content

Commit 9ebdc11

Browse files
authored
Fix CI (#34)
* LuaCheck: Fixed new warnings. * LuaCheck: Fixed warning 211 - Unused local variable. * LuaCheck: Fixed warning 421 - Shadowing a local variable. * LuaCheck: Fixed warning 432 - Shadowing an upvalue argument. * LuaCheck: Fixed warning 511 - Unreachable code. * LuaCheck: Ignore warning 143 - Accessing undefined field of a table. Ignoring the specific occurence through inline comments.
1 parent 541e1fd commit 9ebdc11

11 files changed

Lines changed: 129 additions & 95 deletions

File tree

.luacheckrc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ allow_defined = true
1010
-- Ignore files / directories
1111
exclude_files =
1212
{
13-
"tests/", -- CuberitePluginChecker
13+
"tests/",
14+
15+
-- Not present in git, but used locally for on-the-fly checking:
16+
"InfoReg.lua",
17+
"AutoAPI/",
1418
}
1519

1620
-- Ignore variables, warning codes
1721
ignore =
1822
{
19-
"113", -- Accessing an undefined global variable.
20-
"211", -- Unused local variable.
21-
"421", -- Shadowing a local variable.
22-
"432", -- Shadowing an upvalue argument.
23-
"511", -- Unreachable code.
23+
"631", -- Line too long.
2424
}

APIImpl/File.lua

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,27 +54,27 @@ return
5454
end,
5555

5656
["<static> cFile:DeleteFile(string)"] = function(a_Simulator, a_ThisClass, a_Path)
57-
if not(cFile:IsFile(a_Path)) then
57+
a_Path = a_Simulator:redirectPath(a_Path)
58+
if not(utils.isFile(a_Path)) then
5859
return false
5960
end
60-
a_Path = a_Simulator:redirectPath(a_Path)
6161
return (os.remove(a_Path) ~= nil)
6262
end,
6363

6464
["<static> cFile:DeleteFolder(string)"] = function(a_Simulator, a_ThisClass, a_Path)
65-
if not(cFile:IsFolder(a_Path)) then
65+
a_Path = a_Simulator:redirectPath(a_Path)
66+
if not(utils.isFolder(a_Path)) then
6667
return false
6768
end
68-
a_Path = a_Simulator:redirectPath(a_Path)
6969
return (os.remove(a_Path) ~= nil)
7070
end,
7171

7272
["<static> cFile:DeleteFolderContents(string)"] = function(a_Simulator, a_ThisClass, a_Path)
73-
if not(cFile:IsFolder(a_Path)) then
73+
if not(utils.isFolder(a_Path)) then
7474
return false
7575
end
7676
a_Path = a_Simulator:redirectPath(a_Path)
77-
return deleteFolderContents(a_Path)
77+
return utils.deleteFolderContents(a_Path)
7878
end,
7979

8080
["<static> cFile:Exists(string)"] = function(a_Simulator, a_ThisClass, a_Path)
@@ -111,14 +111,12 @@ return
111111

112112
["<static> cFile:IsFile(string)"] = function(a_Simulator, a_ThisClass, a_FileName)
113113
a_FileName = a_Simulator:redirectPath(a_FileName)
114-
local mode = lfs.attributes(a_FileName, "mode")
115-
return (mode == "file")
114+
return utils.isFile(a_FileName)
116115
end,
117116

118117
["<static> cFile:IsFolder(string)"] = function(a_Simulator, a_ThisClass, a_Path)
119118
a_Path = a_Simulator:redirectPath(a_Path)
120-
local mode = lfs.attributes(a_Path, "mode")
121-
return (mode == "directory")
119+
return utils.isFolder(a_Path)
122120
end,
123121

124122
["<static> cFile:ReadWholeFile(string)"] = function(a_Simulator, a_ThisClass, a_Path)

APIImpl/Misc.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ return
4040

4141
["cRoot:DoWithPlayerByUUID(cUUID, function)"] = function(a_Simulator, a_Root, a_PlayerUUID, a_Callback)
4242
for playerName, player in pairs(a_Simulator.players) do
43-
if (player.uuid == a_Uuid) then
43+
if (player.uuid == a_PlayerUUID) then
4444
local res = a_Simulator:processCallbackRequest({
4545
Function = a_Callback,
4646
ParamValues = { a_Simulator:getPlayerByName(playerName) },
4747
Notes = string.format("cRoot:DoWithPlayerByUUID() for player %s", playerName),
4848
})
49-
return true
49+
return not(not(res)) -- Convert to bool
5050
end
5151
end
5252
return false -- player not found

APIImpl/Network.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77

88

9-
local socket = require("socket")
9+
-- local socket = require("socket")
1010
local http = require("socket.http")
1111
local https = require("ssl.https")
1212
local ltn12 = require("ltn12")

APIImpl/PluginManager.lua

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ end
1919

2020

2121

22+
--- Returns a cPluginLua instance that acts as the current plugin
23+
local function getCurrentPlugin(a_Simulator, a_Self)
24+
local res = a_Simulator:createInstance({Type = "cPluginLua"})
25+
-- Save the path to the plugin folder in the self variable
26+
getmetatable(res).simulatorInternal_pluginPath = a_Simulator.options.pluginPath
27+
return res
28+
end
29+
30+
31+
32+
33+
2234
--- Implementation of the cPluginManager:BindCommand function
2335
-- There are two separate API endpoints for the same implementation, so the implementation is pulled into a common function
2436
local function BindCommand(a_Simulator, a_Self, a_Command, a_Permission, a_Callback, a_HelpString)
@@ -106,7 +118,7 @@ return
106118

107119
["<static> cPluginManager:DoWithPlugin(string, function) -> (boolean)"] = function(a_Simulator, a_Class, a_PluginName, a_Callback)
108120
-- The currently tested plugin is the only one present, if the name matches, call with "self":
109-
local currPlugin = cPluginManager:GetCurrentPlugin()
121+
local currPlugin = getCurrentPlugin(a_Simulator)
110122
if (a_PluginName == currPlugin:GetName()) then
111123
local res = a_Simulator:processCallbackRequest({
112124
Function = a_Callback,
@@ -154,12 +166,7 @@ return
154166

155167
["cPluginManager:ForEachPlugin(function) -> (boolean)"] = ForEachPlugin,
156168

157-
["cPluginManager:GetCurrentPlugin()"] = function (a_Simulator, a_Self)
158-
local res = a_Simulator:createInstance({Type = "cPluginLua"})
159-
-- Save the path to the plugin folder in the self variable
160-
getmetatable(res).simulatorInternal_pluginPath = a_Simulator.options.pluginPath
161-
return res
162-
end,
169+
["cPluginManager:GetCurrentPlugin()"] = getCurrentPlugin,
163170

164171
["<static> cPluginManager:GetPluginsPath()"] = function (a_Simulator)
165172
return a_Simulator.options.pluginPath .. "/.."

APIImpl/World.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ return
134134
ParamValues = { a_Simulator:getPlayerByName(playerName) },
135135
Notes = string.format("cWorld:DoWithEntityByID() for player %s", playerName),
136136
})
137-
return true
137+
return not(not(res)) -- Convert to bool
138138
end
139139
end
140140
return false -- player not found
@@ -175,7 +175,7 @@ return
175175
ParamValues = { a_Simulator:getPlayerByName(a_PlayerName) },
176176
Notes = string.format("cWorld:DoWithPlayer() for player %s", a_PlayerName),
177177
})
178-
return true
178+
return not(not(res)) -- Convert to bool
179179
end
180180
return false -- player not found
181181
end,
@@ -195,7 +195,7 @@ return
195195
ParamValues = { a_Simulator:getPlayerByName(playerName) },
196196
Notes = string.format("cWorld:DoWithPlayerByUUID() for player %s", playerName),
197197
})
198-
return true
198+
return not(not(res)) -- Convert to bool
199199
end
200200
end
201201
return false -- player not found
@@ -293,7 +293,7 @@ return
293293
-- If there is an exact match, use that:
294294
local exactMatch = a_Simulator.players[a_PlayerName]
295295
if (exactMatch and (exactMatch.worldName == worldName)) then
296-
local res = a_Simulator:processCallbackRequest({
296+
a_Simulator:processCallbackRequest({
297297
Function = a_Callback,
298298
ParamValues = { a_Simulator:getPlayerByName(a_PlayerName) },
299299
Notes = string.format("cWorld:FindAndDoWithPlayer() for player %s", a_PlayerName),
@@ -304,7 +304,7 @@ return
304304
-- If no exact match, use the first player in the world:
305305
for playerName, player in pairs(a_Simulator.players) do
306306
if (player.worldName == worldName) then
307-
local res = a_Simulator:processCallbackRequest({
307+
a_Simulator:processCallbackRequest({
308308
Function = a_Callback,
309309
ParamValues = { a_Simulator:getPlayerByName(playerName) },
310310
Notes = string.format("cWorld:FindAndDoWithPlayer() for player %s", playerName),

Logger.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
local Logger =
1010
{
1111
-- The various log levels:
12-
ERROR = 9, -- Emitting this log also terminates the entire program
12+
ERROR = 9, -- Emitting this log also prints stacktrace and terminates the entire program
1313
WARNING = 5,
1414
INFO = 4,
1515
DEBUG = 3,
1616
TRACE = 1,
17-
18-
-- If currentLogLevel is higher than message's loglevel, the message won't be output
19-
currentLogLevel = DEBUG,
2017
}
2118

19+
-- If currentLogLevel is higher than message's loglevel, the message won't be output
20+
Logger.currentLogLevel = Logger.DEBUG
21+
2222

2323

2424

Scenario.lua

Lines changed: 55 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,33 @@ end
159159

160160

161161

162+
--- Recursively fuzzes a single command
163+
-- To be used only inside fuzzCommand!
164+
-- a_CurrentIndex is the index into the a_Split array specifying the index that this recursion level should modify
165+
-- a_Split is the command params split array
166+
-- The recursion is called "backwards", the last param is chosen first and then the previous param is recursed
167+
-- When a_CurrentIndex is zero, the actual command handlers are invoked
168+
local function fuzzSingleCommand(a_Simulator, a_Command, a_PlayerName, a_Choices, a_NumChoices, a_CurrentIndex, a_Split)
169+
if (a_CurrentIndex == 0) then
170+
-- We've built the whole command, serialize the params into a string and execute it:
171+
a_Simulator.logger:info("Scenario: fuzzing command \"%s\".", a_Command .. " " .. table.concat(a_Split, " "))
172+
a_Simulator:executePlayerCommand(a_PlayerName, a_Command .. " " .. table.concat(a_Split, " "))
173+
-- Process all queued callbacks:
174+
a_Simulator:processAllQueuedCallbackRequests()
175+
return
176+
end
177+
178+
-- Try all choices on position <a_CurrentIndex> and recurse:
179+
for ch = 1, a_NumChoices do
180+
a_Split[a_CurrentIndex] = a_Choices[ch]
181+
fuzzSingleCommand(a_Simulator, a_Command, a_PlayerName, a_Choices, a_NumChoices, a_CurrentIndex - 1, a_Split)
182+
end
183+
end
184+
185+
186+
187+
188+
162189
--- Fuzzes a single command
163190
-- a_Simulator is the simulator instance on which to fuzz the commands
164191
-- a_Command is the registered command (string) being fuzzed
@@ -167,28 +194,6 @@ end
167194
-- a_MinLen is the minimum length of the fuzzed command parameter array
168195
-- a_MaxLen is the maximum length of the fuzzed command parameter array
169196
local function fuzzCommand(a_Simulator, a_Command, a_PlayerName, a_Choices, a_MinLen, a_MaxLen)
170-
-- Recursively fuzzes a single command
171-
-- a_CurrentIndex is the index into the a_Split array specifying the index that this recursion level should modify
172-
-- a_Split is the command params split array
173-
-- The recursion is called "backwards", the last param is chosen first and then the previous param is recursed
174-
-- When a_CurrentIndex is zero, the actual command handlers are invoked
175-
local function fuzzSingleCommand(a_Simulator, a_Command, a_PlayerName, a_Choices, a_NumChoices, a_CurrentIndex, a_Split)
176-
if (a_CurrentIndex == 0) then
177-
-- We've built the whole command, serialize the params into a string and execute it:
178-
a_Simulator.logger:info("Scenario: fuzzing command \"%s\".", a_Command .. " " .. table.concat(a_Split, " "))
179-
a_Simulator:executePlayerCommand(a_PlayerName, a_Command .. " " .. table.concat(a_Split, " "))
180-
-- Process all queued callbacks:
181-
a_Simulator:processAllQueuedCallbackRequests()
182-
return
183-
end
184-
185-
-- Try all choices on position <a_CurrentIndex> and recurse:
186-
for ch = 1, a_NumChoices do
187-
a_Split[a_CurrentIndex] = a_Choices[ch]
188-
fuzzSingleCommand(a_Simulator, a_Command, a_PlayerName, a_Choices, a_NumChoices, a_CurrentIndex - 1, a_Split)
189-
end
190-
end
191-
192197
-- Start the fuzzing:
193198
for len = a_MinLen, a_MaxLen do
194199
fuzzSingleCommand(a_Simulator, a_Command, a_PlayerName, a_Choices, #a_Choices, len, {})
@@ -199,38 +204,43 @@ end
199204

200205

201206

207+
--- Recursively fuzzes a single console command
208+
-- To be used only inside FuzzConsoleCommand!
209+
-- a_CurrentIndex is the index into the a_Split array specifying the index that this recursion level should modify
210+
-- a_Split is the command params split array
211+
-- The recursion is called "backwards", the last param is chosen first and then the previous param is recursed
212+
-- When a_CurrentIndex is zero, the actual command handlers are invoked
213+
local function fuzzSingleConsoleCommand(a_Simulator, a_Command, a_Choices, a_NumChoices, a_CurrentIndex, a_Split)
214+
if (a_CurrentIndex == 0) then
215+
-- We've built the whole command, serialize the params into a string and execute it:
216+
a_Simulator.logger:info("Scenario: fuzzing console command \"%s\".", a_Command .. " " .. table.concat(a_Split, " "))
217+
a_Simulator:executeConsoleCommand(a_Command .. " " .. table.concat(a_Split, " "))
218+
-- Process all queued callbacks:
219+
a_Simulator:processAllQueuedCallbackRequests()
220+
return
221+
end
222+
223+
-- Try all choices on position <a_CurrentIndex> and recurse:
224+
for ch = 1, a_NumChoices do
225+
a_Split[a_CurrentIndex] = a_Choices[ch]
226+
fuzzSingleConsoleCommand(a_Simulator, a_Command, a_Choices, a_NumChoices, a_CurrentIndex - 1, a_Split)
227+
end
228+
end
229+
230+
231+
232+
233+
202234
--- Fuzzes a single console command
203235
-- a_Simulator is the simulator instance on which to fuzz the commands
204236
-- a_Command is the registered command (string) being fuzzed
205237
-- a_Choices is the array-table of choices for the command parameters
206238
-- a_MinLen is the minimum length of the fuzzed command parameter array
207239
-- a_MaxLen is the maximum length of the fuzzed command parameter array
208240
local function fuzzConsoleCommand(a_Simulator, a_Command, a_Choices, a_MinLen, a_MaxLen)
209-
-- Recursively fuzzes a single console command
210-
-- a_CurrentIndex is the index into the a_Split array specifying the index that this recursion level should modify
211-
-- a_Split is the command params split array
212-
-- The recursion is called "backwards", the last param is chosen first and then the previous param is recursed
213-
-- When a_CurrentIndex is zero, the actual command handlers are invoked
214-
local function fuzzSingleCommand(a_Simulator, a_Command, a_Choices, a_NumChoices, a_CurrentIndex, a_Split)
215-
if (a_CurrentIndex == 0) then
216-
-- We've built the whole command, serialize the params into a string and execute it:
217-
a_Simulator.logger:info("Scenario: fuzzing console command \"%s\".", a_Command .. " " .. table.concat(a_Split, " "))
218-
a_Simulator:executeConsoleCommand(a_Command .. " " .. table.concat(a_Split, " "))
219-
-- Process all queued callbacks:
220-
a_Simulator:processAllQueuedCallbackRequests()
221-
return
222-
end
223-
224-
-- Try all choices on position <a_CurrentIndex> and recurse:
225-
for ch = 1, a_NumChoices do
226-
a_Split[a_CurrentIndex] = a_Choices[ch]
227-
fuzzSingleCommand(a_Simulator, a_Command, a_Choices, a_NumChoices, a_CurrentIndex - 1, a_Split)
228-
end
229-
end
230-
231241
-- Start the fuzzing:
232242
for len = a_MinLen, a_MaxLen do
233-
fuzzSingleCommand(a_Simulator, a_Command, a_Choices, #a_Choices, len, {})
243+
fuzzSingleConsoleCommand(a_Simulator, a_Command, a_Choices, #a_Choices, len, {})
234244
end -- for len - number of chosen params
235245
end
236246

0 commit comments

Comments
 (0)