-
Notifications
You must be signed in to change notification settings - Fork 18
[Extension] Extract and test Compliant and Non-compliant code blocks #91
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for scrc-coding-guidelines ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Hey @x0rw -- thanks for starting on this! Could I ask for your reason for choosing the 2021 edition instead of the newer 2024 edition? |
I just went with 2021 out of habit. |
Could we update to the 2024 edition then? |
Hey @x0rw -- wanted to check in to see if this is a work in progress or ready for review |
It’s still in progress. I need to write some tests for it (haven’t found the time yet) because it can easily fail and cause false alerts, I guess. |
Okay, thanks for the update. |
e5df07c
to
65a6733
Compare
Hey @x0rw -- checking in on this PR. How's it going? Anything needed to help? |
migrate from aggregating test blocks in pure .rs file testing, to a proper project structure to manage dependancies properly(tokio,...)
97509eb
to
b882c1d
Compare
Hey @PLeVasseur.
|
Hi @x0rw, sorry to bother you. Should I mark this as ready for review? Since it's currently a Draft PR :3 |
Hi @felix91gr 👋🏻 @PLeVasseur what do you think? |
@x0rw you mean like code in a non-compliant example that triggers a panic, that sort of thing? |
Hi @felix91gr Triggering a panic is fine because we can set the Sorry for the late reply 😄. |
Hey @x0rw -- here's an idea: what if we have folks submit examples using the They've had to put some thought into attributes to allow for things like this. For example, pulling from the above doc, we could have bits that are intended to not be compiled / checked be tagged like this:
And for bits of code that are known to panic like this:
(sorry for the weird formatting, I struggled to get this to show up correctly with the "embedded" backticks) We could consider then on whether to leave these annotations in the rendered version or remove it (using an additional part added to our Sphinx extension) Thoughts? tagging @felix91gr as well given he's been interested |
I think this is brilliant.
I'm not 100% sure about how Regarding non-compiling code... well, if code doesn't compile, then it can't be either a compliant nor a non-compliant example, right? Since the point of both kinds of examples is that they would compile, and therefore the guidelines (and tooling associated with the guidelines) are needed to differentiate both of them.
Dw mate, it's all good :) |
As a side note: I did something similar with IMO the @x0rw Do you think such a matching feature would be easy to add? |
Hi @PLeVasseur
This is a great idea, which will save us a lot of time and thinking, the only thing that should be thought of now is how we should handle these rustdoc blocks when Sphinx renders them into HTML, maybe just striping them out of the rustdoc is enough. HI @senier 👋
Great idea, but there is another way with rustdoc, we can use catch_unwind with manual assertions so in the end we can do something like in the example in here: https://doc.rust-lang.org/std/panic/fn.catch_unwind.html, in addition we can wrap a macro around it so in the end the authors can do
I still haven't looked at the limitations of this approach.
I encountered a similar challenge when trying to create tests that intentionally segfaults when the program triggers a specific syscall (a Linux security mechanism enforces this). In this case, the output cannot be relied on for snapshot testing, as the OS terminates the process immediately and any buffered stdout/stderr may be partially written or lost. We can then only rely on exit codes and signals but sometimes if it is well planed we can rely on outputs but for non-compliant codes we don't want to add unrelated code just to make it relaible for the test. Tagging @felix91gr on this last part. also, I agree that there shouldn't be any non-compiling code. |
TL;DR
|
Hi @x0rw 👋
TIL! I like that idea (won't help me with my other project as the code is |
Thanks for the summary! Despite my comment, I think the Don't hesitate to let me know when you want me to review / try your code. |
Extract code blocks from .rst files and create a global Rust test file (generated.rs) to check them all together using
rustc --test --edition=2021 exts/rust-code-runner/generated.rs
under the hood.Features:
anything between
// HIDDEN START
and// HIDDEN END
will not be rendered but will still be included for compilation in the generated test file.--error-format=json output
and extract minimal error information.Tasks:
How to test:
Run:
./make.py -c --offline
it will notify you in case there is any issue in any code block,also check
exts/rust-code-runner/generated.rs
after doing so.(Not rebased yet)
Resolves #80