-
-
Notifications
You must be signed in to change notification settings - Fork 9
Developers
Brandon Sturgeon edited this page Jun 9, 2022
·
11 revisions
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 )
### `GLuaTest_MakeColors`
This hook is called when the `colors` table is created for the result logger.
#### Parameters
- **`colors`**: A table with color names as the keys, and `Color` objects as the value
#### Example
For this extension, we'll slightly tweak the default `red` color
```lua
hook.Add( "GLuaTest_MakeColors", "Change_RedColor", function( colors )
colors.red = Color( 225, 75, 75 )
end )