chore: add GUT test framework

This commit is contained in:
xiaji
2026-05-29 09:16:10 +08:00
parent 5741ba1dc0
commit 07fc763413
808 changed files with 76903 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://dtt3yfg7bla2r"]
[node name="ConstObject" type="Node2D"]

View File

@@ -0,0 +1,7 @@
extends "res://addons/gut/test.gd"
func before_each():
gut.p("ran before_each", 2)
func test_assert_eq_number_not_equal():
gut.assert_eq(1, 2, "Should fail. 1 != 2")

View File

@@ -0,0 +1 @@
uid://b3n3euwd8obnu

View File

@@ -0,0 +1,4 @@
extends 'res://addons/gut/test.gd'
# per issue 290, if a const is defined and it starts with "Test" then GUT will
# treat it like an inner test class. This should not happen.
const TestConstThing = preload('res://test/resources/parsing_and_loading_samples/ConstObject.tscn')

View File

@@ -0,0 +1 @@
uid://cq1k8wxlrqnl2

View File

@@ -0,0 +1,8 @@
const b_ref := preload('res://test/resources/parsing_and_loading_samples/cyclic_ref_class_b.gd')
class CyclicRefAInnerClass:
var foo = 'bar'
class CyclicRfAInnerInnerClass:
var bar = 'foo'

View File

@@ -0,0 +1 @@
uid://be5q6d3e8y4d

View File

@@ -0,0 +1,5 @@
const a_ref := preload('res://test/resources/parsing_and_loading_samples/cyclic_ref_class_a.gd')
class CyclicRefBInnerClass:
var foo = 'bar'

View File

@@ -0,0 +1 @@
uid://dir5mfqrjbigl

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/bad_prefix.gdc"

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/extends_another_thing.gdc"

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/has_inner_class.gdc"

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/inner_classes_check_before_after.gdc"

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/parse_samples.gdc"

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/test_has_inner_class.gdc"

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/test_only_inner_classes.gdc"

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/test_samples.gdc"

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/test_samples2.gdc"

View File

@@ -0,0 +1,3 @@
[remap]
path="res://test/resources/parsing_and_loading_samples/exported/test_samples3.gdc"

View File

@@ -0,0 +1,5 @@
# used to test doubler with duplicate methods.
extends 'res://addons/gut/test.gd'
func _ready():
pass

View File

@@ -0,0 +1 @@
uid://7njq61fgknsq

View File

@@ -0,0 +1,33 @@
extends "res://addons/gut/test.gd"
func test_something():
pass
func test_nothing():
pass
class TestClass1:
extends "res://addons/gut/test.gd"
func test_context1_one():
pass
func test_context1_two():
pass
func print_something():
print('hello world')
class DifferentPrefixClass:
extends "res://addons/gut/test.gd"
func test_something():
pass
func not_a_test():
pass
class DoesNotExtend:
func test_something_not_extended():
pass
class TestDoesNotExtendTest:
func test_something():
pass
class TestExtendsTestClass1:
extends TestClass1

View File

@@ -0,0 +1 @@
uid://v7vs3xl0ns3r

View File

@@ -0,0 +1,39 @@
# ##############################################################################
# These classes are used to verify that the befores and afters are being called
# correctly with inner classes.
# ##############################################################################
extends "res://addons/gut/test.gd"
class BeforeAfterCounterTest:
extends "res://addons/gut/test.gd"
var before_all_calls = 0
var before_each_calls = 0
var after_all_calls = 0
var after_each_calls = 0
func before_all():
before_all_calls += 1
func before_each():
before_each_calls += 1
func after_all():
after_all_calls += 1
func after_each():
after_each_calls += 1
class TestInner1:
extends BeforeAfterCounterTest
func test_passing():
assert_eq(1, 1, '1 = 1')
class TestInner2:
extends BeforeAfterCounterTest
func test_passing():
assert_eq(2, 2, '2 = 2')

View File

@@ -0,0 +1,13 @@
extends "res://addons/gut/test.gd"
func test_one():
pass
func test_two():
pass
func not_prefixed():
pass
func diff_prefix_something():
pass

View File

@@ -0,0 +1 @@
uid://dmsj68r58obck

View File

@@ -0,0 +1,7 @@
extends "res://addons/gut/test.gd"
func before_each():
gut.p("ran before_each", 2)
func test_assert_eq_number_not_equal():
assert_eq(1, 2, "Should fail. 1 != 2")

View File

