Skip to content

Commit

Permalink
Merge pull request #20 from StatisMike/feature/gd-rehearse_update
Browse files Browse the repository at this point in the history
gd_rehearse_update
  • Loading branch information
StatisMike authored Feb 28, 2024
2 parents 084943f + bb0379d commit e0f2830
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gdext_check.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: schedule-check
name: Continuous tests
on:
schedule:
- cron: "27 06 * * *"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/successful_merge.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:

doc:
name: Deploy documentation on Github Pages
runs-on: ubuntu-22.04
runs-on: ubuntu-latest

steps:
- name: Checkout sources
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# gd-props
![tests workflow](https://github.com/StatisMike/gd-props/actions/workflows/tests.yaml/badge.svg)
![Schedule tests](https://github.com/StatisMike/gd-props/actions/workflows/gdext_check.yaml/badge.svg)
[![Latest compatible gdext](https://byob.yarr.is/StatisMike/gd-props/gdext_latest_success)](https://github.com/godot-rust/gdext)

> Resources are akin to the versatile props that set the scene for an interactive masterpiece on the stage of game world.
Expand Down
13 changes: 9 additions & 4 deletions tests/rust/src/bench/gdbin.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use gd_rehearse::bench::gdbench;
use gd_rehearse::bench::*;
use godot::engine::{load, save};
use godot::obj::Gd;
use serde::{Deserialize, Serialize};

use crate::remove_file;
use crate::structs::node::{test_resource_setup, TestResourceNode};
use crate::structs::resource::TestResource;

#[gdbench(repeat = 10)]
Expand All @@ -30,13 +31,17 @@ fn deserialize() -> bool {
true
}

#[gdbench(repeat = 5, scene_path = "res://dev_test.tscn")]
fn gdbin_save() -> bool {
#[gdbench(repeat = 10, setup = test_resource_setup, scene_path = "res://dev_test.tscn")]
fn gdbin_save(ctx: &BenchContext) -> bool {
let path = "res://";
let file = "test.gdbin";
let file_path = &format!("{}{}", path, file);

let resource = TestResource::new_random(50, 50);
let resource = ctx
.get_setup_node_as::<TestResourceNode>("TestResourceNode")
.bind()
.res
.clone();

save(resource, file_path);

Expand Down
13 changes: 9 additions & 4 deletions tests/rust/src/bench/gdron.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use gd_rehearse::bench::gdbench;
use gd_rehearse::bench::{gdbench, BenchContext};
use godot::engine::{load, save};
use godot::obj::Gd;
use serde::{Deserialize, Serialize};

use crate::remove_file;
use crate::structs::node::{test_resource_setup, TestResourceNode};
use crate::structs::resource::TestResource;

#[gdbench(repeat = 10)]
Expand All @@ -30,13 +31,17 @@ fn deserialize() -> bool {
true
}

#[gdbench(repeat = 5, scene_path = "res://dev_test.tscn")]
fn gdron_save() -> bool {
#[gdbench(repeat = 10, setup = test_resource_setup, scene_path = "res://dev_test.tscn")]
fn gdron_save(ctx: &BenchContext) -> bool {
let path = "res://";
let file = "test.gdron";
let file_path = &format!("{}{}", path, file);

let resource = TestResource::new_random(50, 50);
let resource = ctx
.get_setup_node_as::<TestResourceNode>("TestResourceNode")
.bind()
.res
.clone();

save(resource, file_path);

Expand Down
8 changes: 4 additions & 4 deletions tests/rust/src/itest/export.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use gd_rehearse::{itest::gditest, CaseContext};
use gd_rehearse::itest::*;
use godot::{
builtin::{GString, NodePath},
engine::NodeExt,
Expand All @@ -7,15 +7,15 @@ use godot::{
use crate::structs::node::ExportTestNode;

#[gditest(scene_path = "res://export_test.tscn")]
fn exported_can_retrieve_node(ctx: &CaseContext) {
fn exported_can_retrieve_node(ctx: &TestContext) {
let node = ctx
.scene_tree()
.try_get_node_as::<ExportTestNode>(NodePath::from("ExportTestNode"));
assert!(node.is_some());
}

#[gditest(scene_path = "res://export_test.tscn")]
fn exported_bundled_works(ctx: &CaseContext) {
fn exported_bundled_works(ctx: &TestContext) {
let node = ctx
.scene_tree()
.try_get_node_as::<ExportTestNode>(NodePath::from("ExportTestNode"))
Expand Down Expand Up @@ -61,7 +61,7 @@ fn exported_bundled_works(ctx: &CaseContext) {
}

#[gditest(scene_path = "res://export_test.tscn")]
fn exported_ext_works(ctx: &CaseContext) {
fn exported_ext_works(ctx: &TestContext) {
let node = ctx
.scene_tree()
.try_get_node_as::<ExportTestNode>(NodePath::from("ExportTestNode"))
Expand Down
28 changes: 24 additions & 4 deletions tests/rust/src/structs/node.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use godot::engine::INode;
use godot::obj::Gd;
use gd_rehearse::bench::BenchContext;
use godot::engine::{INode, Node};
use godot::obj::{Base, Gd, NewAlloc};
use godot::register::{godot_api, GodotClass};

use super::resource::{WithBundledGd, WithExtGd};
use super::resource::{TestResource, WithBundledGd, WithExtGd};

#[derive(GodotClass)]
#[class(base=Node)]
Expand All @@ -15,7 +16,7 @@ pub struct ExportTestNode {

#[godot_api]
impl INode for ExportTestNode {
fn init(_base: godot::obj::Base<Self::Base>) -> Self {
fn init(_base: Base<Node>) -> Self {
// "res://export_test/test_resource.gdron"
let bundle_res = Gd::<WithBundledGd>::default();
// "res://export_test/with_ext_gd.gdron"
Expand All @@ -40,3 +41,22 @@ impl ExportTestNode {
self.ext_res.clone()
}
}

#[derive(GodotClass)]
#[class(base=Node)]
pub(crate) struct TestResourceNode {
pub(crate) res: Gd<TestResource>,
}

#[godot_api]
impl INode for TestResourceNode {
fn init(_base: Base<Node>) -> Self {
Self {
res: TestResource::new_random(100, 100),
}
}
}

pub(crate) fn test_resource_setup(ctx: &mut BenchContext) {
ctx.setup_add_node(TestResourceNode::new_alloc().upcast(), "TestResourceNode");
}

0 comments on commit e0f2830

Please sign in to comment.