Skip to content

Automatically enable exclude_addons option when running tests #600

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

Merged
merged 1 commit into from
May 10, 2024
Merged

Automatically enable exclude_addons option when running tests #600

merged 1 commit into from
May 10, 2024

Conversation

mphe
Copy link
Contributor

@mphe mphe commented May 9, 2024

GUT will throw errors if exclude_addons option is disabled, e.g. due to overriding native methods.
When working on addons it is usually desired to disable exclude_addons in order to get proper code diagnostics.
This however makes it tedious to run GUT because the option has to be manually disabled before running tests and manually enabled again afterwards to get diagnostics.
To workaround this issue, this commit automatically enables the exclude_addons option when running tests, so regardless of the project settings in the editor, GUT will always run as intended.

Copy link
Owner

@bitwes bitwes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great idea. I double checked, and this cannot be done in a pre-hook script. This must be done before an instance of addons/gut/utils.gd is created, since it loads all the scripts that have issues.

I think a better place for this (I tested a bunch of different spots) is a new _init() method in addons/gut/gut_config.gd. Although I cannot think of a scenario where you would not want to enable this, since it is on by default and it is suggested that you enable it if it is not, there still might be a reason. If that ever arises, having it in gut_config.gd will make more sense when an option is added.

@mphe
Copy link
Contributor Author

mphe commented May 9, 2024

Isn't gut_config also instantiated in the editor? In that case it should not change exclude_addons because it would interfer with the user's project config.
The intent was to only change it at runtime.

But I sure can add a setting to enable or disable it if needed.

@bitwes
Copy link
Owner

bitwes commented May 9, 2024

Good catch. I just tested it, and it will turn it back on when you open the project. I added a check for is_editor_hint and it does not turn it back on then.

func _init():
	if(!Engine.is_editor_hint()):
		ProjectSettings.set("debug/gdscript/warnings/exclude_addons", true)

I don't think an option is needed yet. I'm not entirely sure where it would be applied, mostly because "Native Method Override" is an error by default (which I have no issue with) . I don't know if there is a point in execution where we have loaded a config file and utils.gd has NOT been referenced (which loads the problem scripts). We may only be able to turn "exclude addons" off at a later time, instead of having it always off based on the option.

I tried lazy loading the problem scripts but that didn't stop the errors when opening the project. I'm not sure if this would help in finding a spot to apply an option for auto-exclude-addons.

var _Doubler = null
var Doubler = null :
	get:
		if(_Doubler == null):
			_Doubler = load('res://addons/gut/doubler.gd')
		return _Doubler

GUT will throw errors if this option is disabled, e.g. due to overriding
native methods.
When working on addons it is usually desired to disable exclude_addons
in order to get proper code diagnostics.
This however makes it tedious to run GUT because the option has to be
manually disabled before running tests and manually enabled again
afterwards to get diagnostics.
To workaround this issue, this commit automatically enables the
exclude_addons option when running tests, so regardless of the project
settings in the editor, GUT will always run as intended.
@mphe
Copy link
Contributor Author

mphe commented May 10, 2024

Moved the code into _init() in gut_config.gd.

Copy link
Owner

@bitwes bitwes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@bitwes bitwes merged commit 0a010d4 into bitwes:main May 10, 2024
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

Successfully merging this pull request may close these issues.

2 participants