Skip to content

Commit

Permalink
added all graphics 'state' tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ellraiser committed Oct 8, 2023
1 parent 8f10ba9 commit e1948f6
Show file tree
Hide file tree
Showing 10 changed files with 506 additions and 151 deletions.
51 changes: 25 additions & 26 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ jobs:
with:
name: love-x86_64-AppImage-debug
path: love-${{ github.sha }}.AppImage-debug.tar.gz
- name: Make Runnable
run: chmod a+x love-linux-x86_64.AppImage
- name: Run All Tests
run: xvfb-run love-linux-x86_64.AppImage testing
- name: Love Test Report
uses: ellraiser/love-test-report@main
with:
name: Love Testsuite Linux
title: linux-test-report
path: testing/output/lovetest_runAllTests.md
windows-os:
runs-on: windows-latest
strategy:
Expand Down Expand Up @@ -208,25 +218,22 @@ jobs:
- name: Build Test Exe
if: steps.vars.outputs.arch != 'ARM64'
run: cmake --build build --config Release --target install
- name: Run All Tests (OpenGL)
- name: Install Mesa
if: steps.vars.outputs.arch != 'ARM64'
run: install\lovec.exe testing/main.lua
- name: Love Test Report (OpenGL)
if: steps.vars.outputs.arch != 'ARM64'
uses: ellraiser/love-test-report@main
with:
name: Love Testsuite Windows (OpenGL)
title: windows-${{ steps.vars.outputs.arch }}${{ steps.vars.outputs.compatname }}-test-report-opengl
path: testing/output/lovetest_runAllTests.md
- name: Run All Tests (Vulkan)
run: |
curl.exe -L --output mesa.7z --url https://github.com/pal1000/mesa-dist-win/releases/download/23.2.1/mesa3d-23.2.1-release-msvc.7z
7z x mesa.7z
mklink opengl32.dll "x64\opengl32.dll"
mklink libglapi.dll "x64\libglapi.dll"
- name: Run All Tests
if: steps.vars.outputs.arch != 'ARM64'
run: install\lovec.exe testing/main.lua --renderers vulkan
- name: Love Test Report (Vulkan)
run: install\lovec.exe testing/main.lua
- name: Love Test Report
if: steps.vars.outputs.arch != 'ARM64'
uses: ellraiser/love-test-report@main
with:
name: Love Testsuite Windows (Vulkan)
title: windows-${{ steps.vars.outputs.arch }}${{ steps.vars.outputs.compatname }}-test-report-vulkan
name: Love Testsuite Windows
title: windows-${{ steps.vars.outputs.arch }}${{ steps.vars.outputs.compatname }}-test-report
path: testing/output/lovetest_runAllTests.md
macOS:
runs-on: macos-latest
Expand Down Expand Up @@ -256,21 +263,13 @@ jobs:
with:
name: love-macos
path: love-macos.zip
- name: Run All Tests (OpenGL)
- name: Run All Tests
run: love-macos/love.app/Contents/MacOS/love testing
- name: Love Test Report (OpenGL)
uses: ellraiser/love-test-report@main
with:
name: Love Testsuite MacOS (OpenGL)
title: macos-test-report-opengl
path: testing/output/lovetest_runAllTests.md
- name: Run All Tests (metal)
run: love-macos/love.app/Contents/MacOS/love testing --renderers metal
- name: Love Test Report (metal)
- name: Love Test Report
uses: ellraiser/love-test-report@main
with:
name: Love Testsuite MacOS (Metal)
title: macos-test-report-metal
name: Love Testsuite MacOS
title: macos-test-report
path: testing/output/lovetest_runAllTests.md
iOS-Simulator:
runs-on: macos-latest
Expand Down
37 changes: 34 additions & 3 deletions testing/classes/TestMethod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ TestMethod = {
result = {},
colors = {
red = {1, 0, 0, 1},
redpale = {1, 0.5, 0.5, 1},
red07 = {0.7, 0, 0, 1},
green = {0, 1, 0, 1},
greenhalf = {0, 0.5, 0, 1},
greenfade = {0, 1, 0, 0.5},
blue = {0, 0, 1, 1},
bluefade = {0, 0, 1, 0.5},
yellow = {1, 1, 0, 1},
black = {0, 0, 0, 1},
white = {1, 1, 1, 1}
}
},
delay = 0,
delayed = false
}
setmetatable(test, self)
self.__index = self
Expand Down Expand Up @@ -69,6 +77,11 @@ TestMethod = {
local coord = pixels[p]
local tr, tg, tb, ta = imgdata:getPixel(coord[1], coord[2])
local compare_id = tostring(coord[1]) .. ',' .. tostring(coord[2])
-- prevent us getting stuff like 0.501960785 for 0.5 red
tr = math.floor((tr*10)+0.5)/10
tg = math.floor((tg*10)+0.5)/10
tb = math.floor((tb*10)+0.5)/10
ta = math.floor((ta*10)+0.5)/10
-- @TODO add some sort pixel tolerance to the coords
self:assertEquals(col[1], tr, 'check pixel r for ' .. i .. ' at ' .. compare_id .. '(' .. label .. ')')
self:assertEquals(col[2], tg, 'check pixel g for ' .. i .. ' at ' .. compare_id .. '(' .. label .. ')')
Expand Down Expand Up @@ -201,12 +214,19 @@ TestMethod = {
-- @desc - quick assert for value not nil
-- @param {any} value - value to check not nil
-- @return {nil}
assertNotNil = function (self, value)
assertNotNil = function (self, value, err)
self:assertNotEquals(nil, value, 'check not nil')
if err ~= nil then
table.insert(self.asserts, {
key = 'assert #' .. tostring(self.count),
passed = false,
message = err,
test = 'assert not nil catch'
})
end
end,



-- @method - TestMethod:skipTest()
-- @desc - used to mark this test as skipped for a specific reason
-- @param {string} reason - reason why method is being skipped
Expand All @@ -217,6 +237,17 @@ TestMethod = {
end,


-- currently unused
setDelay = function(self, frames)
self.delay = frames
self.delayed = true
love.test.delayed = self
end,
isDelayed = function(self)
return self.delayed
end,


-- @method - TestMethod:evaluateTest()
-- @desc - evaluates the results of all assertions for a final restult
-- @return {nil}
Expand Down
51 changes: 40 additions & 11 deletions testing/classes/TestSuite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ TestSuite = {
-- testsuite internals
modules = {},
module = nil,
test = nil,
testcanvas = nil,
current = 1,
output = '',
Expand All @@ -19,6 +20,7 @@ TestSuite = {
html = '',
mdrows = '',
mdfailures = '',
delayed = nil,
fakequit = false,
windowmode = true,

Expand Down Expand Up @@ -70,7 +72,8 @@ TestSuite = {
if self.module.called[self.module.index] == nil then
self.module.called[self.module.index] = true
local method = self.module.running[self.module.index]
local test = TestMethod:new(method, self.module)
self.test = TestMethod:new(method, self.module)
TextRun:set('love.' .. self.module.module .. '.' .. method)

-- check method exists in love first
if self.module.module ~= 'objects' and (love[self.module.module] == nil or love[self.module.module][method] == nil) then
Expand All @@ -80,26 +83,52 @@ TestSuite = {
tested .. matching,
' ==> FAIL (0/0) - call failed - method does not exist'
)
-- otherwise run the test method then eval the asserts
-- otherwise run the test method
else
local ok, chunk, err = pcall(self[self.module.module][method], test)
local ok, chunk, err = pcall(self[self.module.module][method], self.test)
if ok == false then
print("FATAL", chunk, err)
test.fatal = tostring(chunk) .. tostring(err)
self.test.fatal = tostring(chunk) .. tostring(err)
end
local ok, chunk, err = pcall(test.evaluateTest, test)
end

-- once we've run check delay + eval
else

-- @TODO use coroutines?
-- if we have a test method that needs a delay
-- we wait for the delay to run out first
if self.delayed ~= nil then
self.delayed.delay = self.delayed.delay - 1
-- re-run the test method again when delay ends
-- its up to the test to handle the :isDelayed() property
if self.delayed.delay <= 0 then
local ok, chunk, err = pcall(self[self.module.module][self.delayed.method], self.test)
if ok == false then
print("FATAL", chunk, err)
self.test.fatal = tostring(chunk) .. tostring(err)
end
self.delayed = nil
end
else

-- now we're all done evaluate the test
local ok, chunk, err = pcall(self.test.evaluateTest, self.test)
if ok == false then
print("FATAL", chunk, err)
test.fatal = tostring(chunk) .. tostring(err)
self.test.fatal = tostring(chunk) .. tostring(err)
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
-- 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

-- once all tests have run
else

-- print module results and add to output
Expand Down
4 changes: 2 additions & 2 deletions testing/conf.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function love.conf(t)
t.console = true
t.window.name = 'love.test'
t.window.width = 256
t.window.height = 256
t.window.width = 360
t.window.height = 240
t.window.resizable = true
t.renderers = {"opengl"}
t.modules.audio = true
Expand Down
44 changes: 31 additions & 13 deletions testing/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ love.load = function(args)

-- setup basic img to display
if love.window ~= nil then
love.window.setMode(256, 256, {
love.window.setMode(360, 240, {
fullscreen = false,
resizable = true,
centered = true
Expand All @@ -47,6 +47,9 @@ love.load = function(args)
img = nil
}
Logo.img = love.graphics.newQuad(0, 0, 64, 64, Logo.texture)
Font = love.graphics.newFont('resources/font.ttf', 8, 'normal')
TextCommand = love.graphics.newTextBatch(Font, 'Loading...')
TextRun = love.graphics.newTextBatch(Font, '')
end
end

Expand All @@ -63,6 +66,7 @@ love.load = function(args)
local testcmd = '--runAllTests'
local module = ''
local method = ''
local cmderr = 'Invalid flag used'
local modules = {
'audio', 'data', 'event', 'filesystem', 'font', 'graphics',
'image', 'math', 'objects', 'physics', 'sound', 'system',
Expand Down Expand Up @@ -97,9 +101,14 @@ love.load = function(args)
if testcmd == '--runSpecificMethod' then
local testmodule = TestModule:new(module, method)
table.insert(love.test.modules, testmodule)
love.test.module = testmodule
love.test.module:log('grey', '--runSpecificMethod "' .. module .. '" "' .. method .. '"')
love.test.output = 'lovetest_runSpecificMethod_' .. module .. '_' .. method
if module ~= '' and method ~= '' then
love.test.module = testmodule
love.test.module:log('grey', '--runSpecificMethod "' .. module .. '" "' .. method .. '"')
love.test.output = 'lovetest_runSpecificMethod_' .. module .. '_' .. method
else
if method == '' then cmderr = 'No valid method specified' end
if module == '' then cmderr = 'No valid module specified' end
end
end

-- runSpecificModules runs all methods for all the modules given
Expand All @@ -110,10 +119,13 @@ love.load = function(args)
table.insert(love.test.modules, testmodule)
table.insert(modulelist, modules[m])
end

love.test.module = love.test.modules[1]
love.test.module:log('grey', '--runSpecificModules "' .. table.concat(modulelist, '" "') .. '"')
love.test.output = 'lovetest_runSpecificModules_' .. table.concat(modulelist, '_')
if #modulelist > 0 then
love.test.module = love.test.modules[1]
love.test.module:log('grey', '--runSpecificModules "' .. table.concat(modulelist, '" "') .. '"')
love.test.output = 'lovetest_runSpecificModules_' .. table.concat(modulelist, '_')
else
cmderr = 'No modules specified'
end
end

-- otherwise default runs all methods for all modules
Expand All @@ -129,12 +141,14 @@ love.load = function(args)

-- invalid command
if love.test.module == nil then
print("Wrong flags used")
print(cmderr)
love.event.quit(0)
else
-- start first module
TextCommand:set(testcmd)
love.test.module:runTests()
end

-- start first module
love.test.module:runTests()

end

-- love.update
Expand All @@ -147,7 +161,11 @@ end
-- love.draw
-- draw a little logo to the screen
love.draw = function()
love.graphics.draw(Logo.texture, Logo.img, 64, 64, 0, 2, 2)
local lw = (love.graphics.getPixelWidth() - 128) / 2
local lh = (love.graphics.getPixelHeight() - 128) / 2
love.graphics.draw(Logo.texture, Logo.img, lw, lh, 0, 2, 2)
love.graphics.draw(TextCommand, 4, 12, 0, 2, 2)
love.graphics.draw(TextRun, 4, 32, 0, 2, 2)
end


Expand Down
Loading

0 comments on commit e1948f6

Please sign in to comment.