Skip to content

Commit

Permalink
Try #1000:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Jan 6, 2023
2 parents 16e5847 + 6aaff59 commit 6a9b22b
Show file tree
Hide file tree
Showing 8 changed files with 258 additions and 234 deletions.
20 changes: 12 additions & 8 deletions .github/composite/godot/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,23 +62,27 @@ runs:
cd test;
mkdir -p ./project/lib;
cp ../target/debug/libgdnative_test.so ./project/lib/;
${GODOT_BIN} --path ./project/ > >(tee "${{ runner.temp }}/stdout.log");
if grep -q "Leaked instance" "${{ runner.temp }}/stdout.log"; then
${GODOT_BIN} --path ./project/ > >(tee "${{ runner.temp }}/stdout.log") 2> >(tee "${{ runner.temp }}/stderr.log");
bash ../tools/check-test-output.sh "${{ runner.temp }}/stdout.log" "${{ runner.temp }}/stderr.log";
if [[ $? -ne 0 ]]; then
exit 1;
fi;
${GODOT_BIN} -e --path ./project/ --run-editor-tests > >(tee "${{ runner.temp }}/stdout.log");
if grep -q "Leaked instance" "${{ runner.temp }}/stdout.log"; then
${GODOT_BIN} -e --path ./project/ --run-editor-tests > >(tee "${{ runner.temp }}/stdout.log") 2> >(tee "${{ runner.temp }}/stderr.log");
bash ../tools/check-test-output.sh "${{ runner.temp }}/stdout.log" "${{ runner.temp }}/stderr.log";
if [[ $? -ne 0 ]]; then
exit 1;
fi;
cargo build --features type-tag-fallback ${{ inputs.rust_extra_args }}
mkdir -p ./project/lib;
cp ../target/debug/libgdnative_test.so ./project/lib/;
${GODOT_BIN} --path ./project/ > >(tee "${{ runner.temp }}/stdout.log");
if grep -q "Leaked instance" "${{ runner.temp }}/stdout.log"; then
${GODOT_BIN} --path ./project/ > >(tee "${{ runner.temp }}/stdout.log") 2> >(tee "${{ runner.temp }}/stderr.log");
bash ../tools/check-test-output.sh "${{ runner.temp }}/stdout.log" "${{ runner.temp }}/stderr.log";
if [[ $? -ne 0 ]]; then
exit 1;
fi;
${GODOT_BIN} -e --path ./project/ --run-editor-tests > >(tee "${{ runner.temp }}/stdout.log");
if grep -q "Leaked instance" "${{ runner.temp }}/stdout.log"; then
${GODOT_BIN} -e --path ./project/ --run-editor-tests > >(tee "${{ runner.temp }}/stdout.log") 2> >(tee "${{ runner.temp }}/stderr.log");
bash ../tools/check-test-output.sh "${{ runner.temp }}/stdout.log" "${{ runner.temp }}/stderr.log";
if [[ $? -ne 0 ]]; then
exit 1;
fi;
shell: bash
2 changes: 1 addition & 1 deletion gdnative-core/src/export/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ impl<'a> Varargs<'a> {
/// Returns the remaining arguments as a slice of `Variant`s.
#[inline]
pub fn as_slice(&self) -> &'a [&'a Variant] {
self.args
&self.args[self.idx..]
}

/// Discard the rest of the arguments, and return an error if there is any.
Expand Down
31 changes: 3 additions & 28 deletions test/project/addons/editor_test_runner/plugin.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,8 @@ func _enter_tree():
run_tests = true
break
if run_tests:
_run_tests()
var tests = Tests.new()
add_child(tests)
tests.run()
else:
print("Opening editor normally for the test project. To run tests, pass `--run-editor-tests` to the executable.")

func _run_tests():
var version = Engine.get_version_info()
print(" -- Running on Godot ", version["string"])
print(" -- Rust GDNative test suite (called from editor):")
gdn = GDNative.new()
var status = false;

gdn.library = load("res://gdnative.gdnlib")

if gdn.initialize():
status = gdn.call_native("standard_varcall", "run_tests", [])

gdn.terminate()
else:
print(" -- Could not load the GDNative library.")

print()
if status:
print(" All tests PASSED.")
else:
print(" Tests FAILED.")
OS.exit_code = 1

print(" -- exiting.")
get_tree().quit()

199 changes: 3 additions & 196 deletions test/project/main.gd
Original file line number Diff line number Diff line change
@@ -1,199 +1,6 @@
extends Node

var gdn

func _ready():
var version = Engine.get_version_info()
print(" -- Running on Godot ", version["string"])
print(" -- Rust GDNative test suite:")
_timeout()

gdn = GDNative.new()
var status = false;

gdn.library = load("res://gdnative.gdnlib")

if gdn.initialize():
status = gdn.call_native("standard_varcall", "run_tests", [])

status = status && _test_argument_passing_sanity()
status = status && _test_generic_class()
status = status && _test_optional_args()
status = status && yield(_test_async_resume(), "completed")

# Godot needs another frame to dispose the executor driver node. Otherwise the process
# aborts due to `_process` being called after `terminate` (`get_api` fail, not UB).
yield(get_tree().create_timer(0.1), "timeout")

