From 7f4adc0ffeb4168930e766d3195b3e5337b1e3be Mon Sep 17 00:00:00 2001 From: ell <77150506+ellraiser@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:05:06 +0000 Subject: [PATCH] small update changed tests so that all assert failures are logged rather than just the first assert that failed, added isOS() to the test method class to be used in tests directly, updated test readme on a couple bits and added newTexture basic check --- testing/classes/TestMethod.lua | 79 +++++++++++++++++++++++++++------- testing/classes/TestSuite.lua | 15 ++++++- testing/main.lua | 3 ++ testing/readme.md | 14 +++--- testing/tests/audio.lua | 2 +- testing/tests/filesystem.lua | 2 +- testing/tests/graphics.lua | 45 +++++++++++-------- testing/todo.md | 2 - 8 files changed, 114 insertions(+), 48 deletions(-) diff --git a/testing/classes/TestMethod.lua b/testing/classes/TestMethod.lua index 1f336d06b..931dad850 100644 --- a/testing/classes/TestMethod.lua +++ b/testing/classes/TestMethod.lua @@ -374,23 +374,42 @@ TestMethod = { end, + -- @method - TestMethod:isOS() + -- @desc - checks for a specific OS (or list of OSs) + -- @param {string||table} - single OS string or list of OSs that are allowed, + -- these will be checked agaisnt love.system.getOS()'s return value + -- @return {boolean} - returns true if one of the OSs given matches actual OS + isOS = function(self, oss) + if type(oss) == 'table' then + for o=1,#oss do + if oss[o] == love.test.current_os then return true end + end + else + return love.test.current_os == oss + end + end, + -- @method - TestMethod:evaluateTest() -- @desc - evaluates the results of all assertions for a final restult -- @return {nil} evaluateTest = function(self) local failure = '' local failures = 0 + + -- check all asserts for failures, additional failures are also printed + local assert_failures = {} for a=1,#self.asserts do - -- @TODO show all failed assertion methods? - -- currently just shows the first assert that failed if not self.asserts[a].passed and not self.skipped then if failure == '' then failure = self.asserts[a] end + table.insert(assert_failures, self.asserts[a]) failures = failures + 1 end end if self.fatal ~= '' then failure = self.fatal end local passed = tostring(#self.asserts - failures) local total = '(' .. passed .. '/' .. tostring(#self.asserts) .. ')' + + -- skipped tests have a special log if self.skipped then self.testmodule.skipped = self.testmodule.skipped + 1 love.test.totals[3] = love.test.totals[3] + 1 @@ -398,9 +417,12 @@ TestMethod = { total = '', result = "SKIP", passed = false, - message = '(0/0) - method skipped [' .. self.skipreason .. ']' + message = '(0/0) - method skipped [' .. self.skipreason .. ']', + failures = {} } else + + -- if no failure but has asserts, then passed if failure == '' and #self.asserts > 0 then self.passed = true self.testmodule.passed = self.testmodule.passed + 1 @@ -409,38 +431,48 @@ TestMethod = { total = total, result = 'PASS', passed = true, - message = nil + message = nil, + failures = {} } + + -- otherwise it failed else self.passed = false self.testmodule.failed = self.testmodule.failed + 1 love.test.totals[2] = love.test.totals[2] + 1 + + -- no asserts means invalid test if #self.asserts == 0 then local msg = 'no asserts defined' if self.fatal ~= '' then msg = self.fatal end - self.result = { - total = total, - result = 'FAIL', - passed = false, - key = 'test', - message = msg + self.result = { + total = total, + result = 'FAIL', + passed = false, + key = 'test', + message = msg, + failures = {} } + + -- otherwise we had failures, log the first and supply the list of + -- additional failures if any for printResult() else local key = failure['key'] if failure['test'] ~= nil then key = key .. ' [' .. failure['test'] .. ']' end local msg = failure['message'] - if self.fatal ~= '' then + if self.fatal ~= '' then key = 'code' msg = self.fatal end - self.result = { - total = total, - result = 'FAIL', - passed = false, + self.result = { + total = total, + result = 'FAIL', + passed = false, key = key, - message = msg + message = msg, + failures = assert_failures } end end @@ -535,6 +567,21 @@ TestMethod = { ' ==> ' .. self.result.result .. ' - ' .. endtime .. 's ' .. self.result.total .. msg ) + + -- if we failed on multiple asserts, list them here - makes it easier for + -- debugging new methods added that are failing multiple asserts + if #self.result.failures > 1 then + for f=2,#self.result.failures do + local addf = self.result.failures[f] + self.testmodule:log( + self.testmodule.colors[self.result.result], + ' ' .. tested .. matching, + ' ==> ' .. + addf['key'] .. ' [' .. addf['test'] .. '] failed - ' .. addf['message'] + ) + end + end + end diff --git a/testing/classes/TestSuite.lua b/testing/classes/TestSuite.lua index 8a2e76dee..a5c3e841a 100644 --- a/testing/classes/TestSuite.lua +++ b/testing/classes/TestSuite.lua @@ -23,6 +23,7 @@ TestSuite = { delayed = nil, fakequit = false, windowmode = true, + current_os = love.system.getOS(), -- love modules to test audio = {}, @@ -76,7 +77,10 @@ TestSuite = { TextRun = 'love.' .. self.module.module .. '.' .. method self.test.co = coroutine.create(function() - local ok, chunk, err = pcall(love.test[love.test.module.module][method], love.test.test) + local ok, chunk, err = pcall( + love.test[love.test.module.module][method], + love.test.test + ) if ok == false then love.test.test['passed'] = false love.test.test['fatal'] = tostring(chunk) .. tostring(err) @@ -140,7 +144,14 @@ TestSuite = { printResult = function(self) local finaltime = UtilTimeFormat(self.time) - local name, version, vendor, device = love.graphics.getRendererInfo() + -- in case we dont have love.graphics loaded, for future module specific disabling + local name = 'NONE' + local version = 'NONE' + local vendor = 'NONE' + local device = 'NONE' + if love.graphics then + name, version, vendor, device = love.graphics.getRendererInfo() + end local md = '