1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-06 17:25:19 +00:00

Prevent shallow scripts from leaking into the ResourceCache

Co-Authored-By: Moritz Burgdorff <mburgdorff@outlook.com>
Co-Authored-By: Lily <gofastlily@gmail.com>
This commit is contained in:
HolonProduction
2025-08-05 23:25:13 +02:00
parent 8deb221829
commit b4203f7f64
6 changed files with 84 additions and 5 deletions

View File

@@ -32,10 +32,23 @@
#include "gdscript_test_runner.h"
#include "modules/gdscript/gdscript_cache.h"
#include "tests/test_macros.h"
#include "tests/test_utils.h"
namespace GDScriptTests {
class TestGDScriptCacheAccessor {
public:
static bool has_shallow(String p_path) {
return GDScriptCache::singleton->shallow_gdscript_cache.has(p_path);
}
static bool has_full(String p_path) {
return GDScriptCache::singleton->full_gdscript_cache.has(p_path);
}
};
// TODO: Handle some cases failing on release builds. See: https://github.com/godotengine/godot/pull/88452
#ifdef TOOLS_ENABLED
TEST_SUITE("[Modules][GDScript]") {
@@ -72,6 +85,26 @@ func _init():
CHECK_MESSAGE(int(ref_counted->get_meta("result")) == 42, "The script should assign object metadata successfully.");
}
TEST_CASE("[Modules][GDScript] Loading keeps ResourceCache and GDScriptCache in sync") {
const String path = TestUtils::get_temp_path("gdscript_load_test.gd");
{
Ref<FileAccess> fa = FileAccess::open(path, FileAccess::ModeFlags::WRITE);
fa->store_string("extends Node\n");
fa->close();
}
CHECK(!ResourceCache::has(path));
CHECK(!TestGDScriptCacheAccessor::has_shallow(path));
CHECK(!TestGDScriptCacheAccessor::has_full(path));
Ref<GDScript> loaded = ResourceLoader::load(path);
CHECK(ResourceCache::has(path));
CHECK(!TestGDScriptCacheAccessor::has_shallow(path));
CHECK(TestGDScriptCacheAccessor::has_full(path));
}
TEST_CASE("[Modules][GDScript] Validate built-in API") {
GDScriptLanguage *lang = GDScriptLanguage::get_singleton();