Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use gut.p and asserts outside of GutTest #603

Open
m21-cerutti opened this issue May 12, 2024 · 1 comment
Open

Use gut.p and asserts outside of GutTest #603

m21-cerutti opened this issue May 12, 2024 · 1 comment

Comments

@m21-cerutti
Copy link

Versions

Godot 4.2.2 with GUT 9.2.1

The Feature

I was thinking of making my log and error system more robust in my game, and I was thinking it would be great that I would use it with GUT, like adding calls to gut.p and asserts to detect errors when loading a concrete scene with GUT for extent (doing e2e tests).
But it seems it can be called only inside a GutTest class (that conflict with my autoload inheritance).

How can I achieve that ?

@bitwes
Copy link
Owner

bitwes commented May 13, 2024

I've had this same thought, but the logger resides in addons/gut and when you export you game you shouldn't be including GUT or your tests in the export (not the final project at least). The logger also isn't documented or designed for general consumption, so it might be unwieldy to use. I can't move GUT's logger somewhere else since I don't want to make people install two addons.

Probably a bad idea, but sometimes bad ideas are fun

If you really really really want to try using it though...and this is kinda ugly, and not officially supported...you could:

  • Create your own logger that has the same methods (with your own implementation) that addons/gut/logger.gd has (or at least all the ones you plan to use.
  • In an autoload:
    • Check to see if addons/gut exists, if it does set your global logger to Gut's instance (more on that later)
    • If addons/gut does not exist, set it to an instance of your own logger.
# your_autoload.gd

var lgr = null

# maybe this will have to go in _ready, or maybe it has to go in _init, timing might be weird
func _init():
  if(FileAccess.file_exists('res://addons/gut/logger.gd')):
    lgr = GutUtils.get_instance().get_logger()
  else:
    lgr = MyLoggerThatActsLikeGutLoggerButIsNot.new()

Maybe if this works, and you really like it, we can explore adding something more formal to GUT...but probably not.

Good Luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants