Skip to content

[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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from

Conversation

x0rw
Copy link
Contributor

@x0rw x0rw commented May 25, 2025

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:

  • marker comments to hide specific code from being rendered in html:
      .. code-block:: rust

        // HIDDEN START
        use std::fs;
        use std::io::{self, Read};
        // HIDDEN END 

anything between // HIDDEN START and // HIDDEN END will not be rendered but will still be included for compilation in the generated test file.

  • This extension is not tied to the other 'needs' extension so it can be used in other projects that require similar features.
  • A set of functions that parse rustc --error-format=json output and extract minimal error information.

Tasks:

  • Write unit tests -- this mostly uses regex(scary) for extracting code blocks.
  • Comments
  • Refactor
  • Feature-gate running code, for CI integration.

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

Copy link

netlify bot commented May 25, 2025

Deploy Preview for scrc-coding-guidelines ready!

Name Link
🔨 Latest commit b882c1d
🔍 Latest deploy log https://app.netlify.com/projects/scrc-coding-guidelines/deploys/68694de1027678000825062c
😎 Deploy Preview https://deploy-preview-91--scrc-coding-guidelines.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@x0rw x0rw marked this pull request as draft May 25, 2025 22:02
@PLeVasseur
Copy link
Collaborator

Hey @x0rw -- thanks for starting on this!

Could I ask for your reason for choosing the 2021 edition instead of the newer 2024 edition?

@x0rw
Copy link
Contributor Author

x0rw commented May 26, 2025

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.

@PLeVasseur
Copy link
Collaborator

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?

@PLeVasseur
Copy link
Collaborator

Hey @x0rw -- wanted to check in to see if this is a work in progress or ready for review

@x0rw
Copy link
Contributor Author

x0rw commented Jun 7, 2025

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.

@PLeVasseur
Copy link
Collaborator

Okay, thanks for the update.

@x0rw x0rw force-pushed the extension/execute-code-blocks branch from e5df07c to 65a6733 Compare June 25, 2025 22:50
@PLeVasseur
Copy link
Collaborator

Hey @x0rw -- checking in on this PR. How's it going? Anything needed to help? ☺️

@x0rw x0rw force-pushed the extension/execute-code-blocks branch from 97509eb to b882c1d Compare July 5, 2025 16:07
@x0rw
Copy link
Contributor Author

x0rw commented Jul 5, 2025

Hey @PLeVasseur.
It's ready,
Now, it aggregates all the code blocks in a rust project structure and prevents hidden sections from appearing in other builds(html..), then it sanitises these codeb blocks, to remove stuffs like "#[macro_export]" and "#[tokio::main]" that could break the tests.

  • the standard generated cargo.toml can be set to include external crates that are common in the tests like tokio, because i think when we reach Concurrency chapters, we will need external crates for some examples.
  • running ./make.py collects test code blocks in build/rust-code-blocks/ and running ./make.py -c --offline --test-rust-blocks will test them and report the errors back,
    also try to intentionally write fallible code in a code block.
    and tell me if more flags or configurable options are necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add infrastructure for how to extract and test compliant and non-compliant code
2 participants