gdn.terminate()
else:
print(" -- Could not load the GDNative library.")

print()
if status:
print(" All tests PASSED.")
else:
print(" Tests FAILED.")
OS.exit_code = 1

print(" -- exiting.")
get_tree().quit()

func _timeout():
yield(get_tree().create_timer(10.0), "timeout")
print(" -- Test run is taking too long.")
OS.exit_code = 1

print(" -- exiting.")
get_tree().quit()

func _test_argument_passing_sanity():
print(" -- test_argument_passing_sanity")

var script = NativeScript.new()
script.set_library(gdn.library)
script.set_class_name("Foo")
var foo = Reference.new()
foo.set_script(script)

var status = true

status = status && _assert_choose("foo", foo, "choose", "foo", true, "bar")
status = status && _assert_choose("night", foo, "choose", "day", false, "night")
status = status && _assert_choose(42, foo, "choose_variant", 42, "int", 54.0)
status = status && _assert_choose(9.0, foo, "choose_variant", 6, "float", 9.0)

if status:
assert("foo" == foo.choose("foo", true, "bar"))
assert("night" == foo.choose("day", false, "night"))
assert(42 == foo.choose_variant(42, "int", 54.0))
assert(9.0 == foo.choose_variant(6, "float", 9.0))

if !status:
printerr(" !! test_argument_passing_sanity failed")

return status

func _assert_choose(expected, foo, fun, a, which, b):
var got_value = foo.call(fun, a, which, b)
if got_value == expected:
return true
printerr(" !! expected ", expected, ", got ", got_value)
return false

func _test_optional_args():
print(" -- _test_optional_args")
print(" -- expected error messages for edge cases:")
print(" -- missing non-optional parameter `b` (#1)")
print(" -- 1 excessive argument is given: [I64(6)]")
print(" -- the test is successful when and only when these errors are shown")

var script = NativeScript.new()
script.set_library(gdn.library)
script.set_class_name("OptionalArgs")
var opt_args = Reference.new()
opt_args.set_script(script)

var status = true

status = status && _assert_opt_args(null, opt_args, [1])
status = status && _assert_opt_args(2, opt_args, [1, 1])
status = status && _assert_opt_args(6, opt_args, [1, 3, 2])
status = status && _assert_opt_args(13, opt_args, [5, 1, 3, 4])
status = status && _assert_opt_args(42, opt_args, [4, 1, 20, 4, 13])
status = status && _assert_opt_args(null, opt_args, [1, 2, 3, 4, 5, 6])

if !status:
printerr(" !! _test_optional_args failed")

return status

func _assert_opt_args(expected, opt_args, args):
var got_value = opt_args.callv("opt_sum", args);
if got_value == expected:
return true
printerr(" !! expected ", expected, ", got ", got_value)
return false


func _test_async_resume():
print(" -- _test_async_resume")

var driver_script = NativeScript.new()
driver_script.set_library(gdn.library)
driver_script.set_class_name("AsyncExecutorDriver")
var driver = Node.new()
driver.set_script(driver_script)
add_child(driver)

var script = NativeScript.new()
script.set_library(gdn.library)
script.set_class_name("AsyncMethods")
var resume = Reference.new()
resume.set_script(script)

var status = true

# Force this to return a FunctionState for convenience
yield(get_tree().create_timer(0.1), "timeout")

var fn_state = resume.resume_add(1, self, "_get_async_number")
if !fn_state:
printerr(" !! _test_async_resume failed")
remove_child(driver)
driver.queue_free()
return false

yield(fn_state, "resumable")
status = status && fn_state.is_valid()

fn_state = fn_state.resume(2)
if !fn_state:
printerr(" !! _test_async_resume failed")
remove_child(driver)
driver.queue_free()
return false

var result = yield(fn_state, "completed")

status = status && (result == 42)

if !status:
printerr(" !! _test_async_resume failed")

remove_child(driver)
driver.queue_free()

return status

func _get_async_number():
yield(get_tree().create_timer(0.1), "timeout")
return 39

func _test_generic_class():
print(" -- _test_generic_class")

var int_script = NativeScript.new()
int_script.set_library(gdn.library)
int_script.set_class_name("IntOps")

var str_script = NativeScript.new()
str_script.set_library(gdn.library)
str_script.set_class_name("StrOps")

var int_ops = Reference.new()
int_ops.set_script(int_script)

var str_ops = Reference.new()
str_ops.set_script(str_script)

var status = true

status = status && int_ops.add(1, 2) == 3
status = status && int_ops.sub(3, 2) == 1
status = status && str_ops.add("foo", "bar") == "foobar"

if !status:
printerr(" !! _test_generic_class failed")

return status
var tests = Tests.new()
add_child(tests)
tests.run()
8 changes: 7 additions & 1 deletion test/project/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,14 @@

config_version=4

_global_script_classes=[ ]
_global_script_classes=[ {
"base": "Node",
"class": "Tests",
"language": "GDScript",
"path": "res://tests.gd"
} ]
_global_script_class_icons={
"Tests": ""
}

[application]
Expand Down
Loading

0 comments on commit 6a9b22b

Please sign in to comment.