Browse Source

tests: compare screenshot test output to a reference image, on desktops.

Sasha Szpakowski 1 year ago
parent
commit
89f43ff48d

BIN
testing/output/expected/love.test.graphics.captureScreenshot-1.png


+ 17 - 3
testing/tests/graphics.lua

@@ -1452,15 +1452,29 @@ end
 -- love.graphics.captureScreenshot
 love.test.graphics.captureScreenshot = function(test)
   love.graphics.captureScreenshot('example-screenshot.png')
-  test:waitFrames(10)
+  test:waitFrames(1)
   -- need to wait until end of the frame for the screenshot
-  test:assertNotNil(love.filesystem.openFile('example-screenshot.png', 'r'))
+  test:assertTrue(love.filesystem.exists('example-screenshot.png'))
   love.filesystem.remove('example-screenshot.png')
   -- test callback version
+  local cbdata = nil
+  local prevtextcommand = TextCommand
+  TextCommand = "Capturing screenshot"
   love.graphics.captureScreenshot(function (idata)
     test:assertNotEquals(nil, idata, 'check we have image data')
+    cbdata = idata
   end)
-  test:waitFrames(10)
+  test:waitFrames(1)
+  TextCommand = prevtextcommand
+  test:assertNotNil(cbdata)
+
+  if love.system.getOS() == "iOS" or love.system.getOS() == "Android" then
+    -- Mobile operating systems don't let us control the window resolution,
+    -- so we can't compare the reference image properly.
+    test:assertTrue(true, 'skip test')
+  else
+    test:compareImg(cbdata)
+  end
 end