Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor integration tests by reusing godot_test macro #896

Merged
merged 2 commits into from
May 22, 2022

Conversation

Bromeon
Copy link
Member

@Bromeon Bromeon commented May 21, 2022

Reduces boilerplate of the form

fn test_with_certain_name() -> bool {
    println!(" -- test_with_certain_name");

    let ok = std::panic::catch_unwind(|| {
        // actual test code here
    })
    .is_ok();

    if !ok {
        godot_error!("   !! Test test_with_certain_name failed");
    }

    ok
}

to

godot_itest! { test_with_certain_name {
    // actual test code here
}}

which reduces repetition and focuses on important things. This is done by slightly adjusting the existing godot_test macro to godot_itest, which is needed so it can also be used in the tests crate.

This change leads to a net removal of 300 lines of code.


I was also considering a proc-macro attribute

#[godot_test]
fn test_with_certain_name() {
    // actual test code here
}

which might be a tiny bit nicer syntax-wise, and even started implementing it. But I think the declarative macro does the job, is simpler and likely faster to compile (as we don't need syn to tokenize the entire code).


Tests of this form now all have the #[must_use] attribute, yielding a warning if a boolean test result is ignored.

@Bromeon Bromeon added c: tools Component: tooling, tests, IDEs, Cargo, Rust ecosystem quality-of-life No new functionality, but improves ergonomics/internals labels May 21, 2022
@Bromeon Bromeon added this to the v0.10.1 milestone May 21, 2022
@Bromeon
Copy link
Member Author

Bromeon commented May 22, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented May 22, 2022

Build succeeded:

@bors bors bot merged commit a6063f5 into godot-rust:master May 22, 2022
@Bromeon Bromeon deleted the feature/use-test-macro branch May 22, 2022 09:38
@Bromeon
Copy link
Member Author

Bromeon commented May 22, 2022

Clippy nightly failed due to a regression in Clippy: rust-lang/rust-clippy#8867

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: tools Component: tooling, tests, IDEs, Cargo, Rust ecosystem quality-of-life No new functionality, but improves ergonomics/internals
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant