-
-
Notifications
You must be signed in to change notification settings - Fork 10
Developers
Are you interested in writing an extension for GLuaTest? That's great!
Please remember you can always reach out for help, even for simple questions.
GLuaTest exposes the following Hooks:
This hook is called when a new expect
object is created.
You can modify the given table in any way you'd like, and it'll be exposed inside of the tests cases.
-
subject
: The subject of the expectation. (The value passed intoexpect( )
in the test case) -
expect
: The createdexpect
table
Let's use the CreateExpect
hook to add a new expectation.
hook.Add( "GLuaTest_CreateExpect", "Add_GTE", function( subject, expect )
local to = expect.to
local expected = to.expected
function to.beGreaterThanOrEqualTo( comparison )
if subject < comparison then
expected( "to be greater than or equal to '%s'", comparison )
end
end
end )
This hook is called after the test files have been found, configured, and prepared. They will be run immediately after this hook.
-
testFiles
A sequential table of Test Files (description below)
A Test File looks like this:
Key | Type | Description |
---|---|---|
fileName |
string |
The test filename (not path) |
groupName |
string |
The groupName key set in the test file (can be nil ) |
cases |
table |
A sequential table of test cases (the contents of the cases key in the test file) |
project |
string |
The name of the directory under the tests/ directory that this test file is located |
In this example, we'll add a new feature that allows users to mark a test file as "skipped" and exclude it from being automatically run.
hook.Add( "GLuaTest_RunTestFiles", "Add_Skipped", function( testFiles )
for i = #testFiles, 1, -1, do
local testFile = testFiles[i]
if testFile.skip == true then
table.remove( testFiles, i )
end
end
end )
This hook is called when the colors
table is created for the result logger.
-
colors
: A table with color names as the keys, andColor
objects as the value
For this extension, we'll slightly tweak the default red
color
hook.Add( "GLuaTest_MakeColors", "Change_RedColor", function( colors )
colors.red = Color( 225, 75, 75 )
end )
This hook is called when an instance of LogHelpers
is created.
You can use this hook to stub, modify, or overwrite any of the methods in LogHelpers
.
You can see the available methods in the LogHelpers file.
-
LogHelpers
: A table of Log Helper methods
This hook is called when a new instance of ResultLogger
is created.
You can use this hook to stub, modify, or overwrite any of the methods in ResultLogger
.
You can see the available methods in the ResultLogger file.
-
ResultLogger
: A table of Result Logger methods
This hook runs when a test case finishes, and is about to be logged.
You can use this hook to modify anything about the result before it's logged.
-
result
: AResult
object (see below)
The Result
object
Key | Type | Description |
---|---|---|
success |
boolean /nil
|
A boolean indicating if the test case succeeded. If the test is empty, this field will be nil
|
testGroup |
table |
The TestGroup object for this test case |
case |
table |
The TestCase object |
errInfo |
table /nil
|
A table containing information about the failure. If success is true , this field will be nil
|
This hook runs when GLuaTest is about to run a test case. You can use this hook to modify the test case, or to prevent the test case from being run.
-
testGroup
: TheTestGroup
object -
case
: TheTestCase
object
-
false
to prevent the test case from running
This hook runs when a new Stub
object is created. This hook can be used to add or change a Stub
's functionality.
-
stubTbl
: TheStub
object -
meta
: The metatable that will be applied to thestubTbl
-
tbl
: A reference to the table that is being modified with this Stub (can benil
) -
key
: The key of thetbl
that is being modified with this Stub (can benil
)