-
-
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