Skip to content

Commit

Permalink
Reorganize file structure of itest cases
Browse files Browse the repository at this point in the history
Changes:
* Group tests by shared semantics, rather than having all on top level.
* Remove 2 tests in `builtin.rs` (Vector2, VariantArray), already covered through unit-tests and other itests.
  • Loading branch information
Bromeon committed Aug 27, 2023
1 parent d9bd66f commit 64d059e
Show file tree
Hide file tree
Showing 45 changed files with 174 additions and 182 deletions.
61 changes: 0 additions & 61 deletions itest/rust/src/builtin_test.rs

This file was deleted.

File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
*/

use godot::bind::{godot_api, GodotClass};
use godot::builtin::{varray, Callable, ToVariant, Variant};
use godot::engine::Object;
use godot::builtin::inner::InnerCallable;
use godot::builtin::{varray, Callable, GodotString, StringName, ToVariant, Variant};
use godot::engine::{Node2D, Object};
use godot::obj::{Gd, Share};
use godot::prelude::GodotString;

use crate::framework::itest;

Expand Down Expand Up @@ -105,3 +105,23 @@ fn callable_call_return() {
// errors in godot but does not crash
assert_eq!(callable.callv(varray!["string"]), Variant::nil());
}

#[itest]
fn callable_call_engine() {
let obj = Node2D::new_alloc();
let cb = Callable::from_object_method(obj.share(), "set_position");
let inner: InnerCallable = cb.as_inner();

assert!(!inner.is_null());
assert_eq!(inner.get_object_id(), obj.instance_id().to_i64());
assert_eq!(inner.get_method(), StringName::from("set_position"));

// TODO once varargs is available
// let pos = Vector2::new(5.0, 7.0);
// inner.call(&[pos.to_variant()]);
// assert_eq!(obj.get_position(), pos);
//
// inner.bindv(array);

obj.free();
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use crate::framework::{expect_panic, itest};
use std::cmp::Ordering;
use std::fmt::Display;

use godot::builtin::{
dict, varray, FromVariant, GodotString, NodePath, StringName, ToVariant, Variant, Vector2,
Vector3,
};
use godot::builtin::{
Basis, Dictionary, VariantArray, VariantConversionError, VariantOperator, VariantType,
};
use godot::engine::Node2D;
use godot::obj::InstanceId;
use godot::prelude::{Basis, Dictionary, VariantArray, VariantConversionError};
use godot::sys::{GodotFfi, VariantOperator, VariantType};
use std::cmp::Ordering;
use std::fmt::{Debug, Display};
use godot::sys::GodotFfi;

use crate::common::roundtrip;
use crate::framework::{expect_panic, itest};

const TEST_BASIS: Basis = Basis::from_rows(
Vector3::new(1.0, 2.0, 3.0),
Expand Down Expand Up @@ -408,19 +413,6 @@ fn variant_hash_correct() {

// ----------------------------------------------------------------------------------------------------------------------------------------------

pub(crate) fn roundtrip<T>(value: T)
where
T: FromVariant + ToVariant + PartialEq + Debug,
{
// TODO test other roundtrip (first FromVariant, then ToVariant)
// Some values can be represented in Variant, but not in T (e.g. Variant(0i64) -> Option<InstanceId> -> Variant is lossy)

let variant = value.to_variant();
let back = T::try_from_variant(&variant).unwrap();

assert_eq!(value, back);
}

fn truncate_bad<T>(original_value: i64)
where
T: FromVariant + Display,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions itest/rust/src/builtin_tests/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

mod geometry {
mod basis_test;
mod plane_test;
mod projection_test;
mod quaternion_test;
mod rect2_test;
mod rect2i_test;
mod transform2d_test;
mod transform3d_test;
}

mod containers {
mod array_test;
mod callable_test;
mod dictionary_test;
mod rid_test;
mod signal_test;
mod variant_test;
}

mod string {
mod godot_string_test;
mod node_path_test;
mod string_name_test;
}

mod color_test;
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 22 additions & 0 deletions itest/rust/src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

use std::fmt::Debug;

use godot::builtin::{FromVariant, ToVariant};

pub fn roundtrip<T>(value: T)
where
T: FromVariant + ToVariant + PartialEq + Debug,
{
// TODO test other roundtrip (first FromVariant, then ToVariant)
// Some values can be represented in Variant, but not in T (e.g. Variant(0i64) -> Option<InstanceId> -> Variant is lossy)

let variant = value.to_variant();
let back = T::try_from_variant(&variant).unwrap();

assert_eq!(value, back);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ fn codegen_constants() {
// assert_eq!(Material::RENDER_PRIORITY_MIN, -128);
}

#[itest]
fn cfg_test() {
// Makes sure that since_api and before_api are mutually exclusive
assert_ne!(cfg!(since_api = "4.1"), cfg!(before_api = "4.1"));
assert_ne!(cfg!(since_api = "4.2"), cfg!(before_api = "4.2"));
}

// ----------------------------------------------------------------------------------------------------------------------------------------------

#[derive(GodotClass)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

mod constant_test;
mod native_structures_test;
mod node_test;
mod utilities_test;
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion itest/rust/src/framework/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::framework::{passes_filter, RustTestCase, TestContext};

#[derive(GodotClass, Debug)]
#[class(init)]
pub(crate) struct IntegrationTests {
pub struct IntegrationTests {
total: i64,
passed: i64,
skipped: i64,
Expand Down
42 changes: 6 additions & 36 deletions itest/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,15 @@

use godot::init::{gdextension, ExtensionLibrary};

mod builtin_tests;
mod common;
mod engine_tests;
mod framework;

mod array_test;
mod base_test;
mod basis_test;
mod builtin_test;
mod callable_test;
mod codegen_test;
mod color_test;
mod derive_variant;
mod dictionary_test;
mod enum_test;
mod func_test;
mod gdscript_ffi_test;
mod init_test;
mod native_structures_test;
mod node_test;
mod object_test;
mod option_ffi_test;
mod packed_array_test;
mod plane_test;
mod projection_test;
mod property_test;
mod quaternion_test;
mod rect2_test;
mod rect2i_test;
mod registration;
mod rid_test;
mod signal_test;
mod singleton_test;
mod string;
mod transform2d_test;
mod transform3d_test;
mod utilities_test;
mod variant_test;
mod virtual_methods_test;
mod object_tests;
mod register_tests;

// ----------------------------------------------------------------------------------------------------------------------------------------------
// API for test cases
// Entry point

#[gdextension(entry_point=itest_init)]
unsafe impl ExtensionLibrary for framework::IntegrationTests {}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

mod godot_string_test;
mod node_path_test;
mod string_name_test;
mod base_test;
mod object_test;
mod property_test;
mod singleton_test;
mod virtual_methods_test;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@

use std::fmt::Debug;

use crate::framework::itest;
use crate::variant_test::roundtrip;
use godot::bind::FromVariant;
use godot::bind::ToVariant;
use godot::builtin::{dict, varray, FromVariant, ToVariant, Variant};

use crate::common::roundtrip;
use crate::framework::itest;

#[macro_export]
macro_rules! roundtrip_with_skip {
($name_to:ident, $name_from:ident, $value:expr, $to_var:expr, $from_var:expr) => {
Expand Down
Loading

0 comments on commit 64d059e

Please sign in to comment.