CFC-Servers / GLuaTest

An exciting and nimble unit testing framework for GLua projects
https://discord.gg/epJK9Xx3pc
GNU General Public License v3.0
51 stars 2 forks source link

WIP cleanup/setup logic #7

Closed brandonsturgeon closed 2 years ago

brandonsturgeon commented 2 years ago

This will let each test case define its own setup/cleanup functions, and give entire test files the ability to run setup/cleanup before/after each or all of its test cases.

Test file could now look like: (The before/after and setup/cleanup funcs would be optional of course)

return {
    beforeAll = function() end,
    beforeEach = function( state ) state.ent = ents.Create( "blah" ) end,

    afterAll = function() end,
    afterEach = function( state ) if IsValid( state.ent ) then state.ent:Remove() end end,

    cases = {
        {
            name = "Example test",
            setup = function( state ) state.ent:SetMaterial( "pp/whatever" ) end,
            cleanup = function( state ) print( state.ent ) end,
            func = function( state )
                expect( state.ent:GetMaterial() ).to.equal( "pp/whatever" )
            end
        }
    }
}