From e03b2db08bce57f276ce61fb4169e3cc84984348 Mon Sep 17 00:00:00 2001
From: ell <77150506+ellraiser@users.noreply.github.com>
Date: Thu, 5 Oct 2023 23:03:32 +0100
Subject: [PATCH] 0.2
- 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
---
testing/classes/TestMethod.lua | 26 +-
testing/classes/TestModule.lua | 11 +-
testing/classes/TestSuite.lua | 18 +-
testing/conf.lua | 2 +-
testing/examples/lovetest_runAllTests.html | 1 +
testing/examples/lovetest_runAllTests.xml | 578 +++++++++++
testing/main.lua | 8 +-
testing/output/lovetest_runAllTests.html | 1 -
testing/output/lovetest_runAllTests.xml | 385 --------
testing/readme.md | 32 +-
testing/resources/cubemap.png | Bin 0 -> 27634 bytes
testing/resources/love2.png | Bin 0 -> 680 bytes
testing/resources/love3.png | Bin 0 -> 680 bytes
testing/tests/audio.lua | 109 +--
testing/tests/data.lua | 48 +-
testing/tests/event.lua | 22 +-
testing/tests/filesystem.lua | 121 ++-
testing/tests/font.lua | 19 +-
testing/tests/graphics.lua | 1022 +++++++++++++++++++-
testing/tests/image.lua | 19 +-
testing/tests/math.lua | 75 +-
testing/tests/objects.lua | 26 +-
testing/tests/physics.lua | 103 +-
testing/tests/sound.lua | 11 +-
testing/tests/system.lua | 32 +-
testing/tests/thread.lua | 14 +-
testing/tests/timer.lua | 10 +-
testing/tests/video.lua | 6 +-
testing/tests/window.lua | 111 ++-
testing/todo.md | 26 +
30 files changed, 1976 insertions(+), 860 deletions(-)
create mode 100644 testing/examples/lovetest_runAllTests.html
create mode 100644 testing/examples/lovetest_runAllTests.xml
delete mode 100644 testing/output/lovetest_runAllTests.html
delete mode 100644 testing/output/lovetest_runAllTests.xml
create mode 100644 testing/resources/cubemap.png
create mode 100644 testing/resources/love2.png
create mode 100644 testing/resources/love3.png
create mode 100644 testing/todo.md
diff --git a/testing/classes/TestMethod.lua b/testing/classes/TestMethod.lua
index b0c763082..8fa55080f 100644
--- a/testing/classes/TestMethod.lua
+++ b/testing/classes/TestMethod.lua
@@ -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
@@ -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 = ''
@@ -309,7 +315,7 @@ TestMethod = {
-- append XML for the test class result
self.testmodule.xml = self.testmodule.xml .. '\t\t\n' ..
+ '" time="' .. endtime .. '">\n' ..
failure .. '\t\t\n'
-- unused currently, adds a preview image for certain graphics methods to the output
@@ -329,7 +335,7 @@ TestMethod = {
'
' ..
'' .. status .. ' | ' ..
'' .. self.method .. ' | ' ..
- '' .. tostring(self.finish*1000) .. 'ms | ' ..
+ '' .. endtime .. 's | ' ..
'' .. output .. preview .. ' | ' ..
'
'
@@ -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
-}
\ No newline at end of file
+}
diff --git a/testing/classes/TestModule.lua b/testing/classes/TestModule.lua
index 379aac360..9ee6cd62e 100644
--- a/testing/classes/TestModule.lua
+++ b/testing/classes/TestModule.lua
@@ -83,12 +83,13 @@ 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\n' .. self.xml .. '\t\n'
+ '" time="' .. finaltime .. '">\n' .. self.xml .. '\t\n'
-- add html to main output
local status = '🔴'
if self.failed == 0 then status = '🟢' end
@@ -96,8 +97,8 @@ TestModule = {
'🟢 ' .. tostring(self.passed) .. ' Tests' ..
'🔴 ' .. tostring(self.failed) .. ' Failures' ..
'🟡 ' .. tostring(self.skipped) .. ' Skipped' ..
- '' .. tostring(self.time*1000) .. 'ms' .. '
' ..
- ' | Method | Time | Details |
' ..
+ '- ' .. finaltime .. 's
' .. '
' ..
+ ' | Method | Time | Details |
' ..
self.html .. '
'
-- print module results to console
self:log('yellow', 'love.' .. self.module .. '.testmodule.end')
@@ -105,10 +106,10 @@ TestModule = {
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
-}
\ No newline at end of file
+}
diff --git a/testing/classes/TestSuite.lua b/testing/classes/TestSuite.lua
index 234019c8f..9552b5aee 100644
--- a/testing/classes/TestSuite.lua
+++ b/testing/classes/TestSuite.lua
@@ -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},
@@ -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
@@ -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 = '\n'
+ '" time="' .. finaltime .. '">\n'
local status = '🔴'
if self.totals[2] == 0 then status = '🟢' end
@@ -141,14 +141,14 @@ TestSuite = {
'- 🟢 ' .. tostring(self.totals[1]) .. ' Tests
' ..
'- 🔴 ' .. tostring(self.totals[2]) .. ' Failures
' ..
'- 🟡 ' .. tostring(self.totals[3]) .. ' Skipped
' ..
- '- ' .. tostring(self.time*1000) .. 'ms
'
+ '- ' .. finaltime .. 's
'
-- @TODO use mountFullPath to write output to src?
love.filesystem.createDirectory('output')
love.filesystem.write('output/' .. self.output .. '.xml', xml .. self.xml .. '')
love.filesystem.write('output/' .. self.output .. '.html', html .. self.html .. '