Skip to content

Commit

Permalink
0.2
Browse files Browse the repository at this point in the history
- Added tests for all obj creation, transformation, window + system info graphics methods
- Added half the state methods for graphics + added placeholders for missing drawing methods
- Added TestMethod:assertNotNil() for quick nil checking
- Added time total to the end of each module summary in console log to match file output

- Removed a bunch of unessecary nil checks
- Removed :release() from test methods, collectgarbage("collect") is called between methods instead

- Renamed /output to /examples to avoid confusion

- Replaced love.filesystem.newFile with love.filesystem.openFile
- Replaced love.math.noise with love.math.perlinNoise / love.math.simplexNoise

- Fixed newGearJoint throwing an error in 12 as body needs to be dynamic not static now

- Some general cleanup, incl. better comments and time format in file output
  • Loading branch information
ellraiser committed Oct 5, 2023
1 parent 08467cb commit e03b2db
Show file tree
Hide file tree
Showing 30 changed files with 1,976 additions and 860 deletions.
26 changes: 16 additions & 10 deletions testing/classes/TestMethod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,23 @@ TestMethod = {
-- @param {table} obj - table to check is a valid love object
-- @return {nil}
assertObject = function(self, obj)
self:assertNotEquals(nil, obj, 'check not nill')
self:assertNotNil(obj)
self:assertEquals('userdata', type(obj), 'check is userdata')
if obj ~= nil then
if obj ~= nil then
self:assertNotEquals(nil, obj:type(), 'check has :type()')
end
end,


-- @method - TestMethod:assertNotNil()
-- @desc - quick assert for value not nil
-- @param {any} value - value to check not nil
-- @return {nil}
assertNotNil = function (self, value)
self:assertNotEquals(nil, value, 'check not nil')
end,



-- @method - TestMethod:skipTest()
-- @desc - used to mark this test as skipped for a specific reason
Expand Down Expand Up @@ -289,10 +298,7 @@ TestMethod = {
self.finish = love.timer.getTime() - self.start
love.test.time = love.test.time + self.finish
self.testmodule.time = self.testmodule.time + self.finish
local endtime = tostring(math.floor((love.timer.getTime() - self.start)*1000))
if string.len(endtime) == 1 then endtime = ' ' .. endtime end
if string.len(endtime) == 2 then endtime = ' ' .. endtime end
if string.len(endtime) == 3 then endtime = ' ' .. endtime end
local endtime = UtilTimeFormat(love.timer.getTime() - self.start)

-- get failure/skip message for output (if any)
local failure = ''
Expand All @@ -309,7 +315,7 @@ TestMethod = {
-- append XML for the test class result
self.testmodule.xml = self.testmodule.xml .. '\t\t<testclass classname="' ..
self.method .. '" name="' .. self.method ..
'" time="' .. tostring(self.finish*1000) .. '">\n' ..
'" time="' .. endtime .. '">\n' ..
failure .. '\t\t</testclass>\n'

-- unused currently, adds a preview image for certain graphics methods to the output
Expand All @@ -329,7 +335,7 @@ TestMethod = {
'<tr class=" ' .. cls .. '">' ..
'<td>' .. status .. '</td>' ..
'<td>' .. self.method .. '</td>' ..
'<td>' .. tostring(self.finish*1000) .. 'ms</td>' ..
'<td>' .. endtime .. 's</td>' ..
'<td>' .. output .. preview .. '</td>' ..
'</tr>'

Expand All @@ -350,10 +356,10 @@ TestMethod = {
self.testmodule:log(
self.testmodule.colors[self.result.result],
' ' .. tested .. matching,
' ==> ' .. self.result.result .. ' - ' .. endtime .. 'ms ' ..
' ==> ' .. self.result.result .. ' - ' .. endtime .. 's ' ..
self.result.total .. msg
)
end


}
}
11 changes: 6 additions & 5 deletions testing/classes/TestModule.lua
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,33 @@ TestModule = {
-- the XML + HTML for the test to the testsuite output
-- @return {nil}
printResult = function(self)
local finaltime = UtilTimeFormat(self.time)
-- add xml to main output
love.test.xml = love.test.xml .. '\t<testsuite name="love.' .. self.module ..
'" tests="' .. tostring(self.passed) ..
'" failures="' .. tostring(self.failed) ..
'" skipped="' .. tostring(self.skipped) ..
'" time="' .. tostring(self.time*1000) .. '">\n' .. self.xml .. '\t</testsuite>\n'
'" time="' .. finaltime .. '">\n' .. self.xml .. '\t</testsuite>\n'
-- add html to main output
local status = '🔴'
if self.failed == 0 then status = '🟢' end
love.test.html = love.test.html .. '<h2>' .. status .. '&nbsp;love.' .. self.module .. '</h2><ul class="summary">' ..
'<li>🟢&nbsp;' .. tostring(self.passed) .. ' Tests</li>' ..
'<li>🔴&nbsp;' .. tostring(self.failed) .. ' Failures</li>' ..
'<li>🟡&nbsp;' .. tostring(self.skipped) .. ' Skipped</li>' ..
'<li>' .. tostring(self.time*1000) .. 'ms</li>' .. '<ul><br/><br/>' ..
'<table><thead><tr><td width="20px"></td><td width="100px">Method</td><td width="100px">Time</td><td>Details</td></tr></thead><tbody>' ..
'<li>' .. finaltime .. 's</li>' .. '<ul><br/><br/>' ..
'<table><thead><tr><td width="20px"></td><td width="100px">Method</td><td width="60px">Time</td><td>Details</td></tr></thead><tbody>' ..
self.html .. '</tbody></table>'
-- print module results to console
self:log('yellow', 'love.' .. self.module .. '.testmodule.end')
local failedcol = '\27[31m'
if self.failed == 0 then failedcol = '\27[37m' end
self:log('green', tostring(self.passed) .. ' PASSED' .. ' || ' ..
failedcol .. tostring(self.failed) .. ' FAILED || \27[37m' ..
tostring(self.skipped) .. ' SKIPPED')
tostring(self.skipped) .. ' SKIPPED || ' .. finaltime .. 's')
self.start = false
self.fakequit = false
end


}
}
18 changes: 9 additions & 9 deletions testing/classes/TestSuite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TestSuite = {
-- testsuite internals
modules = {},
module = nil,
testcanvas = love.graphics.newCanvas(16, 16),
testcanvas = nil,
current = 1,
output = '',
totals = {0, 0, 0},
Expand Down Expand Up @@ -91,6 +91,9 @@ TestSuite = {
test.fatal = tostring(chunk) .. tostring(err)
end
end
-- save having to :release() anything we made in the last test
-- 7251ms > 7543ms
collectgarbage("collect")
-- move onto the next test
self.module.index = self.module.index + 1
end
Expand Down Expand Up @@ -124,15 +127,12 @@ TestSuite = {
-- the XML + HTML of the testsuite output
-- @return {nil}
printResult = function(self)
local finaltime = tostring(math.floor(self.time*1000))
if string.len(finaltime) == 1 then finaltime = ' ' .. finaltime end
if string.len(finaltime) == 2 then finaltime = ' ' .. finaltime end
if string.len(finaltime) == 3 then finaltime = ' ' .. finaltime end
local finaltime = UtilTimeFormat(self.time)

local xml = '<testsuites name="love.test" tests="' .. tostring(self.totals[1]) ..
'" failures="' .. tostring(self.totals[2]) ..
'" skipped="' .. tostring(self.totals[3]) ..
'" time="' .. tostring(self.time*1000) .. '">\n'
'" time="' .. finaltime .. '">\n'

local status = '🔴'
if self.totals[2] == 0 then status = '🟢' end
Expand All @@ -141,19 +141,19 @@ TestSuite = {
'<li>🟢&nbsp;' .. tostring(self.totals[1]) .. ' Tests</li>' ..
'<li>🔴&nbsp;' .. tostring(self.totals[2]) .. ' Failures</li>' ..
'<li>🟡&nbsp;' .. tostring(self.totals[3]) .. ' Skipped</li>' ..
'<li>' .. tostring(self.time*1000) .. 'ms</li></ul><br/><br/>'
'<li>' .. finaltime .. 's</li></ul><br/><br/>'

-- @TODO use mountFullPath to write output to src?
love.filesystem.createDirectory('output')
love.filesystem.write('output/' .. self.output .. '.xml', xml .. self.xml .. '</testsuites>')
love.filesystem.write('output/' .. self.output .. '.html', html .. self.html .. '</div></body></html>')

self.module:log('grey', '\nFINISHED - ' .. finaltime .. 'ms\n')
self.module:log('grey', '\nFINISHED - ' .. finaltime .. 's\n')
local failedcol = '\27[31m'
if self.totals[2] == 0 then failedcol = '\27[37m' end
self.module:log('green', tostring(self.totals[1]) .. ' PASSED' .. ' || ' .. failedcol .. tostring(self.totals[2]) .. ' FAILED || \27[37m' .. tostring(self.totals[3]) .. ' SKIPPED')

end


}
}
2 changes: 1 addition & 1 deletion testing/conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ function love.conf(t)
t.modules.timer = true
t.modules.video = true
t.modules.window = true
end
end
1 change: 1 addition & 0 deletions testing/examples/lovetest_runAllTests.html

Large diffs are not rendered by default.

Loading

0 comments on commit e03b2db

Please sign in to comment.