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

GDScript: Load global classes when running debug tests #79425

Merged

Conversation

vnen
Copy link
Member

@vnen vnen commented Jul 13, 2023

So when running compiler debug tests it works with dependencies within a project.

So when running compiler debug tests it works with dependencies within a
project.
@vnen vnen added this to the 4.2 milestone Jul 13, 2023
@vnen vnen requested a review from a team as a code owner July 13, 2023 16:10
@dalexeev
Copy link
Member

dalexeev commented Jul 14, 2023

I tested it. This works under the following conditions:

  1. It's bin/<godot executable> --test gdscript-compiler <path/to/script.gd> command (test_gdscript.cpp).
  2. There is project.godot file.
  3. There is correct .godot/global_script_class_cache.cfg file.

It doesn't work for regular tests bin/<godot executable> --test (gdscript_test_runner.cpp). Is it intentional?

@anvilfolk
Copy link
Contributor

Interesting! So this only works because it's done within the context of a project. Is there any situation in which this might be run but there is no ProjectSettings singleton, which might cause a crash?

I was working on something similar to try to add a unit test to #79205, but there we cannot rely on ProjectSettings, I believe. My attempted solution was to add global class names found in .gd test scripts, as well as .notest.gd test scripts. Unfortunately that wasn't enough to make the class loadable and I didn't investigate further.

@vnen
Copy link
Member Author

vnen commented Jul 25, 2023

It doesn't work for regular tests bin/<godot executable> --test (gdscript_test_runner.cpp). Is it intentional?

Yes, the test runner does not use a project nor the global classes config. It generates the index on the fly from all the test files:

bool GDScriptTestRunner::generate_class_index() {
StringName gdscript_name = GDScriptLanguage::get_singleton()->get_name();
for (int i = 0; i < tests.size(); i++) {
GDScriptTest test = tests[i];
String base_type;
String class_name = GDScriptLanguage::get_singleton()->get_global_class_name(test.get_source_file(), &base_type);
if (class_name.is_empty()) {
continue;
}
ERR_FAIL_COND_V_MSG(ScriptServer::is_global_class(class_name), false,
"Class name '" + class_name + "' from " + test.get_source_file() + " is already used in " + ScriptServer::get_global_class_path(class_name));
ScriptServer::add_global_class(class_name, base_type, gdscript_name, test.get_source_file());
}
return true;
}

Interesting! So this only works because it's done within the context of a project. Is there any situation in which this might be run but there is no ProjectSettings singleton, which might cause a crash?

I don't think there's such case. This code is really only run from one code path AFAIK.

Copy link
Member

@adamscott adamscott left a comment

Choose a reason for hiding this comment

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

Approved. It has been tested and it works. Thanks @vnen!

@akien-mga akien-mga merged commit 6de0613 into godotengine:master Oct 3, 2023
13 checks passed
@akien-mga
Copy link
Member

Thanks!

@vnen vnen deleted the gdscript-load-classes-for-debug-tests branch October 19, 2023 13:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants