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

adds doc tests to Godot Ext #139

Merged
merged 1 commit into from
Mar 20, 2023
Merged

adds doc tests to Godot Ext #139

merged 1 commit into from
Mar 20, 2023

Conversation

astrale-sharp
Copy link
Contributor

adds doc to godot::log::*
adds passing doc test for bind.rs

#35

Copy link
Member

@lilizoey lilizoey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to get some more missing documentation!
And having more info on how to use GodotExt is nice, doctests are nice but i am so bad at figuring out how to write them properly lol.

///
///
/// Note that you have to implement init otherwise you won't be able to call new or any
/// other methods from gdscript
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing period here, and some other places too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@@ -4,6 +4,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/

/// Throws a godot warning
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this and the others, as they are equivalent to some godot-functions, you could add a

/// _Godot equivalent: @GlobalScope.push_warning()_

at the bottom. We do this in some other places too to make it easier for people familiar with godot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -75,6 +78,7 @@ pub use crate::{godot_error, godot_print, godot_script_error, godot_warn};
use crate::builtin::{StringName, Variant};
use crate::sys::{self, GodotFfi};

/// prints to the godot console, it's use is to be used by the godot_print! macro
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wording is a little clunky here, maybe just drop "it's use is to be" and have it just say "used by the godot_print! macro".
Also it should be "its use" not "it's use".
I think you can also link to the godot_print macro in the doc here?
Also, missing capitalization and period.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes that's better, thanks I'm not a native english speaker so this is a big help.

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this pull request 🙂

Maybe some general suggestions:

  • Please pay attention to use full English sentences even in documentation. That means: capitalization, full stops or punctuation in general.
  • For code examples, make sure they are properly indented and formatted (rustfmt).
  • In godot-rust, you can typically not use ``` in doctests, because the Godot engine is needed for a lot of things to work. Instead, use ```no_run.
  • Run ./check.sh locally to make sure some of the basic checks pass. See Contributing.md.
  • Pay attention to details like:
    • surrounding library symbols with single backticks whenever you refer to them from docs
    • capitalizing names properly ("GDScript" and "Godot", not "gdscript" and "godot")

///
/// # Examples
///
/// ## Basic Reference
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called RefCounted now (Reference in Godot 3).

And what do you mean with "basic"? Maybe be explicit and say:

/// ## With `RefCounted` as a base class

@@ -21,6 +22,7 @@ macro_rules! godot_warn {
};
}

/// Throws a godot error
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't throw an error (what does that even mean, there are no exceptions in Rust or GDScript?).
Instead, it prints one. Here, it would be interesting to see how it differentiates from godot_print and godot_warn.

The upstream Godot documentation can also be a good source of information, although in this particular case, the method doesn't exist as is.

@lilizoey
Copy link
Member

lilizoey commented Mar 5, 2023

Run ./check.sh locally to make sure some of the basic checks pass. See Contributing.md.

Running it locally for me didn't cause any errors, did it for you?

@Bromeon
Copy link
Member

Bromeon commented Mar 5, 2023

Running it locally for me didn't cause any errors, did it for you?

I didn't try, but I'd expect it to fail with doctests that need engine support.
Let's see what bors thinks.

bors try

bors bot added a commit that referenced this pull request Mar 5, 2023
@bors
Copy link
Contributor

bors bot commented Mar 5, 2023

try

Build succeeded:

@Bromeon Bromeon added the documentation Improvements or additions to documentation label Mar 7, 2023
@astrale-sharp
Copy link
Contributor Author

Thank you for all the comments and pointers!

i ran check.sh before pushing and it passed but bors try seems to have some fail checks :/

@astrale-sharp
Copy link
Contributor Author

I initially thought about ```no_run` but seeing as cargo test --doc was passing I decided to leave it off, should I add it ?

@Bromeon
Copy link
Member

Bromeon commented Mar 7, 2023

That's strange, it could mean that your doctests are not actually run.
Could you check if they are listed when you run cargo test or cargo test --doc?

@astrale-sharp
Copy link
Contributor Author

They are listed for sure cause they didn't run initially (i forgot a bracket somewhere) and then they started passing.

@astrale-sharp
Copy link
Contributor Author

I'm fixing some little things before i push on this PR again, taken comments into account and testing that what I write is actually correct.

@astrale-sharp
Copy link
Contributor Author

I'm running cargo test --doc just to be sure

test src/bind.rs - bind::GodotExt (line 65) ... ok
test src/bind.rs - bind::GodotExt (line 34) ... ok

definitely running and passing.

just let me reread myself

@astrale-sharp
Copy link
Contributor Author

Okay, took all comments into account, ran check.sh successfully again, I'm ready for another review or merging !

Copy link
Member

@Bromeon Bromeon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As already mentioned by sayaks on Discord, this will soon be obsolete, as #136 is almost ready.

I don't think it makes sense to merge this PR now, as it would just introduce conflicts for #136 and would be immediately reverted (for example, bind.rs is being removed by that PR). Instead, I would suggest:

  1. to move the GodotExt documentation you added to the #[derive(GodotClass)] macro documentation, in godot-macros/src/lib.rs
  2. to update it according to the new API in Virtual function dispatch #136 (should be relatively simple, GodotExt becomes <Base>Virtual, e.g. RefCountedVirtual)
  3. to leave the print docs as-is, they are fine.

Comment on lines 78 to 80
/// fn init(base : Base<Node>) -> Self {
/// MyNode {base}
/// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe run the examples through rustfmt:

Suggested change
/// fn init(base : Base<Node>) -> Self {
/// MyNode {base}
/// }
/// fn init(base: Base<Node>) -> Self {
/// MyNode { base }
/// }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

running cargo fmt or rustfmt godot-core/src/bind.rs changes no file on my system, is that expected behaviour? I don't like to format by hand, my eyes are bad at this x)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it probably doesn't format doc test i assume ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's an easy workaround, you remove /// from each line of your doctests and let cargo fmt do the work

Comment on lines 40 to 46
/// #[godot_api]
/// impl MyRef {
/// #[func]
/// pub fn hello_world(&mut self) {
/// godot_print!("Hello World!")
/// }
/// }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting

@astrale-sharp
Copy link
Contributor Author

Is it better to wait for #136 to be merged, rebase and then move the documentation to macros/src/lib.rs?

@Bromeon
Copy link
Member

Bromeon commented Mar 7, 2023

#136 modifies neither macros/src/lib.rs nor the prints, so should be safe to do in parallel already.

Also, please squash commits to one once you're ready 🙂

@astrale-sharp
Copy link
Contributor Author

One last question, the doc test are now failing (since NodeVirtual and RefCountedVirtual don't exist yet)
I think we should keep them failing until #136 is merged but i can also add no_run if you want.

I hope this was helping and I have not been annoying with my slow pace and multiple questions !

@astrale-sharp
Copy link
Contributor Author

Apart from that, I squashed it good it should be good to go 😉

@Bromeon
Copy link
Member

Bromeon commented Mar 7, 2023

I think we should keep them failing until #136 is merged

Yep, agree, thanks a lot! This would also not need a rebase, bors automatically tests against latest master.

@Bromeon
Copy link
Member

Bromeon commented Mar 20, 2023

#136 is now merged, this has some conflicts.

@astrale-sharp could you rebase onto master?

adds doc tests to godot-macros
@astrale-sharp
Copy link
Contributor Author

Oh yea, I removed docs from bind.rs which was surpressed

@astrale-sharp
Copy link
Contributor Author

Seems to fail but I'm on my small laptop for weeks and it takes so long to compile godot-core x)

@Bromeon
Copy link
Member

Bromeon commented Mar 20, 2023

No worries, the failures were a network issue, nothing caused by you.

Thanks a lot for the documentation!
bors r+

@bors
Copy link
Contributor

bors bot commented Mar 20, 2023

Build succeeded:

@bors bors bot merged commit cccf247 into godot-rust:master Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants