Skip to content

Commit

Permalink
Add test hint
Browse files Browse the repository at this point in the history
Similar to editor_hint, this introduces a hint if the current execution is under test. It's very hard to setup the import process the same in tests - especially with nested imports - i.e. blend imports gltf which imports a texture.

Split off from godotengine#98909
  • Loading branch information
demolke committed Nov 29, 2024
1 parent 94161a2 commit bc32f4e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
7 changes: 7 additions & 0 deletions core/config/engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class Engine {
HashMap<StringName, Object *> singleton_ptrs;

bool editor_hint = false;
bool tests_hint = false;
bool project_manager_hint = false;
bool extension_reloading = false;

Expand Down Expand Up @@ -157,6 +158,9 @@ class Engine {
_FORCE_INLINE_ void set_editor_hint(bool p_enabled) { editor_hint = p_enabled; }
_FORCE_INLINE_ bool is_editor_hint() const { return editor_hint; }

_FORCE_INLINE_ void set_tests_hint(bool p_enabled) { tests_hint = p_enabled; }
_FORCE_INLINE_ bool is_tests_hint() const { return tests_hint; }

_FORCE_INLINE_ void set_project_manager_hint(bool p_enabled) { project_manager_hint = p_enabled; }
_FORCE_INLINE_ bool is_project_manager_hint() const { return project_manager_hint; }

Expand All @@ -166,6 +170,9 @@ class Engine {
_FORCE_INLINE_ void set_editor_hint(bool p_enabled) {}
_FORCE_INLINE_ bool is_editor_hint() const { return false; }

_FORCE_INLINE_ void set_tests_hint(bool p_enabled) {}
_FORCE_INLINE_ bool is_tests_hint() const { return false; }

_FORCE_INLINE_ void set_project_manager_hint(bool p_enabled) {}
_FORCE_INLINE_ bool is_project_manager_hint() const { return false; }

Expand Down
4 changes: 2 additions & 2 deletions editor/editor_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,7 @@ Error EditorFileSystem::_reimport_file(const String &p_file, const HashMap<Strin
importer = ResourceFormatImporter::get_singleton()->get_importer_by_extension(p_file.get_extension());
load_default = true;
if (importer.is_null()) {
ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "BUG: File queued for import, but can't be imported, importer for type '" + importer_name + "' not found.");
ERR_FAIL_V_MSG(ERR_FILE_CANT_OPEN, "BUG: File '" + p_file + "' queued for import, but can't be imported, importer for type '" + importer_name + "' not found.");
}
}

Expand Down Expand Up @@ -3205,7 +3205,7 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) {
}

Error EditorFileSystem::reimport_append(const String &p_file, const HashMap<StringName, Variant> &p_custom_options, const String &p_custom_importer, Variant p_generator_parameters) {
ERR_FAIL_COND_V_MSG(!importing, ERR_INVALID_PARAMETER, "Can only append files to import during a current reimport process.");
ERR_FAIL_COND_V_MSG(!Engine::get_singleton()->is_tests_hint() && !importing, ERR_INVALID_PARAMETER, "Can only append files to import during a current reimport process.");
Vector<String> reloads;
reloads.append(p_file);

Expand Down
2 changes: 2 additions & 0 deletions tests/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ struct GodotTestCaseListener : public doctest::IReporter {
#ifdef TOOLS_ENABLED
if (name.contains("[Editor]")) {
Engine::get_singleton()->set_editor_hint(true);
Engine::get_singleton()->set_tests_hint(true);
EditorPaths::create();
EditorSettings::create();
}
Expand Down Expand Up @@ -376,6 +377,7 @@ struct GodotTestCaseListener : public doctest::IReporter {
#endif // TOOLS_ENABLED

Engine::get_singleton()->set_editor_hint(false);
Engine::get_singleton()->set_tests_hint(false);

if (SceneTree::get_singleton()) {
SceneTree::get_singleton()->finalize();
Expand Down

0 comments on commit bc32f4e

Please sign in to comment.