Module ammtest
¶
AMM test library.
Index¶
Function
Assert that the geven value is a boolean. |
|
Assert that two floats are equal, within the given tolerance. |
|
Assert that two values are deep-equal. |
|
Assert that g == e. |
|
Assert that the given function throws an error when called, and that the error message matches the given pattern. |
|
Assert that the given value is false. |
|
Assert that g > e. |
|
Assert that g >= e. |
|
Assert that two arrays contain the same number of elements. |
|
Assert that g < e. |
|
Assert that g <= e. |
|
Assert that the given string matches a pattern. |
|
Assert that the geven value is a nil. |
|
Assert that the geven value is not a boolean. |
|
Assert that two floats are not equal, within the given tolerance. |
|
Assert that two values are not deep-equal. |
|
Assert that g ~= e. |
|
Assert that two arrays contain different number of elements. |
|
Assert that the given string does not match a pattern. |
|
Assert that the geven value is not a nil. |
|
Assert that the geven value is not a number. |
|
Assert that the geven value is not a string. |
|
Assert that the geven value is not a table. |
|
Assert that the geven value is a number. |
|
Assert that the geven value is a string. |
|
Assert that the geven value is a table. |
|
Assert that the given value is true. |
|
Mark test as failed and immediately stop it. |
|
Get log lines that were printed during the test. |
|
Get log lines that were printed during the test, concatenated into a single string. |
|
Check if we're currently in test mode. |
|
Search and load all tests in all dev packages. |
|
Main function that will collect and run all the tests. |
|
Test parameter, used with ammtest.Suite.caseParams. |
|
Temporarily replace value of a variable. |
|
Pretty print a table/variable. |
|
Pretty print function arguments. |
|
Run all collected tests and return a result. |
|
Mark test as skipped and immediately stop it. |
|
Create a new test suite. |
Class
Results of a single test case. |
|
Container for test parameters and additional debug values. Used with ammtest.Suite.caseParams. |
|
Results of a single test suite. |
|
Base class for test suites. |
Alias
Result of a test run. |
Function¶
-
ammtest.assertBoolean(g:
any
, msg?:string
)¶ Assert that the geven value is a boolean.
-
ammtest.assertClose(g:
number
, e:number
, tol?:number
, msg?:string
)¶ Assert that two floats are equal, within the given tolerance.
-
ammtest.assertDeepEq(g: <
T
>, e: <T
>, msg?:string
)¶ Assert that two values are deep-equal.
That is, if two values are tables, they should contain the same set of keys, and their values should themselves be deep-equal; if two values are not tables, they should be equal when compared by the
==
operator.
-
ammtest.assertEq(g: <
T
>, e: <T
>, msg?:string
)¶ Assert that
g == e
.
-
ammtest.assertError(fn: fun(...
any
): ...unknown
, args:any
[], pat:string
, msg?:string
)¶ Assert that the given function throws an error when called, and that the error message
matches
the given pattern.If the given function doesn’t throw an error, and returns a value instead, the value will be displayed in a test failure message.
Example:
test.assertError( function (a, b) return a + b end, { nil, 1 }, "attempt to perform arithmetic on a nil value", )
-
ammtest.assertFalse(g:
any
, msg?:string
)¶ Assert that the given value is false.
-
ammtest.assertGt(g: <
T
>, e: <T
>, msg?:string
)¶ Assert that
g > e
.
-
ammtest.assertGte(g: <
T
>, e: <T
>, msg?:string
)¶ Assert that
g >= e
.
-
ammtest.assertLen(g:
any
[], e:integer
, msg?:string
)¶ Assert that two arrays contain the same number of elements.
-
ammtest.assertLt(g: <
T
>, e: <T
>, msg?:string
)¶ Assert that
g < e
.
-
ammtest.assertLte(g: <
T
>, e: <T
>, msg?:string
)¶ Assert that
g <= e
.
-
ammtest.assertMatch(g:
string
, pat:string
, msg?:string
)¶ Assert that the given string
matches
a pattern.
-
ammtest.assertNil(g:
any
, msg?:string
)¶ Assert that the geven value is a nil.
-
ammtest.assertNotBoolean(g:
any
, msg?:string
)¶ Assert that the geven value is not a boolean.
-
ammtest.assertNotClose(g:
number
, e:number
, tol?:number
, msg?:string
)¶ Assert that two floats are not equal, within the given tolerance.
-
ammtest.assertNotDeepEq(g: <
T
>, e: <T
>, msg?:string
)¶ Assert that two values are not deep-equal.
-
ammtest.assertNotEq(g: <
T
>, e: <T
>, msg?:string
)¶ Assert that
g ~= e
.
-
ammtest.assertNotLen(g:
any
[], e:integer
, msg?:string
)¶ Assert that two arrays contain different number of elements.
-
ammtest.assertNotMatch(g:
string
, pat:string
, msg?:string
)¶ Assert that the given string does not
match
a pattern.
-
ammtest.assertNotNil(g:
any
, msg?:string
)¶ Assert that the geven value is not a nil.
-
ammtest.assertNotNumber(g:
any
, msg?:string
)¶ Assert that the geven value is not a number.
-
ammtest.assertNotString(g:
any
, msg?:string
)¶ Assert that the geven value is not a string.
-
ammtest.assertNotTable(g:
any
, msg?:string
)¶ Assert that the geven value is not a table.
-
ammtest.assertNumber(g:
any
, msg?:string
)¶ Assert that the geven value is a number.
-
ammtest.assertString(g:
any
, msg?:string
)¶ Assert that the geven value is a string.
-
ammtest.assertTable(g:
any
, msg?:string
)¶ Assert that the geven value is a table.
-
ammtest.assertTrue(g:
any
, msg?:string
)¶ Assert that the given value is true.
-
ammtest.fail(msg?:
string
)¶ Mark test as failed and immediately stop it.
-
ammtest.getLog() {level:
integer
, msg:string
}[] ¶ Get log lines that were printed during the test.
This function only works in tests, no in setup/teardown functions.
-
ammtest.getLogStr()
string
¶ Get log lines that were printed during the test, concatenated into a single string.
This function only works in tests, no in setup/teardown functions.
-
ammtest.isInTest()
boolean
¶ Check if we’re currently in test mode.
-
ammtest.loadTests(name?:
string
)¶ Search and load all tests in all dev packages.
-
ammtest.main(name?:
string
)¶ Main function that will collect and run all the tests.
-
ammtest.param(...:
any
)ammtest.Param
¶ Test parameter, used with
ammtest.Suite:caseParams()
.
-
ammtest.patch(env?:
table
<string
,any
>, name:string
, value:any
)¶ Temporarily replace value of a variable.
Calling
ammtest.patch(a.b, "c", x)
is equivalent to executinga.b.c = x
, and then restoring the old value. To replace global variable, setenv
tonil
.Depending on where this function was called from, the effects are restored after test case, test teardown, or suite teardown.
- Parameters:
env? (
table
<string
,any
>) – table that contains the replaced value.name (
string
) – name of the replaced value.value (
any
) – new value.
-
ammtest.pprint(x:
any
, long:boolean
)string
¶ Pretty print a table/variable.
- Parameters:
x (
any
) – value to be pretty printed.long (
boolean
) – whether to shorten the value or not.
-
ammtest.pprintVa(params:
any
[], long:boolean
)string
¶ Pretty print function arguments.
- Parameters:
params (
any
[]) – array of function arguments.long (
boolean
) – whether to shorten the value or not.
-
ammtest.run()
ammtest.Result
[] ¶ Run all collected tests and return a result.
-
ammtest.skip(msg?:
string
)¶ Mark test as skipped and immediately stop it.
-
ammtest.suite(name?:
string
)ammtest.Suite
¶ Create a new test suite.
Class¶
-
class ammtest.CaseResult :
ammcore.class.Base
¶ Results of a single test case.
-
New(self: <T:
ammtest.CaseResult
>, name:string
, status?: "FAIL" | "OK" | "SKIP", msg?:string
, testLoc?:string
, loc?:string
) <T:ammtest.CaseResult
> ¶
-
const name:
string
¶ Name of the test case.
- const status: "FAIL" | "OK" | "SKIP"¶
Status of the test case.
-
const msg:
string
?¶ Message with which the test case failed.
-
const testLoc:
string
?¶ Location of the test function.
-
const loc:
string
?¶ Location of the error that failed the test.
-
New(self: <T:
-
class ammtest.Param :
ammcore.class.Base
¶ Container for test parameters and additional debug values. Used with
ammtest.Suite:caseParams()
.-
New(self: <T:
ammtest.Param
>, values:any
[], loc?:string
) <T:ammtest.Param
> ¶ Note
Use
ammtest.param()
to properly construct test parameters.
-
const values:
any
[]¶ Values that will be passed to the test function.
-
const loc:
string
¶ Location where this parameter was created.
-
New(self: <T:
-
class ammtest.Result :
ammcore.class.Base
¶ Results of a single test suite.
-
New(self: <T:
ammtest.Result
>, name:string
, status?: "FAIL" | "OK" | "SKIP", msg?:string
, loc?:string
) <T:ammtest.Result
> ¶
-
const name:
string
¶ Name of the test suite.
- const status: "FAIL" | "OK" | "SKIP"¶
Status of the test suite.
-
const msg:
string
?¶ Message with which the test suite failed.
-
const loc:
string
?¶ Location of the error that failed the suite. Only set if the failure occurred during suite setup/teardown.
-
const cases:
ammtest.CaseResult
[]¶ Array of test cases executed within this suite.
-
New(self: <T:
-
class ammtest.Suite :
ammcore.class.Base
¶ Base class for test suites.
-
New(self: <T:
ammtest.Suite
>, name?:string
) <T:ammtest.Suite
> ¶ Note
Use
ammtest.suite()
to properly construct test suites.- Parameters:
name? (
string
) – name of the test suite.
-
const name:
string
¶ Name of the suite, used for error messages.
-
virtual setupTest(self:
ammtest.Suite
)¶ Runs before every test.
-
virtual teardownTest(self:
ammtest.Suite
)¶ Runs after every test.
-
virtual setupSuite(self:
ammtest.Suite
)¶ Runs before every suite.
-
virtual teardownSuite(self:
ammtest.Suite
)¶ Runs after every suite.
-
case(self:
ammtest.Suite
, name:string
, fn: fun())¶ Add a test to the suite.
- Parameters:
name (
string
) – test name, used for error messages.fn (fun()) – test implementation.
-
caseParams(self:
ammtest.Suite
, name:string
, params:ammtest.Param
[], fn: fun(...any
))¶ Add a parametrized test to the suite.
Example:
local suite = test.suite("math") suite:caseParams( "multiply", { test.param(2, 2, 4), test.param(3, 3, 9), }, function (a, b, c) test.assertEq(a * b, c) end )
- Parameters:
name (
string
) – test name, used for error messages.params (
ammtest.Param
[]) – array of test parameters.fn (fun(...
any
)) – test implementation, must accept parameters as its arguments.
-
New(self: <T: