gnolang / gno

Gno: An interpreted, stack-based Go virtual machine to build succinct and composable apps + Gno.land: a blockchain for timeless code and fair open-source
https://gno.land/
Other
839 stars 342 forks source link

feat(gnovm): Executable Markdown #2357

Open notJoon opened 1 week ago

notJoon commented 1 week ago

Description

The doctest (tentative name) is a tool that allows code blocks in Markdown, especially those marked as "go" and "gno", to be executed using the gno VM.

It works as follows: First, it parses the code blocks (fenced code blocks) from the Markdown file. After that, the extracted code is written to a temporary file, and the code is executed at the VM level.

Also supports static analysis to automatically include imports or packages without explicitly specifying them before execution. However, in this case, it assumes the code always executes the main function, fixes the package as 'main', and only searches for missing library paths in the standard library. Additionally, to prevent unnecessary executions, a feature to cache execution results has been added.

Moving forward, there is potential to further enhance this tool to support code documentation by allowing the execution of code embedded within comments, similar to Rust.

related #2245

CLI

The CLI command is used as follows:

gno doctest -path -index

path literally means the path of the markdown to be executed. And index specifies which code block in the file to execute, based on its position. However, I plan to replace index with a feature that allows specifying tags. That will execute when there's a partial or complete match with the given tag, like go test -run <name>.

Current issues:

  1. Slow execution time.
  2. There's a problem with recognizing only realm path packages like p, r.
codecov[bot] commented 1 week ago

Codecov Report

Attention: Patch coverage is 78.60465% with 46 lines in your changes missing coverage. Please review.

Project coverage is 54.84%. Comparing base (28c3b1a) to head (5a8a2d8). Report is 5 commits behind head on master.

Files Patch % Lines
gnovm/pkg/doctest/analyzer.go 70.45% 19 Missing and 7 partials :warning:
gnovm/cmd/gno/doctest.go 75.00% 6 Missing and 6 partials :warning:
gnovm/pkg/doctest/exec.go 83.67% 4 Missing and 4 partials :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #2357 +/- ## ========================================== + Coverage 54.68% 54.84% +0.15% ========================================== Files 583 587 +4 Lines 78502 78985 +483 ========================================== + Hits 42927 43316 +389 - Misses 32367 32430 +63 - Partials 3208 3239 +31 ``` | [Flag](https://app.codecov.io/gh/gnolang/gno/pull/2357/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | Coverage Δ | | |---|---|---| | [contribs/gnodev](https://app.codecov.io/gh/gnolang/gno/pull/2357/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `23.81% <ø> (ø)` | | | [contribs/gnofaucet](https://app.codecov.io/gh/gnolang/gno/pull/2357/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `15.31% <ø> (+0.85%)` | :arrow_up: | | [contribs/gnokeykc](https://app.codecov.io/gh/gnolang/gno/pull/2357/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `0.00% <ø> (ø)` | | | [contribs/gnomd](https://app.codecov.io/gh/gnolang/gno/pull/2357/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `0.00% <ø> (ø)` | | | [gno.land](https://app.codecov.io/gh/gnolang/gno/pull/2357/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `62.54% <ø> (ø)` | | | [gnovm](https://app.codecov.io/gh/gnolang/gno/pull/2357/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `60.12% <78.60%> (+0.17%)` | :arrow_up: | | [tm2](https://app.codecov.io/gh/gnolang/gno/pull/2357/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang) | `54.36% <ø> (+0.03%)` | :arrow_up: | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=gnolang#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.