Skip to content

Commit

Permalink
testsuite updates
Browse files Browse the repository at this point in the history
- added some additional checks to check for lua version/jit enabled for use with other repos (namely love potion)
- updated HTML report to group each image compare and fix pixel rendering
- fixed not showing image checks for the 4th compareImg or more in a given test method
- fixed pixel tolerance usage crashing when looking at images on the boundary
- fixed compare img not checking the first 2 rows of pixels on the x + y
  • Loading branch information
ellraiser committed Mar 22, 2024
1 parent 7bd6c27 commit 9582e1c
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
/output/*.html
/output/*.md
/output/actual/*.png
/output/difference/*.png
resources/.DS_Store
resources/.DS_Store
63 changes: 40 additions & 23 deletions classes/TestMethod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -275,24 +275,25 @@ TestMethod = {
local ok, chunk, _ = pcall(love.image.newImageData, expected_path)
if ok == false then return self:assertEquals(true, false, chunk) end
local expected = chunk
local iw = imgdata:getWidth()-2
local ih = imgdata:getHeight()-2
local iw = imgdata:getWidth()-1
local ih = imgdata:getHeight()-1
local differences = {}
local rgba_tolerance = self.rgba_tolerance * (1/255)
for ix=2,iw do
for iy=2,ih do
for ix=0,iw do
for iy=0,ih do
local ir, ig, ib, ia = imgdata:getPixel(ix, iy)
local points = {
{expected:getPixel(ix, iy)}
}
if self.pixel_tolerance > 0 then
table.insert(points, {expected:getPixel(ix-1, iy+1)})
table.insert(points, {expected:getPixel(ix-1, iy)})
table.insert(points, {expected:getPixel(ix-1, iy-1)})
table.insert(points, {expected:getPixel(ix, iy+1)})
table.insert(points, {expected:getPixel(ix, iy-1)})
table.insert(points, {expected:getPixel(ix+1, iy+1)})
table.insert(points, {expected:getPixel(ix+1, iy)})
table.insert(points, {expected:getPixel(ix+1, iy-1)})
if ix > 0 and iy < ih-1 then table.insert(points, {expected:getPixel(ix-1, iy+1)}) end
if ix > 0 then table.insert(points, {expected:getPixel(ix-1, iy)}) end
if ix > 0 and iy > 0 then table.insert(points, {expected:getPixel(ix-1, iy-1)}) end
if iy < ih-1 then table.insert(points, {expected:getPixel(ix, iy+1)}) end
if iy > 0 then table.insert(points, {expected:getPixel(ix, iy-1)}) end
if ix < iw-1 and iy < ih-1 then table.insert(points, {expected:getPixel(ix+1, iy+1)}) end
if ix < iw-1 then table.insert(points, {expected:getPixel(ix+1, iy)}) end
if ix < iw-1 and iy > 0 then table.insert(points, {expected:getPixel(ix+1, iy-1)}) end
end
local has_match_r = false
local has_match_g = false
Expand All @@ -317,11 +318,27 @@ TestMethod = {
tostring(ix) .. ',' .. tostring(iy) .. ', matching = ' .. ymatch ..
', not matching = ' .. nmatch .. ' (' .. self.method .. '-' .. tostring(self.imgs) .. ')'
)
if matching ~= true then
table.insert(differences, ix+1)
table.insert(differences, iy+1)
end
end
end
local path = 'tempoutput/actual/love.test.graphics.' ..
self.method .. '-' .. tostring(self.imgs) .. '.png'
imgdata:encode('png', path)
if #differences > 0 then
local difference = love.graphics.newCanvas(iw+1, ih+1)
love.graphics.setCanvas(difference)
love.graphics.clear(0, 0, 0, 1)
love.graphics.setColor(1, 0, 1, 1)
love.graphics.points(differences)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setCanvas()
local dpath = 'tempoutput/difference/love.test.graphics.' ..
self.method .. '-' .. tostring(self.imgs) .. '.png'
love.graphics.readbackTexture(difference):encode('png', dpath)
end
self.imgs = self.imgs + 1
end,

Expand Down Expand Up @@ -532,17 +549,17 @@ TestMethod = {
local preview = ''
if self.testmodule.module == 'graphics' then
local filename = 'love.test.graphics.' .. self.method
if love.filesystem.openFile('tempoutput/actual/' .. filename .. '-1.png', 'r') then
preview = '<div class="preview">' .. '<img src="expected/' .. filename .. '-1.png"/><p>Expected</p></div>' ..
'<div class="preview">' .. '<img src="actual/' .. filename .. '-1.png"/><p>Actual</p></div>'
end
if love.filesystem.openFile('tempoutput/actual/' .. filename .. '-2.png', 'r') then
preview = preview .. '<div class="preview">' .. '<img src="expected/' .. filename .. '-2.png"/><p>Expected</p></div>' ..
'<div class="preview">' .. '<img src="actual/' .. filename .. '-2.png"/><p>Actual</p></div>'
end
if love.filesystem.openFile('tempoutput/actual/' .. filename .. '-3.png', 'r') then
preview = preview .. '<div class="preview">' .. '<img src="expected/' .. filename .. '-3.png"/><p>Expected</p></div>' ..
'<div class="preview">' .. '<img src="actual/' .. filename .. '-3.png"/><p>Actual</p></div>'
for f=1,5 do
local fstr = tostring(f)
if love.filesystem.openFile('tempoutput/actual/' .. filename .. '-' .. fstr .. '.png', 'r') then
preview = preview .. '<div class="preview-wrap">'
preview = preview .. '<div class="preview">' .. '<img src="expected/' .. filename .. '-' .. fstr .. '.png"/><p>Expected</p></div>' ..
'<div class="preview">' .. '<img src="actual/' .. filename .. '-' .. fstr .. '.png"/><p>Actual</p></div>'
if love.filesystem.openFile('tempoutput/difference/' .. filename .. '-' .. fstr .. '.png', 'r') then
preview = preview .. '<div class="preview">' .. '<img src="difference/' .. filename .. '-' .. fstr .. '.png"/><p>Difference</p></div>'
end
preview = preview .. '</div>'
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion classes/TestSuite.lua
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ TestSuite = {

local status = '🔴'
if self.totals[2] == 0 then status = '🟢' end
local html = '<html><head><style>* { font-family: monospace; margin: 0; font-size: 11px; padding: 0; } body { margin: 50px; } h1 { padding-bottom: 10px; font-size: 13px; } h2 { padding: 20px 0 10px 0; font-size: 12px; } .summary { list-style: none; margin: 0; padding: 0; } .summary li { float: left; background: #eee; padding: 5px; margin-right: 10px; } table { background: #eee; margin-top: 10px; width: 100%; max-width: 800px; border-collapse: collapse } table thead { background: #ddd; } table th, table td { padding: 2px; } tr.red { color: red } .wrap { max-width: 800px; margin: auto; } .preview { width: 64px; height: 80px; float: left; margin-right: 10px; } .preview img { width: 100% } .preview p { text-align: center; }</style></head><body><div class="wrap"><h1>' .. status .. '&nbsp;love.test</h1><ul class="summary">'
local html = '<html><head><style>* { font-family: monospace; margin: 0; font-size: 11px; padding: 0; } body { margin: 50px; } h1 { padding-bottom: 10px; font-size: 13px; } h2 { padding: 20px 0 10px 0; font-size: 12px; } .summary { list-style: none; margin: 0; padding: 0; } .summary li { float: left; background: #eee; padding: 5px; margin-right: 10px; } table { background: #eee; margin-top: 10px; width: 100%; max-width: 800px; border-collapse: collapse } table thead { background: #ddd; } table th, table td { padding: 2px; } tr.red { color: red } .wrap { max-width: 800px; margin: auto; } .preview-wrap { display: inline-block; height: 80px; padding: 5px 0 0 5px; margin: 5px; background: #ccc; } .preview { width: 64px; height: 80px; float: left; margin-right: 10px; } .preview:nth-last-child(1) { margin-right: 5px; } .preview img { width: 100%; image-rendering: pixelated; } .preview p { text-align: center; }</style></head><body><div class="wrap"><h1>' .. status .. '&nbsp;love.test</h1><ul class="summary">'
html = html ..
'<li>🟢&nbsp;' .. tostring(self.totals[1]) .. ' Tests</li>' ..
'<li>🔴&nbsp;' .. tostring(self.totals[2]) .. ' Failures</li>' ..
Expand Down
3 changes: 3 additions & 0 deletions output/difference/notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Graphic Differences
If a graphics test fails then a "difference" image will be created to highlight
the differences between the actual + expected image, for use in the HTML report
2 changes: 0 additions & 2 deletions todo.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ These are all the outstanding methods that require test coverage, along with a f
- love.graphics.drawIndirect()
- love.graphics.getQuadIndexBuffer()
- love.graphics.setBlendState()
- love.graphics.setOrthoProjection()
- love.graphics.setPerspectiveProjection()
- love.graphics.resetProjection()
- love.graphics.Mesh:getAttachedAttributes()
- love.graphics.Shader:hasStage()

0 comments on commit 9582e1c

Please sign in to comment.