@@ -0,0 +1,19 @@
# This file should be ignored by add_script since it does not extend GutTest
func before_all():
print("should be ignored")
# This class matches the default prefix but should be ignored because it does
# not extend GutTest
class TestDoesNotExtendTest:
func before_all():
print("should be ignored")
# This class should be ignored because the outer script does not extend GutTest.
class TestExtendsButShouldBeIgnored:
extends GutTest
func before_all():
print("should be ignored")

View File

@@ -0,0 +1 @@
uid://capxuhdpgydxr

View File

@@ -0,0 +1,44 @@
extends "res://addons/gut/test.gd"
func before_all():
gut.p('script: pre-run')
func before_each():
gut.p('script: setup')
func after_each():
gut.p('script: teardown')
func after_all():
gut.p('script: post-run')
func test_something():
assert_true(true)
func test_nothing():
assert_true(false)
class TestClass1:
extends "res://addons/gut/test.gd"
func before_all():
gut.p('TestClass1: pre-run')
func before_each():
gut.p('TestClass1: setup')
func after_each():
gut.p('TestClass1: teardown')
func after_all():
gut.p('TestClass1: post-run')
func test_context1_one():
assert_true(true)
func test_context1_two():
pending()
func test_failing():
assert_eq(2, 1)
func print_something():
print('hello world')
class NotTestClass:
func test_something():
pass
func not_a_test():
pass

View File

@@ -0,0 +1 @@
uid://cfshg7vvo3u43

View File

@@ -0,0 +1,19 @@
extends "res://addons/gut/test.gd"
class TestInner1:
extends "res://addons/gut/test.gd"
func test_passing():
assert_eq(1, 1, '1 = 1')
func test_passing2():
assert_eq(2, 2, '2 = 2')
class TestInner2:
extends "res://addons/gut/test.gd"
func test_failing():
assert_eq(1, 2, '1 != 2')
func test_failing2():
assert_eq(2, 3, '2 != 3')

View File

@@ -0,0 +1 @@
uid://yhn3cd1hqmp0

View File

@@ -0,0 +1,53 @@
# ##############################################################################
#All the magic happens with the extends. This gets you access to all the gut
#asserts and the overridable setup and teardown methods.
#
#The path to this script is passed to an instance of the gut script when calling
#test_script
#
#WARNING
# DO NOT assign anything to the gut variable. This is set at runtime by the gut
# script. Setting it to something will cause everything to go crazy go nuts.
# ##############################################################################
extends "res://addons/gut/test.gd"
func before_each():
gut.p("ran setup", 2)
func after_each():
gut.p("ran teardown", 2)
func before_all():
gut.p("ran run setup", 2)
func after_all():
gut.p("ran run teardown", 2)
func test_assert_eq_number_not_equal():
assert_eq(1, 2, "Should fail. 1 != 2")
func test_assert_eq_number_equal():
assert_eq('asdf', 'asdf', "Should pass")
func test_assert_true_with_true():
assert_true(true, "Should pass, true is true")
func test_assert_true_with_false():
assert_true(false, "Should fail")
func test_something_else():
assert_true(false, "didn't work")
func test_show_a_gut_print():
#This is what you should use to print out stuff if
#you want to see it in context of the test that it
#ran in.
gut.p("HELLO WORLD")
#display different info based on log level. Default
#level is 0, which means it will always show up.
#Notice, that since this prints something at level 0
#it will always be printed even when the log level
#is set to print only failures.
gut.p("log 0", 0)
gut.p("log 1", 1)
gut.p("log 2", 2)

View File

@@ -0,0 +1 @@
uid://bsjyq3r2q75md

View File

@@ -0,0 +1,53 @@
# ##############################################################################
#All the magic happens with the extends. This gets you access to all the gut
#asserts and the overridable setup and teardown methods.
#
#The path to this script is passed to an instance of the gut script when calling
#test_script
#
#WARNING
# DO NOT assign anything to the gut variable. This is set at runtime by the gut
# script. Setting it to something will cause everything to go crazy go nuts.
# ##############################################################################
extends "res://addons/gut/test.gd"
func before_each():
gut.p("ran setup", 2)
func after_each():
gut.p("ran teardown", 2)
func before_all():
gut.p("ran run setup", 2)
func after_all():
gut.p("ran run teardown", 2)
func test_assert_eq_number_not_equal():
assert_eq(1, 2, "Should fail. 1 != 2")
func test_assert_eq_number_equal():
assert_eq('asdf', 'asdf', "Should pass")
func test_assert_true_with_true():
assert_true(true, "Should pass, true is true")
func test_assert_true_with_false():
assert_true(false, "Should fail")
func test_something_else():
assert_true(false, "didn't work")
func test_show_a_gut_print():
#This is what you should use to print out stuff if
#you want to see it in context of the test that it
#ran in.
gut.p("HELLO WORLD")
#display different info based on log level. Default
#level is 0, which means it will always show up.
#Notice, that since this prints something at level 0
#it will always be printed even when the log level
#is set to print only failures.
gut.p("log 0", 0)
gut.p("log 1", 1)
gut.p("log 2", 2)

