From 5704055d30499cc63672d44001760a98abfbfc08 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Sun, 9 Oct 2022 12:41:28 -0400 Subject: Fix cyclic references in GDScript 2.0 --- modules/gdscript/tests/gdscript_test_runner.cpp | 8 +++++++- .../tests/scripts/analyzer/features/gdscript_to_preload.gd | 7 ------- .../scripts/analyzer/features/gdscript_to_preload.notest.gd | 4 ++++ .../tests/scripts/analyzer/features/gdscript_to_preload.out | 1 - .../analyzer/features/preload_constant_types_are_inferred.gd | 2 +- .../scripts/analyzer/features/preload_cyclic_reference.gd | 4 ++++ .../scripts/analyzer/features/preload_cyclic_reference.out | 2 ++ .../analyzer/features/preload_cyclic_reference_a.notest.gd | 12 ++++++++++++ .../analyzer/features/preload_cyclic_reference_b.notest.gd | 10 ++++++++++ .../scripts/analyzer/features/use_preload_script_as_type.gd | 2 +- 10 files changed, 41 insertions(+), 11 deletions(-) delete mode 100644 modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.notest.gd delete mode 100644 modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.out create mode 100644 modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.out create mode 100644 modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_a.notest.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_b.notest.gd (limited to 'modules/gdscript/tests') diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index 1ccbf9d150..7f42643c8f 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -251,7 +251,10 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) { return false; } } else { - if (next.get_extension().to_lower() == "gd") { + if (next.ends_with(".notest.gd")) { + next = dir->get_next(); + continue; + } else if (next.get_extension().to_lower() == "gd") { #ifndef DEBUG_ENABLED // On release builds, skip tests marked as debug only. Error open_err = OK; @@ -597,6 +600,9 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) { } enable_stdout(); + + GDScriptCache::remove_script(script->get_path()); + return result; } diff --git a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd b/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd deleted file mode 100644 index ea744e3027..0000000000 --- a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd +++ /dev/null @@ -1,7 +0,0 @@ -const A := 42 - -func test(): - pass - -func something(): - return "OK" diff --git a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.notest.gd new file mode 100644 index 0000000000..c3fc176679 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.notest.gd @@ -0,0 +1,4 @@ +const A := 42 + +func something(): + return "OK" diff --git a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.out b/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.out deleted file mode 100644 index d73c5eb7cd..0000000000 --- a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.out +++ /dev/null @@ -1 +0,0 @@ -GDTEST_OK diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd b/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd index 276875dd5a..9d0324ead8 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd @@ -1,4 +1,4 @@ -const Constants = preload("gdscript_to_preload.gd") +const Constants = preload("gdscript_to_preload.notest.gd") func test(): var a := Constants.A diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.gd b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.gd new file mode 100644 index 0000000000..b730453a8a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.gd @@ -0,0 +1,4 @@ +const A = preload("preload_cyclic_reference_a.notest.gd") + +func test(): + A.test_cyclic_reference() diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.out b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.out new file mode 100644 index 0000000000..14bb971221 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.out @@ -0,0 +1,2 @@ +GDTEST_OK +godot diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_a.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_a.notest.gd new file mode 100644 index 0000000000..7a6035ded1 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_a.notest.gd @@ -0,0 +1,12 @@ +const B = preload("preload_cyclic_reference_b.notest.gd") + +const WAITING_FOR = "godot" + +static func test_cyclic_reference(): + B.test_cyclic_reference() + +static func test_cyclic_reference_2(): + B.test_cyclic_reference_2() + +static func test_cyclic_reference_3(): + B.test_cyclic_reference_3() diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_b.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_b.notest.gd new file mode 100644 index 0000000000..3ea5b01156 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_b.notest.gd @@ -0,0 +1,10 @@ +const A = preload("preload_cyclic_reference_a.notest.gd") + +static func test_cyclic_reference(): + A.test_cyclic_reference_2() + +static func test_cyclic_reference_2(): + A.test_cyclic_reference_3() + +static func test_cyclic_reference_3(): + print(A.WAITING_FOR) diff --git a/modules/gdscript/tests/scripts/analyzer/features/use_preload_script_as_type.gd b/modules/gdscript/tests/scripts/analyzer/features/use_preload_script_as_type.gd index 5f73064cc0..beabf3d2e5 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/use_preload_script_as_type.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/use_preload_script_as_type.gd @@ -1,4 +1,4 @@ -const preloaded : GDScript = preload("gdscript_to_preload.gd") +const preloaded : GDScript = preload("gdscript_to_preload.notest.gd") func test(): var preloaded_instance: preloaded = preloaded.new() -- cgit v1.2.3