Luau has much stronger compile-time type checking than Lua. I’m updating the Expectations framework to allow tests to be compiled in –!strict mode. If you happen to be checking on the framework just now, I’d advise waiting a week. Here’s a quick peek at the new version:
--!strict
local __ = require('../inc/expectations')
__:describe('Sample Tests', function()
__:test('addition', function()
__:expect(2+1).is(4)
end)
__:test('comment inside expect', function()
__:expect(2+1, "not 4??").is(4)
end)
__:test('allowed difference', function()
__:test('pretty close', function()
local dividend = 1
local divisor = 3
local quotient = dividend / divisor
__:expect(quotient, 'this passes').is(0.33, 0.01)
__:expect(quotient, 'this fails').is(0.33)
end)
end)
__:test('comparisons', function()
__:expect(2*2).lt(5)
__:expect(2*2).le(4)
__:expect(2*2, 'went too far').lt(4)
end)
end)
__:execute()
The results from the above are:
Feature: Sample Tests
Actual: 3, Expected: 4. Test: 'addition'.
Actual: 3, Expected: 4. [not 4??] Test: 'comment inside expect'.
Actual: 0.3333333333333333, Expected: 0.33. [this fails] Test: 'pretty close'.
Actual: 4 should be less than 4 [went too far] Test: 'comparisons'.
Sample Tests, 7 Tests: Pass 3, Fail 4, Ignored 0.
You may wonder – I often do – about the ordering of items on the report lines. I’ve found it best to have the error info aligned to the left, as that is most important. That said, I’m considering some formatting changes and ideas are welcome.
An iportant objective of this framework is that it be small enough to be used in world as well as externally on one’s own computer, so it doesn’t have some of the fancy frills of the grown-up language tools. I’ve found that even in this simple form it is invaluable for ensuring that things work and keep working as I develop and refactor.
Anyway … watch this space.