View File

@@ -0,0 +1 @@
uid://dn2j5ink40gxv

View File

@@ -0,0 +1,53 @@
# ##############################################################################
#All the magic happens with the extends. This gets you access to all the gut
#asserts and the overridable setup and teardown methods.
#
#The path to this script is passed to an instance of the gut script when calling
#test_script
#
#WARNING
# DO NOT assign anything to the gut variable. This is set at runtime by the gut
# script. Setting it to something will cause everything to go crazy go nuts.
# ##############################################################################
extends "res://addons/gut/test.gd"
func before_each():
gut.p("ran setup", 2)
func after_each():
gut.p("ran teardown", 2)
func before_all():
gut.p("ran run setup", 2)
func after_all():
gut.p("ran run teardown", 2)
func test_assert_eq_number_not_equal():
assert_eq(1, 2, "Should fail. 1 != 2")
func test_assert_eq_number_equal():
assert_eq('asdf', 'asdf', "Should pass")
func test_assert_true_with_true():
assert_true(true, "Should pass, true is true")
func test_assert_true_with_false():
assert_true(false, "Should fail")
func test_something_else():
assert_true(false, "didn't work")
func test_show_a_gut_print():
#This is what you should use to print out stuff if
#you want to see it in context of the test that it
#ran in.
gut.p("HELLO WORLD")
#display different info based on log level. Default
#level is 0, which means it will always show up.
#Notice, that since this prints something at level 0
#it will always be printed even when the log level
#is set to print only failures.
gut.p("log 0", 0)
gut.p("log 1", 1)
gut.p("log 2", 2)

View File

@@ -0,0 +1 @@
uid://bx53alryr6s40

View File

@@ -0,0 +1,57 @@
extends "res://addons/gut/test.gd"
func test_has_one_defaulted_parameter(p=use_parameters(['a'])):
assert_true(true, 'this one passes')
func test_has_two_parameters(p1=null, p2=null):
assert_true(false, 'Should not see this. This should not be run.')
func test_no_parameters():
assert_true(true, 'this one passes')
func test_has_three_values_for_parameters(p=use_parameters([['a', 'a'], ['b', 'b'], ['c', 'c']])):
assert_eq(p[0], p[1])
func test_does_not_use_use_parameters(p=null):
assert_true(true, 'this passes but should never be called more than once.')
func test_three_values_and_a_yield(p=use_parameters([['a', 'a'], ['b', 'b'], ['c', 'c']])):
await wait_seconds(.2)
assert_eq(p[0], p[1])
class TestInnerClass:
extends "res://addons/gut/test.gd"
func test_inner_has_one_defaulted_parameter(p=null):
assert_true(true, 'this one passes')
func test_inner_has_two_parameters(p1=null, p2=null):
assert_true(false, 'Should not see this. This should not be run.')
func test_inner_no_parameters():
assert_true(true, 'this one passes')
class TestWithBeforeEach:
extends "res://addons/gut/test.gd"
var before_count = 0
var func_params = [1, 2, 3]
func before_each():
before_count += 1
func test_run(p = use_parameters(func_params)):
assert_eq(before_count, p)
class TestWithAfterEach:
extends "res://addons/gut/test.gd"
var after_count = 0
var func_params = [0, 1, 2]
func after_each():
after_count += 1
func test_run(p = use_parameters(func_params)):
assert_eq(after_count, p)

View File

@@ -0,0 +1 @@
uid://4hsvsw0b1k3h

View File

@@ -0,0 +1,6 @@
extends "res://addons/gut/test.gd"
# This test file should only be detected when specifying a 'specific_prefix' and 'suffix.gd'.
func test_empty():
assert_true(true, 'All is well.')

View File

@@ -0,0 +1 @@
uid://ca0tw2bdtpycj