test updates

- update main love readme to include note on tests
- added module tests for Sensor, Keyboard, Touch, Joystick, Mouse, and Love (for hooks + basic love-level methods)
- general clean-up of main class logic
- couple fixes for runner-specific failures (physics.Joint, audio.getActiveSourceCount, mouse.getPosition)
- change window.close test to run last
This commit is contained in:
ell
2023-12-04 16:13:38 +00:00
parent 8951635abc
commit 2875a96e92
19 changed files with 2917 additions and 381 deletions
+13
View File
@@ -29,6 +29,16 @@ There are also unstable/nightly builds:
- For ubuntu linux they are in [ppa:bartbes/love-unstable][unstableppa]
- For arch linux there's [love-git][aur] in the AUR.
Test Suite
----------
The test suite in `testing/` covers all the LÖVE APIs, and tests them the same way developers use them. You can view current test coverage from any [12.0-dev action][12devworkflows].
You can run the suite locally like you would run a normal LÖVE project, i.e.:
`love testing/main.lua`
See the [readme][testsuite] in the testing folder for more info.
You can contribute to the test suite [here][testsuitemain]
Contributing
------------
@@ -107,3 +117,6 @@ Dependencies
[codestyle]: https://love2d.org/wiki/Code_Style
[android-repository]: https://github.com/love2d/love-android
[releases]: https://github.com/love2d/love/releases
[testsuite]: https://github.com/love2d/love/tree/12.0-development/testing
[testsuitemain]: https://github.com/ellraiser/love-test
[12devworkflows]: https://github.com/love2d/love/actions/workflows/main.yml?query=branch%3A12.0-development
+13 -14
View File
@@ -126,11 +126,11 @@ TestMethod = {
-- @method - TestMethod:assertPixels()
-- @desc - checks a list of coloured pixels agaisnt given imgdata
-- @param {ImageData} imgdata - image data to check
-- @param {table} pixels - map of colors to list of pixel coords, i.e.
-- { blue = { {1, 1}, {2, 2}, {3, 4} } }
-- @param {table} pixelchecks - map of colors to list of pixel coords, i.e.
-- { blue = { {1, 1}, {2, 2}, {3, 4} } }
-- @return {nil}
assertPixels = function(self, imgdata, pixels, label)
for i, v in pairs(pixels) do
assertPixels = function(self, imgdata, pixelchecks, label)
for i, v in pairs(pixelchecks) do
local col = self.colors[i]
local pixels = v
for p=1,#pixels do
@@ -379,9 +379,9 @@ TestMethod = {
local failure = ''
local failures = 0
for a=1,#self.asserts do
-- @TODO just return first failed assertion msg? or all?
-- @TODO show all failued assertion methods?
-- currently just shows the first assert that failed
if self.asserts[a].passed == false and self.skipped == false then
if not self.asserts[a].passed and not self.skipped then
if failure == '' then failure = self.asserts[a] end
failures = failures + 1
end
@@ -389,7 +389,7 @@ TestMethod = {
if self.fatal ~= '' then failure = self.fatal end
local passed = tostring(#self.asserts - failures)
local total = '(' .. passed .. '/' .. tostring(#self.asserts) .. ')'
if self.skipped == true then
if self.skipped then
self.testmodule.skipped = self.testmodule.skipped + 1
love.test.totals[3] = love.test.totals[3] + 1
self.result = {
@@ -454,7 +454,6 @@ TestMethod = {
printResult = function(self)
-- get total timestamp
-- @TODO make nicer, just need a 3DP ms value
self.finish = love.timer.getTime() - self.start
love.test.time = love.test.time + self.finish
self.testmodule.time = self.testmodule.time + self.finish
@@ -463,7 +462,7 @@ TestMethod = {
-- get failure/skip message for output (if any)
local failure = ''
local output = ''
if self.passed == false and self.skipped == false then
if not self.passed and not self.skipped then
failure = '\t\t\t<failure message="' .. self.result.key .. ' ' ..
self.result.message .. '">' .. self.result.key .. ' ' .. self.result.message .. '</failure>\n'
output = self.result.key .. ' ' .. self.result.message
@@ -471,7 +470,7 @@ TestMethod = {
love.test.mdfailures = love.test.mdfailures .. '> 🔴 ' .. self.method .. ' \n' ..
'> ' .. output .. ' \n\n'
end
if output == '' and self.skipped == true then
if output == '' and self.skipped then
failure = '\t\t\t<skipped message="' .. self.skipreason .. '" />\n'
output = self.skipreason
end
@@ -504,8 +503,8 @@ TestMethod = {
-- append HTML for the test class result
local status = '🔴'
local cls = 'red'
if self.passed == true then status = '🟢'; cls = '' end
if self.skipped == true then status = '🟡'; cls = '' end
if self.passed then status = '🟢'; cls = '' end
if self.skipped then status = '🟡'; cls = '' end
self.testmodule.html = self.testmodule.html ..
'<tr class=" ' .. cls .. '">' ..
'<td>' .. status .. '</td>' ..
@@ -516,11 +515,11 @@ TestMethod = {
-- add message if assert failed
local msg = ''
if self.result.message ~= nil and self.skipped == false then
if self.result.message ~= nil and not self.skipped then
msg = ' - ' .. self.result.key ..
' failed - (' .. self.result.message .. ')'
end
if self.skipped == true then
if self.skipped then
msg = self.result.message
end
+7 -4
View File
@@ -33,9 +33,12 @@ TestSuite = {
graphics = {},
image = {},
joystick = {},
love = {},
keyboard = {},
math = {},
mouse = {},
physics = {},
sensor = {},
sound = {},
system = {},
thread = {},
@@ -60,7 +63,7 @@ TestSuite = {
-- stagger between tests
if self.module ~= nil then
if self.module.start == true then
if self.module.start then
-- work through each test method 1 by 1
if self.module.index <= #self.module.running then
@@ -70,13 +73,13 @@ TestSuite = {
self.module.called[self.module.index] = true
local method = self.module.running[self.module.index]
self.test = TestMethod:new(method, self.module)
TextRun:set('love.' .. self.module.module .. '.' .. method)
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)
if ok == false then
love.test.test.passed = false
love.test.test.fatal = tostring(chunk) .. tostring(err)
love.test.test['passed'] = false
love.test.test['fatal'] = tostring(chunk) .. tostring(err)
end
end)
-16
View File
@@ -5,20 +5,4 @@ function love.conf(t)
t.window.height = 240
t.window.resizable = true
t.renderers = {"opengl"}
t.modules.audio = true
t.modules.data = true
t.modules.event = true
t.modules.filesystem = true
t.modules.font = true
t.modules.graphics = true
t.modules.image = true
t.modules.math = true
t.modules.objects = true
t.modules.physics = true
t.modules.sound = true
t.modules.system = true
t.modules.thread = true
t.modules.timer = true
t.modules.video = true
t.modules.window = true
end
File diff suppressed because one or more lines are too long
+21 -15
View File
@@ -1,27 +1,33 @@
<!-- PASSED 287 || FAILED 0 || SKIPPED 14 || TIME 14.726 -->
<!-- PASSED 339 || FAILED 0 || SKIPPED 9 || TIME 14.445 -->
### Info
**301** tests were completed in **14.726s** with **287** passed, **0** failed, and **14** skipped
**348** tests were completed in **14.445s** with **339** passed, **0** failed, and **9** skipped
Renderer: OpenGL | 4.1 Metal - 76.3 | Apple | Apple M1 Max
### Report
| Module | Pass | Fail | Skip | Time |
| --------------------- | ------ | ------ | ------- | ------ |
| 🟢 audio | 28 | 0 | 0 | 0.894s |
| 🟢 audio | 28 | 0 | 0 | 0.865s |
| 🟢 data | 12 | 0 | 0 | 0.209s |
| 🟢 event | 4 | 0 | 2 | 0.103s |
| 🟢 filesystem | 29 | 0 | 2 | 0.550s |
| 🟢 font | 7 | 0 | 0 | 0.124s |
| 🟢 graphics | 102 | 0 | 3 | 3.231s |
| 🟢 image | 5 | 0 | 0 | 0.098s |
| 🟢 math | 20 | 0 | 0 | 0.353s |
| 🟢 physics | 23 | 0 | 3 | 0.449s |
| 🟢 sound | 4 | 0 | 0 | 0.074s |
| 🟢 system | 6 | 0 | 2 | 0.144s |
| 🟢 thread | 5 | 0 | 0 | 0.377s |
| 🟢 timer | 6 | 0 | 0 | 2.093s |
| 🟢 event | 4 | 0 | 2 | 0.104s |
| 🟢 filesystem | 29 | 0 | 2 | 0.546s |
| 🟢 font | 7 | 0 | 0 | 0.117s |
| 🟢 graphics | 104 | 0 | 1 | 2.948s |
| 🟢 image | 5 | 0 | 0 | 0.085s |
| 🟢 joystick | 6 | 0 | 0 | 0.106s |
| 🟢 keyboard | 9 | 0 | 0 | 0.151s |
| 🟢 love | 10 | 0 | 0 | 0.166s |
| 🟢 math | 20 | 0 | 0 | 0.339s |
| 🟢 mouse | 18 | 0 | 0 | 0.303s |
| 🟢 physics | 26 | 0 | 0 | 0.439s |
| 🟢 sensor | 1 | 0 | 0 | 0.016s |
| 🟢 sound | 4 | 0 | 0 | 0.073s |
| 🟢 system | 6 | 0 | 2 | 0.137s |
| 🟢 thread | 5 | 0 | 0 | 0.363s |
| 🟢 timer | 6 | 0 | 0 | 2.076s |
| 🟢 touch | 3 | 0 | 0 | 0.007s |
| 🟢 video | 2 | 0 | 0 | 0.040s |
| 🟢 window | 34 | 0 | 2 | 5.986s |
| 🟢 window | 34 | 0 | 2 | 5.355s |
### Failures
File diff suppressed because it is too large Load Diff
+21 -21
View File
@@ -1,6 +1,3 @@
-- & 'c:\Program Files\LOVE\love.exe' ./ --console
-- /Applications/love_12.app/Contents/MacOS/love ./testing
-- load test objs
require('classes.TestSuite')
require('classes.TestModule')
@@ -10,6 +7,8 @@ require('classes.TestMethod')
love.test = TestSuite:new()
-- load test scripts if module is active
-- this is so in future if we have per-module disabling it'll still run
if love ~= nil then require('tests.love') end
if love.audio ~= nil then require('tests.audio') end
if love.data ~= nil then require('tests.data') end
if love.event ~= nil then require('tests.event') end
@@ -17,12 +16,17 @@ if love.filesystem ~= nil then require('tests.filesystem') end
if love.font ~= nil then require('tests.font') end
if love.graphics ~= nil then require('tests.graphics') end
if love.image ~= nil then require('tests.image') end
if love.joystick ~= nil then require('tests.joystick') end
if love.keyboard ~= nil then require('tests.keyboard') end
if love.math ~= nil then require('tests.math') end
if love.mouse ~= nil then require('tests.mouse') end
if love.physics ~= nil then require('tests.physics') end
if love.sensor ~= nil then require('tests.sensor') end
if love.sound ~= nil then require('tests.sound') end
if love.system ~= nil then require('tests.system') end
if love.thread ~= nil then require('tests.thread') end
if love.timer ~= nil then require('tests.timer') end
if love.touch ~= nil then require('tests.touch') end
if love.video ~= nil then require('tests.video') end
if love.window ~= nil then require('tests.window') end
@@ -47,9 +51,8 @@ love.load = function(args)
}
Logo.img = love.graphics.newQuad(0, 0, 64, 64, Logo.texture)
Font = love.graphics.newFont('resources/font.ttf', 8, 'normal')
local txtobj = love.graphics.newTextBatch or love.graphics.newText
TextCommand = txtobj(Font, 'Loading...')
TextRun = txtobj(Font, '')
TextCommand = 'Loading...'
TextRun = ''
end
end
@@ -73,14 +76,14 @@ love.load = function(args)
local method = ''
local cmderr = 'Invalid flag used'
local modules = {
'audio', 'data', 'event', 'filesystem', 'font', 'graphics',
'image', 'math', 'physics', 'sound', 'system',
'thread', 'timer', 'video', 'window'
'audio', 'data', 'event', 'filesystem', 'font', 'graphics', 'image',
'joystick', 'keyboard', 'love', 'math', 'mouse', 'physics', 'sensor',
'sound', 'system', 'thread', 'timer', 'touch', 'video', 'window'
}
GITHUB_RUNNER = false
for a=1,#arglist do
if testcmd == '--runSpecificMethod' then
if module == '' and love[ arglist[a] ] ~= nil then
if module == '' and (arglist[a] == 'love' or love[ arglist[a] ] ~= nil) then
module = arglist[a]
table.insert(modules, module)
elseif module ~= '' and love[module] ~= nil and method == '' then
@@ -88,7 +91,7 @@ love.load = function(args)
end
end
if testcmd == '--runSpecificModules' then
if love[ arglist[a] ] ~= nil and arglist[a] ~= '--isRunner' then
if (arglist[a] == 'love' or love[ arglist[a] ] ~= nil) and arglist[a] ~= '--isRunner' then
table.insert(modules, arglist[a])
end
end
@@ -157,7 +160,7 @@ love.load = function(args)
love.event.quit(0)
else
-- start first module
TextCommand:set(testcmd)
TextCommand = testcmd
love.test.module:runTests()
end
@@ -173,18 +176,19 @@ end
-- love.draw
-- draw a little logo to the screen
love.draw = function()
local lw = (love.graphics.getPixelWidth() - 128) / 2
local lh = (love.graphics.getPixelHeight() - 128) / 2
local lw = (love.graphics.getWidth() - 128) / 2
local lh = (love.graphics.getHeight() - 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)
love.graphics.setFont(Font)
love.graphics.print(TextCommand, 4, 12, 0, 2, 2)
love.graphics.print(TextRun, 4, 32, 0, 2, 2)
end
-- love.quit
-- add a hook to allow test modules to fake quit
love.quit = function()
if love.test.module ~= nil and love.test.module.fakequit == true then
if love.test.module ~= nil and love.test.module.fakequit then
return true
else
return false
@@ -210,7 +214,3 @@ end
function UtilTimeFormat(seconds)
return string.format("%.3f", tostring(seconds))
end
function UtilDebugLog(a, b, c)
if GITHUB_RUNNER == true then print("DEBUG ==> ", a, b, c) end
end
+15 -19
View File
@@ -23,26 +23,22 @@ While the test suite is part of the main Löve repo, the test suite has it's own
## Coverage
This is the status of all module tests.
See the **Todo** section for outstanding tasks if you want to contribute!
| Module | Done | Todo | Skip |
| ----------------- | ---- | ---- | ---- |
| 🟢 audio | 28 | 0 | 0 |
| 🟢 data | 12 | 0 | 0 |
| 🟢 event | 4 | 0 | 2 |
| 🟢 filesystem | 29 | 0 | 2 |
| 🟢 font | 7 | 0 | 0 |
| 🟢 graphics | 104 | 0 | 1 |
| 🟢 image | 5 | 0 | 0 |
| 🟢 math | 20 | 0 | 0 |
| 🟢 physics | 26 | 0 | 0 |
| 🟢 sound | 4 | 0 | 0 |
| 🟢 system | 6 | 0 | 2 |
| 🟢 thread | 5 | 0 | 0 |
| 🟢 timer | 6 | 0 | 0 |
| 🟢 video | 2 | 0 | 0 |
| 🟢 window | 34 | 0 | 2 |
| Module | Done | Skip | Modules | Done | Skip |
| ----------------- | ---- | ---- | ---------------- | ---- | ---- |
| 🟢 audio | 28 | 0 | 🟢 mouse | 18 | 0 |
| 🟢 data | 12 | 0 | 🟢 physics | 26 | 0 |
| 🟢 event | 4 | 2 | 🟢 sensor | 1 | 0 |
| 🟢 filesystem | 29 | 2 | 🟢 sound | 4 | 0 |
| 🟢 font | 7 | 0 | 🟢 system | 6 | 2 |
| 🟢 graphics | 104 | 1 | 🟢 thread | 5 | 0 |
| 🟢 image | 5 | 0 | 🟢 timer | 6 | 0 |
| 🟢 joystick | 6 | 0 | 🟢 touch | 3 | 0 |
| 🟢 keyboard | 9 | 0 | 🟢 video | 2 | 0 |
| 🟢 love | 10 | 0 | 🟢 window | 34 | 2 |
| 🟢 math | 20 | 0 |
> The following modules are not covered as we can't really emulate input nicely:
> `joystick`, `keyboard`, `mouse`, and `touch`
> The following modules are covered but at a basic level as we can't emulate hardware input nicely for all platforms + virtual runners:
> `joystick`, `keyboard`, `mouse`, `sensor` and `touch`
---
File diff suppressed because it is too large Load Diff
+7 -1
View File
@@ -188,6 +188,10 @@ love.test.audio.Source = function(test)
local filtersettings = effsource:getEffect('effectthatdoesntexist', {})
test:assertNotNil(filtersettings)
love.audio.stop(stereo)
love.audio.stop(mono)
love.audio.stop(effsource)
end
@@ -218,6 +222,7 @@ love.test.audio.getActiveSourceCount = function(test)
test:assertNotNil(love.audio.getActiveSourceCount())
-- check source isn't active by default
local testsource = love.audio.newSource('resources/click.ogg', 'static')
love.audio.stop(testsource)
test:assertEquals(0, love.audio.getActiveSourceCount(), 'check not active')
-- check playing a source marks it as active
love.audio.play(testsource)
@@ -363,6 +368,7 @@ love.test.audio.pause = function(test)
love.audio.play(source)
local onepause = love.audio.pause()
test:assertEquals(1, #onepause, 'check 1 paused')
love.audio.stop(source)
end
@@ -372,7 +378,7 @@ love.test.audio.play = function(test)
local source = love.audio.newSource('resources/click.ogg', 'static')
love.audio.play(source)
test:assertTrue(source:isPlaying(), 'check something playing')
love.audio.pause()
love.audio.stop()
end
+81
View File
@@ -0,0 +1,81 @@
-- love.joystick
-- @NOTE we can't test this module fully as it's hardware dependent
-- however we can test methods do what is expected and can handle certain params
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- love.joystick.getGamepadMappingString
love.test.joystick.getGamepadMappingString = function(test)
local mapping = love.joystick.getGamepadMappingString('faker')
test:assertEquals(nil, mapping, 'check no mapping for fake gui')
end
-- love.joystick.getJoystickCount
love.test.joystick.getJoystickCount = function(test)
local count = love.joystick.getJoystickCount()
test:assertEquals(0, count, 'check no joysticks')
end
-- love.joystick.getJoysticks
love.test.joystick.getJoysticks = function(test)
local joysticks = love.joystick.getJoysticks()
test:assertEquals(0, #joysticks, 'check no joysticks')
end
-- love.joystick.loadGamepadMappings
love.test.joystick.loadGamepadMappings = function(test)
local ok, err = pcall(love.joystick.loadGamepadMappings, 'fakefile.txt')
test:assertEquals(false, ok, 'check invalid file')
love.joystick.loadGamepadMappings('resources/mappings.txt')
end
-- love.joystick.saveGamepadMappings
love.test.joystick.saveGamepadMappings = function(test)
love.joystick.loadGamepadMappings('resources/mappings.txt')
local mapping = love.joystick.saveGamepadMappings()
test:assertGreaterEqual(0, #mapping, 'check something mapped')
end
-- love.joystick.setGamepadMapping
love.test.joystick.setGamepadMapping = function(test)
local guid = '030000005e040000130b000011050000'
local mappings = {
love.joystick.setGamepadMapping(guid, 'a', 'button', 1, nil),
love.joystick.setGamepadMapping(guid, 'b', 'button', 2, nil),
love.joystick.setGamepadMapping(guid, 'x', 'button', 3, nil),
love.joystick.setGamepadMapping(guid, 'y', 'button', 4, nil),
love.joystick.setGamepadMapping(guid, 'back', 'button', 5, nil),
love.joystick.setGamepadMapping(guid, 'start', 'button', 6, nil),
love.joystick.setGamepadMapping(guid, 'guide', 'button', 7, nil),
love.joystick.setGamepadMapping(guid, 'leftstick', 'button', 8, nil),
love.joystick.setGamepadMapping(guid, 'leftshoulder', 'button', 9, nil),
love.joystick.setGamepadMapping(guid, 'rightstick', 'button', 10, nil),
love.joystick.setGamepadMapping(guid, 'rightshoulder', 'button', 11, nil),
love.joystick.setGamepadMapping(guid, 'dpup', 'button', 12, nil),
love.joystick.setGamepadMapping(guid, 'dpdown', 'button', 13, nil),
love.joystick.setGamepadMapping(guid, 'dpleft', 'button', 14, nil),
love.joystick.setGamepadMapping(guid, 'dpright', 'button', 15, nil),
love.joystick.setGamepadMapping(guid, 'dpup', 'button', 12, 'u'),
love.joystick.setGamepadMapping(guid, 'dpdown', 'button', 13, 'd'),
love.joystick.setGamepadMapping(guid, 'dpleft', 'button', 14, 'l'),
love.joystick.setGamepadMapping(guid, 'dpright', 'button', 15, 'r'),
love.joystick.setGamepadMapping(guid, 'dpup', 'hat', 12, 'lu'),
love.joystick.setGamepadMapping(guid, 'dpdown', 'hat', 13, 'ld'),
love.joystick.setGamepadMapping(guid, 'dpleft', 'hat', 14, 'ru'),
love.joystick.setGamepadMapping(guid, 'dpright', 'hat', 15, 'rd'),
love.joystick.setGamepadMapping(guid, 'leftstick', 'axis', 8, 'c')
}
for m=1,#mappings do
test:assertEquals(true, mappings[m], 'check mapping #' .. tostring(m))
end
end
+73
View File
@@ -0,0 +1,73 @@
-- love.keyboard
-- @NOTE we can't test this module fully as it's hardware dependent
-- however we can test methods do what is expected and can handle certain params
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- love.keyboard.getKeyFromScancode
love.test.keyboard.getKeyFromScancode = function(test)
local key = love.keyboard.getKeyFromScancode('a')
test:assertEquals('a', key, 'check key')
end
-- love.keyboard.getScancodeFromKey
love.test.keyboard.getScancodeFromKey = function(test)
local scancode = love.keyboard.getScancodeFromKey('a')
test:assertEquals('a', scancode, 'check scancode')
end
-- love.keyboard.hasKeyRepeat
love.test.keyboard.hasKeyRepeat = function(test)
local enabled = love.keyboard.hasKeyRepeat()
test:assertNotNil(enabled)
end
-- love.keyboard.hasScreenKeyboard
love.test.keyboard.hasScreenKeyboard = function(test)
local enabled = love.keyboard.hasScreenKeyboard()
test:assertNotNil(enabled)
end
-- love.keyboard.hasTextInput
love.test.keyboard.hasTextInput = function(test)
local enabled = love.keyboard.hasTextInput()
test:assertNotNil(enabled)
end
-- love.keyboard.isDown
love.test.keyboard.isDown = function(test)
local keydown = love.keyboard.isDown('a')
test:assertNotNil(keydown)
end
-- love.keyboard.isScancodeDown
love.test.keyboard.isScancodeDown = function(test)
local keydown = love.keyboard.isScancodeDown('a')
test:assertNotNil(keydown)
end
-- love.keyboard.setKeyRepeat
love.test.keyboard.setKeyRepeat = function(test)
love.keyboard.setKeyRepeat(true)
local enabled = love.keyboard.hasKeyRepeat()
test:assertEquals(true, enabled, 'check key repeat set')
end
-- love.keyboard.setTextInput
love.test.keyboard.setTextInput = function(test)
love.keyboard.setTextInput(false)
test:assertEquals(false, love.keyboard.hasTextInput(), 'check disable text input')
end
+78
View File
@@ -0,0 +1,78 @@
-- love
-- tests for the main love hooks + methods, mainly just that they exist
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- love.getVersion
love.test.love.getVersion = function(test)
local major, minor, revision, codename = love.getVersion()
test:assertGreaterEqual(0, major, 'check major is number')
test:assertGreaterEqual(0, minor, 'check minor is number')
test:assertGreaterEqual(0, revision, 'check revision is number')
test:assertTrue(codename ~= nil, 'check has codename')
end
-- love.hasDeprecationOutput
love.test.love.hasDeprecationOutput = function(test)
local enabled = love.hasDeprecationOutput()
test:assertEquals(true, enabled, 'check enabled by default')
end
-- love.isVersionCompatible
love.test.love.isVersionCompatible = function(test)
local major, minor, revision, _ = love.getVersion()
test:assertTrue(love.isVersionCompatible(major, minor, revision), 'check own version')
end
-- love.setDeprecationOutput
love.test.love.setDeprecationOutput = function(test)
local enabled = love.hasDeprecationOutput()
test:assertEquals(true, enabled, 'check enabled by default')
love.setDeprecationOutput(false)
test:assertEquals(false, love.hasDeprecationOutput(), 'check disable')
love.setDeprecationOutput(true)
end
-- love.errhand
love.test.love.errhand = function(test)
test:assertTrue(type(love.errhand) == 'function', 'check defined')
end
-- love.load
love.test.love.load = function(test)
test:assertTrue(type(love.load) == 'function', 'check defined')
end
-- love.draw
love.test.love.draw = function(test)
test:assertTrue(type(love.draw) == 'function', 'check defined')
end
-- love.update
love.test.love.update = function(test)
test:assertTrue(type(love.update) == 'function', 'check defined')
end
-- love.run
love.test.love.run = function(test)
test:assertTrue(type(love.run) == 'function', 'check defined')
end
-- love.quit
love.test.love.quit = function(test)
test:assertTrue(type(love.quit) == 'function', 'check defined')
end
+173
View File
@@ -0,0 +1,173 @@
-- love.mouse
-- @NOTE we can't test this module fully as it's hardware dependent
-- however we can test methods do what is expected and can handle certain params
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- love.mouse.getCursor
love.test.mouse.getCursor = function(test)
local cursor = love.mouse.getCursor()
test:assertEquals(nil, cursor, 'check nil initially')
love.mouse.setCursor(love.mouse.getSystemCursor("hand"))
local newcursor = love.mouse.getCursor()
test:assertObject(newcursor)
love.mouse.setCursor()
end
-- love.mouse.getPosition
love.test.mouse.getPosition = function(test)
love.mouse.setPosition(0, 0) -- cant predict
local x, y = love.mouse.getPosition()
test:assertEquals(0, x, 'check x pos')
test:assertEquals(0, y, 'check y pos')
end
-- love.mouse.getRelativeMode
love.test.mouse.getRelativeMode = function(test)
local enabled = love.mouse.getRelativeMode()
test:assertEquals(false, enabled, 'check relative mode')
love.mouse.setRelativeMode(true)
test:assertEquals(true, love.mouse.getRelativeMode(), 'check enabling')
end
-- love.mouse.getSystemCursor
love.test.mouse.getSystemCursor = function(test)
local hand = love.mouse.getSystemCursor('hand')
test:assertObject(hand)
local ok, err = pcall(love.mouse.getSystemCursor, 'love')
test:assertEquals(false, ok, 'check invalid cursor')
end
-- love.mouse.getX
love.test.mouse.getX = function(test)
love.mouse.setPosition(0, 0) -- cant predict
local x = love.mouse.getX()
test:assertEquals(0, x, 'check x pos')
love.mouse.setX(10)
test:assertEquals(10, love.mouse.getX(), 'check set x')
end
-- love.mouse.getY
love.test.mouse.getY = function(test)
love.mouse.setPosition(0, 0) -- cant predict
local y = love.mouse.getY()
test:assertEquals(0, y, 'check x pos')
love.mouse.setY(10)
test:assertEquals(10, love.mouse.getY(), 'check set y')
end
-- love.mouse.isCursorSupported
love.test.mouse.isCursorSupported = function(test)
test:assertNotNil(love.mouse.isCursorSupported())
end
-- love.mouse.isDown
love.test.mouse.isDown = function(test)
test:assertNotNil(love.mouse.isDown())
end
-- love.mouse.isGrabbed
love.test.mouse.isGrabbed = function(test)
test:assertNotNil(love.mouse.isGrabbed())
end
-- love.mouse.isVisible
love.test.mouse.isVisible = function(test)
local visible = love.mouse.isVisible()
test:assertEquals(true, visible, 'check visible default')
love.mouse.setVisible(false)
test:assertEquals(false, love.mouse.isVisible(), 'check invisible')
love.mouse.setVisible(true)
end
-- love.mouse.newCursor
love.test.mouse.newCursor = function(test)
local cursor = love.mouse.newCursor('resources/love.png', 0, 0)
test:assertObject(cursor)
end
-- love.mouse.setCursor
love.test.mouse.setCursor = function(test)
love.mouse.setCursor()
test:assertEquals(nil, love.mouse.getCursor(), 'check reset')
love.mouse.setCursor(love.mouse.getSystemCursor('hand'))
test:assertObject(love.mouse.getCursor())
end
-- love.mouse.setGrabbed
love.test.mouse.setGrabbed = function(test)
test:assertEquals(false, love.mouse.isGrabbed(), 'check not grabbed')
love.mouse.setGrabbed(true)
test:assertEquals(true, love.mouse.isGrabbed(), 'check now grabbed')
love.mouse.setGrabbed(false)
end
-- love.mouse.setPosition
love.test.mouse.setPosition = function(test)
love.mouse.setPosition(10, 10)
local x, y = love.mouse.getPosition()
test:assertEquals(10, x, 'check x position')
test:assertEquals(10, y, 'check y position')
love.mouse.setPosition(15, 20)
local x2, y2 = love.mouse.getPosition()
test:assertEquals(15, x2, 'check new x position')
test:assertEquals(20, y2, 'check new y position')
end
-- love.mouse.setRelativeMode
love.test.mouse.setRelativeMode = function(test)
love.mouse.setRelativeMode(true)
local enabled = love.mouse.getRelativeMode()
test:assertEquals(true, enabled, 'check relative mode')
love.mouse.setRelativeMode(false)
test:assertEquals(false, love.mouse.getRelativeMode(), 'check disabling')
end
-- love.mouse.setVisible
love.test.mouse.setVisible = function(test)
local visible = love.mouse.isVisible()
test:assertEquals(true, visible, 'check visible default')
love.mouse.setVisible(false)
test:assertEquals(false, love.mouse.isVisible(), 'check invisible')
love.mouse.setVisible(true)
end
-- love.mouse.setX
love.test.mouse.setX = function(test)
love.mouse.setX(30)
local x = love.mouse.getX()
test:assertEquals(30, x, 'check x pos')
love.mouse.setX(10)
test:assertEquals(10, love.mouse.getX(), 'check set x')
end
-- love.mouse.setY
love.test.mouse.setY = function(test)
love.mouse.setY(12)
local y = love.mouse.getY()
test:assertEquals(12, y, 'check x pos')
love.mouse.setY(10)
test:assertEquals(10, love.mouse.getY(), 'check set y')
end
+2 -2
View File
@@ -307,10 +307,10 @@ love.test.physics.Joint = function(test)
test:assertFalse(joint:isDestroyed(), 'check not destroyed')
-- check reaction props (sometimes nil on linux runners)
if joint:getReactionForce(1) ~= nil then
if joint:getReactionForce(1) ~= nil and joint:getReactionForce(1) ~= 0/0 then
test:assertEquals(0, joint:getReactionForce(1), 'check reaction force')
end
if joint:getReactionTorque(1) ~= nil then
if joint:getReactionTorque(1) ~= nil and joint:getReactionTorque(1) ~= 0/0 then
test:assertEquals(0, joint:getReactionTorque(1), 'check reaction torque')
end
+19
View File
@@ -0,0 +1,19 @@
-- love.sensor
-- @NOTE we can't test this module fully as it's hardware dependent
-- however we can test methods do what is expected and can handle certain params
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- love.sensor.hasSensor
love.test.sensor.hasSensor = function(test)
-- but we can make sure that the SensorTypes can be passed
local accelerometer = love.sensor.hasSensor('accelerometer')
local gyroscope = love.sensor.hasSensor('gyroscope')
test:assertNotNil(accelerometer)
test:assertNotNil(gyroscope)
end
+33
View File
@@ -0,0 +1,33 @@
-- love.touch
-- @NOTE we can't test this module fully as it's hardware dependent
-- however we can test methods do what is expected and can handle certain params
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
------------------------------------METHODS-------------------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- love.touch.getPosition
-- @TODO is there a way to fake the touchid pointer?
love.test.touch.getPosition = function(test)
test:assertNotNil(love.touch.getPosition)
test:assertEquals('function', type(love.touch.getPosition))
end
-- love.touch.getPressure
-- @TODO is there a way to fake the touchid pointer?
love.test.touch.getPressure = function(test)
test:assertNotNil(love.touch.getPressure)
test:assertEquals('function', type(love.touch.getPressure))
end
-- love.touch.getTouches
love.test.touch.getTouches = function(test)
local touches = love.touch.getTouches()
test:assertNotNil(touches)
test:assertEquals(0, #touches, 'check no touches')
end
+17 -19
View File
@@ -8,17 +8,6 @@
--------------------------------------------------------------------------------
-- love.window.close
love.test.window.close = function(test)
-- closing window should cause graphics to not be active
love.window.close()
local active = love.graphics.isActive()
test:assertFalse(active, 'check window not active')
love.window.updateMode(360, 240) -- reset
active = love.graphics.isActive()
test:assertTrue(active, 'check window active again')
end
-- love.window.fromPixels
love.test.window.fromPixels = function(test)
-- check dpi/pixel ratio as expected
@@ -194,10 +183,7 @@ end
love.test.window.isOpen = function(test)
-- check open initially
test:assertTrue(love.window.isOpen(), 'check window open')
-- try closing
love.window.close()
test:assertFalse(love.window.isOpen(), 'check window closed')
love.window.updateMode(360, 240) -- reset
-- we check closing in test.window.close
end
@@ -205,10 +191,7 @@ end
love.test.window.isVisible = function(test)
-- check visible initially
test:assertTrue(love.window.isVisible(), 'check window visible')
-- check closing makes window not visible
love.window.close()
test:assertFalse(love.window.isVisible(), 'check window not visible')
love.window.updateMode(360, 240) -- reset
-- we check closing in test.window.close
end
@@ -369,3 +352,18 @@ love.test.window.updateMode = function(test)
resizable = true
})
end
-- love.window.close
-- calling love.window.close() last as it will stop the main test image drawing
love.test.window.z_close = function(test)
-- closing window should cause graphics to not be active
love.window.close()
local active = love.graphics.isActive()
test:assertFalse(active, 'check window not active')
-- should also mark the window as not open and not visible
test:assertFalse(love.window.isOpen(), 'check window closed')
test:assertFalse(love.window.isVisible(), 'check window not visible')
love.window.updateMode(360, 240) -- reset
active = love.graphics.isActive()
test:assertTrue(active, 'check window active again')
end