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

Can't add stubs to hooks #35

Closed brandonsturgeon closed 1 year ago

brandonsturgeon commented 1 year ago
hook.Add( "Test", "Test", stub() )
assert( hook.GetTable().Test.Test ) -- Fails

I imagine this is because a stub isn't a function, and all major hook libraries are going to run it through isfunction.

This will probably be an issue elsewhere, too, where we need a stub to be a function but it fails type checks.

I see three options:

  1. Wrap isfunction and type and TypeID for the duration of each test?
  2. Change our hook env to wrap our stub in a holder function?
  3. Make all stubs functions and change the function metatable to make it function the same?

I prefer wrapping the major type functions, just to be thorough, but unfortunately the base hook library localizes the type functions...

So I guess we can do the first two? For now I think I'll make our hook env wrap the stub in a holder function, with the understanding that you still can't do:

expect( hook.GetTable().Event.ListenerID ).to.equal( myStub )
brandonsturgeon commented 1 year ago

After writing some hook-based tests, I've come to the conclusion that the best way to deal with this issue is to just add hooks, call hooks, and clean up any mess you made after the test completes.

(i'll still be pushing some changes that might address this issue indirectly, though)