Skip to content

Commit

Permalink
remove diff. img if no longer different in next run
Browse files Browse the repository at this point in the history
  • Loading branch information
ellraiser committed Mar 22, 2024
1 parent 64059a0 commit e0c8e63
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions classes/TestMethod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ TestMethod = {
local ih = imgdata:getHeight()-1
local differences = {}
local rgba_tolerance = self.rgba_tolerance * (1/255)

-- for each pixel, compare the expected vs the actual pixel data
-- by default rgba_tolerance is 0
for ix=0,iw do
for iy=0,ih do
local ir, ig, ib, ia = imgdata:getPixel(ix, iy)
Expand Down Expand Up @@ -318,6 +321,7 @@ TestMethod = {
tostring(ix) .. ',' .. tostring(iy) .. ', matching = ' .. ymatch ..
', not matching = ' .. nmatch .. ' (' .. self.method .. '-' .. tostring(self.imgs) .. ')'
)
-- add difference co-ord for rendering later
if matching ~= true then
table.insert(differences, ix+1)
table.insert(differences, iy+1)
Expand All @@ -327,6 +331,10 @@ TestMethod = {
local path = 'tempoutput/actual/love.test.graphics.' ..
self.method .. '-' .. tostring(self.imgs) .. '.png'
imgdata:encode('png', path)

-- if we have differences draw them to a new canvas to display in HTML report
local dpath = 'tempoutput/difference/love.test.graphics.' ..
self.method .. '-' .. tostring(self.imgs) .. '.png'
if #differences > 0 then
local difference = love.graphics.newCanvas(iw+1, ih+1)
love.graphics.setCanvas(difference)
Expand All @@ -335,10 +343,14 @@ TestMethod = {
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)

-- otherwise clear the old difference file (if any) to stop it coming up
-- in future reports when there's no longer a difference
elseif love.filesystem.openFile(dpath, 'r') then
love.filesystem.remove(dpath)
end

self.imgs = self.imgs + 1
end,

Expand Down

0 comments on commit e0c8e63

Please sign in to comment.