|
1 year ago | |
---|---|---|
.. | ||
classes | 1 year ago | |
examples | 1 year ago | |
output | 1 year ago | |
resources | 1 year ago | |
tests | 1 year ago | |
conf.lua | 1 year ago | |
main.lua | 1 year ago | |
readme.md | 1 year ago | |
todo.md | 1 year ago |
Basic testing suite for the löve APIs, based off of this issue
Currently written for löve 12
The initial pass is to keep things as simple as possible, and just run all the tests inside Löve to match how they'd be used by developers in-engine. To run the tests, download the repo and then run the main.lua as you would a löve game, i.e:
WINDOWS: & 'c:\Program Files\LOVE\love.exe' PATH_TO_TESTING_FOLDER --console
MACOS: /Applications/love.app/Contents/MacOS/love PATH_TO_TESTING_FOLDER
By default all tests will be run for all modules.
If you want to specify a module you can add:
--runSpecificModules filesystem
For multiple modules, provide a comma seperate list:
--runSpecificModules filesystem,audio,data"
If you want to specify only 1 specific method only you can use:
--runSpecificMethod filesystem write
All results will be printed in the console per method as PASS, FAIL, or SKIP with total assertions met on a module level and overall level.
An XML
file in the style of JUnit XML will be generated in the /output
directory, along with a HTML
and a Markdown
file with a summary of all tests (including visuals for love.graphics tests).
An example of both types of output can be found in the
/examples
folder
The Markdown file can be used with this github action if you want to output the report results to your CI.
Each method has it's own test method written in /tests
under the matching module name.
When you run the tests, a single TestSuite object is created which handles the progress + totals for all the tests.
Each module has a TestModule object created, and each test method has a TestMethod object created which keeps track of assertions for that method. You can currently do the following assertions:
Example test method:
-- love.filesystem.read test method
-- all methods should be put under love.test.MODULE.METHOD, matching the API
love.test.filesystem.read = function(test)
-- setup any data needed then run any asserts using the passed test object
local content, size = love.filesystem.read('resources/test.txt')
test:assertNotNil(content)
test:assertEquals('helloworld', content, 'check content match')
test:assertEquals(10, size, 'check size match')
content, size = love.filesystem.read('resources/test.txt', 5)
test:assertNotNil(content)
test:assertEquals('hello', content, 'check content match')
test:assertEquals(5, size, 'check size match')
-- no need to return anything or cleanup, GCC is called after each method
end
After each test method is ran, the assertions are totalled up, printed, and we move onto the next method! Once all methods in the suite are run a total pass/fail/skip is given for that module and we move onto the next module (if any)
For sanity-checking, if it's currently not covered or we're not sure how to test yet we can set the test to be skipped with test:skipTest(reason)
- this way we still see the method listed in the tests without it affected the pass/fail totals
This is the status of all module tests currently.
| Module | Passed | Failed | Skipped | Time |
| --------------------- | ------ | ------ | ------- | ------ |
| 🟢 love.audio | 26 | 0 | 0 | 2.602s |
| 🟢 love.data | 7 | 0 | 3 | 1.003s |
| 🟢 love.event | 4 | 0 | 2 | 0.599s |
| 🟢 love.filesystem | 27 | 0 | 2 | 2.900s |
| 🟢 love.font | 4 | 0 | 1 | 0.500s |
| 🟢 love.graphics | 81 | 0 | 15 | 10.678s |
| 🟢 love.image | 3 | 0 | 0 | 0.300s |
| 🟢 love.math | 17 | 0 | 0 | 1.678s |
| 🟢 love.physics | 22 | 0 | 0 | 2.197s |
| 🟢 love.sound | 2 | 0 | 0 | 0.200s |
| 🟢 love.system | 6 | 0 | 2 | 0.802s |
| 🟢 love.thread | 3 | 0 | 0 | 0.300s |
| 🟢 love.timer | 6 | 0 | 0 | 2.358s |
| 🟢 love.video | 1 | 0 | 0 | 0.100s |
| 🟢 love.window | 34 | 0 | 2 | 8.050s |
The following modules are not covered as we can't really emulate input nicely:
joystick
, keyboard
, mouse
, and touch
Modules with some small bits needed or needing sense checking:
There is some unused code in the Test.lua class to add preview vs actual images to the HTML output