Module test
Basic unit-testing framework
Functions
| describe (description, ...) | Define a group of tests |
| sdescribe (description, ...) | Define a group of tests that will be skipped. |
| it (description, f) | Define a single test to be used in describe |
| sit (description, f) | Define a single test that will be skipped. |
| fixture (name, scope, f) | Define a fixture to be used in tests |
| parametrize (names, parameters, f) | Run a single test with multiple parameters |
| run_tests () | Run all described tests and write results to stdout |
Assertion Functions
| assertEqual (v1, v2, msg) | Assert two values are equal |
| assertNotEqual (v1, v2, msg) | Assert two values not are equal |
| assertRequal (v1, v2, msg) | Assert two values are recursively equal |
| assertNotRequal (v1, v2, msg) | Assert two values are not recursively equal |
| assertLessThan (less, more, msg) | Assert a value is less than another value |
| assertMoreThan (more, less, msg) | Assert a value is more than another value |
| assertLessThanEqual (less, more, msg) | Assert a value is less than or equal to another value |
| assertMoreThanEqual (more, less, msg) | Assert a value is more than or equal to another value |
| assertRaises (exception, func, msg) | Assert a function raises an error mathing a pattern |
Functions
- describe (description, ...)
-
Define a group of tests
Parameters:
Usage:
describe('Example tests', it('makes an assertion', function() assert(true) end) ) run_tests()
- sdescribe (description, ...)
-
Define a group of tests that will be skipped.
Works exactly like describe, but skips all tests defined inside when run_tests is called.
Parameters:
See also:
- it (description, f)
-
Define a single test to be used in describe
Parameters:
- description string description of test
- f func a test function (function that makes assertions)
- sit (description, f)
-
Define a single test that will be skipped.
Works exactly like it, but will skip the test when run_tests is called.
Parameters:
- description string description of test
- f func a test function (function that makes assertions)
See also:
- fixture (name, scope, f)
-
Define a fixture to be used in tests
Parameters:
- name string name of the fixture
- scope string (optional) scope in which to create fixture ('func', 'group', 'module')
- f func function that creates the fixture (if the 'scope' argument is omitted then 'scope' is treated as 'f')
Usage:
fixture('myFixture', 'func', function() return 1 end) describe('Example tests', it('makes an assertion', function(myFixture) assert(myFixture == 1) end) )
- parametrize (names, parameters, f)
-
Run a single test with multiple parameters
Parameters:
- names string fixtures to parametrize (comma separated)
- parameters table of parameters - if more than one parameter is specified this must be a table of tables
- f func test function created with it
Usage:
describe('Example tests', parametrize('a,b,c', { {1, 2, 3}, {4, 5, 9} }, it('makes an assertion', function(a, b, c) assert(a + b == c) end)) )
- run_tests ()
- Run all described tests and write results to stdout
Assertion Functions
- assertEqual (v1, v2, msg)
-
Assert two values are equal
Parameters:
- v1
- v2
- msg
- assertNotEqual (v1, v2, msg)
-
Assert two values not are equal
Parameters:
- v1
- v2
- msg
- assertRequal (v1, v2, msg)
-
Assert two values are recursively equal
Parameters:
- v1
- v2
- msg
- assertNotRequal (v1, v2, msg)
-
Assert two values are not recursively equal
Parameters:
- v1
- v2
- msg
- assertLessThan (less, more, msg)
-
Assert a value is less than another value
Parameters:
- less
- more
- msg
- assertMoreThan (more, less, msg)
-
Assert a value is more than another value
Parameters:
- more
- less
- msg
- assertLessThanEqual (less, more, msg)
-
Assert a value is less than or equal to another value
Parameters:
- less
- more
- msg
- assertMoreThanEqual (more, less, msg)
-
Assert a value is more than or equal to another value
Parameters:
- more
- less
- msg
- assertRaises (exception, func, msg)
-
Assert a function raises an error mathing a pattern
Parameters:
- exception
- func
- msg