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

feat(gnovm): Test Coverage Support #2616

Open
wants to merge 31 commits into
base: master
Choose a base branch
from
Open

Conversation

notJoon
Copy link
Member

@notJoon notJoon commented Jul 23, 2024

Description

closes #1121

Screenshot 2024-09-11 at 6 40 38 PM

Support testing coverage functionality into previous testing framework. This feature tracks and reports which parts of the code were executed during test runs.

Key Changes

  1. Added coverage data structures
    • Implemented CoverageData and FileCoverage structs
    • Per-file executed line tracker
  2. Coverage collection machanism
    • Collect current location information after PopOp in Machine.Run() method
      • Inserted recordCoverage function for each statement to obtaining accurate coverage tracking result
    • Record executed lines throught AddHit method
  3. Coverage reporting
    • Calculate and output coverage percentage per file
      • Excludes non-executable lines (e.g., comments) from the calculation
    • Terminal visualization using ANSI color codes
  4. Connect with external tools
    • Convert coverage data to JSON format

CLI Options

CLI Options

Flag Desc Example
-cover Activate coverage analysis gno test <path> -cover
-view=<pattern> View coverage for files matching the pattern gno test <path> -cover -view=demo/foo
-show-hits Show number of times each line was executed gno test <path> -cover -view=demo/foo -show-hits
-html=<file> Generate HTML coverage report gno test <path> -cover -html=coverage.html

All coverage-related flags must be preceded by the -cover flag to be active.

Notes:

  • The report displays a list of files with their coverage percentages, color-coded based on coverage level.
  • The -view option supports partial file path patterns and can match multiple files.
  • When using -view, the output is color-coded: green for executed lines, yellow for executable but not executed lines, and white for non-executable lines.
  • The -show-hits option adds an orange hit count next to each executed line when used with -view.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Jul 23, 2024
Copy link

codecov bot commented Jul 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.49%. Comparing base (0e84846) to head (1d02c9a).
Report is 15 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2616      +/-   ##
==========================================
- Coverage   60.90%   60.49%   -0.42%     
==========================================
  Files         564      563       -1     
  Lines       75273    75068     -205     
==========================================
- Hits        45848    45409     -439     
- Misses      26055    26272     +217     
- Partials     3370     3387      +17     
Flag Coverage Δ
contribs/gnodev 61.46% <ø> (ø)
contribs/gnofaucet 14.46% <ø> (-0.86%) ⬇️
gno.land 67.92% <ø> (+0.75%) ⬆️
misc/genstd 80.54% <ø> (ø)
misc/logos 19.88% <ø> (ø)
tm2 62.06% <ø> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@notJoon
Copy link
Member Author

notJoon commented Sep 12, 2024

For simplicity for reviewing I'll change this PR as ready for review.

@notJoon notJoon marked this pull request as ready for review September 12, 2024 10:16
@notJoon notJoon marked this pull request as ready for review September 18, 2024 14:55
@zivkovicmilos
Copy link
Member

@notJoon
Can you please check why the CI is failing? 🙏

@notJoon
Copy link
Member Author

notJoon commented Oct 2, 2024

@zivkovicmilos It seems the problem is occurring when retrieving and updating the line information executed in the stdlib part. If I fix this, I'll ping you.

@thehowl
Copy link
Member

thehowl commented Oct 5, 2024

Hey @notJoon, thanks for covering this. If I get a chance, I'll try to get a review in.

I just wanted to comment because I just added a bounty on the original issue: #1121

This has been a long time coming; we had set out the requirements for a small while before you published this PR; but we have been slow in getting the bounties published 🫠

The requirements are slightly different to what you implemented here in general, and reflect the general comment I'd make on the PR right now: I like the terminal visualization, but ultimately it doesn't matter. Terminal visualization should be the responsibility of other tools based on the eventual coverprofile. If we use coverprofiles properly, it means we can re-use the tools Go already has; and that's more important.

So, I'd recommend you move forward more in the direction of ensuring compatibility in that direction and as specified in the requirements. Note that the bounties exclude AiB/NT employees from working on the bounty, but not grantees; so at your discretion, you can also claim the bounty.

Thanks!

@notJoon
Copy link
Member Author

notJoon commented Oct 5, 2024

@thehowl Looks like the bounty program is gonna start 😮

The CLI output was temporarily added to view during development, so it doesn't matter actually. Ultimately, the goal is to make it as similar as possible to Go's test coverage functionality.

Originally, before the bounty was added, I was planning to split the work to reduce the PR size, but in this case, I wonder if all the work needs to be completed in a single PR?

Or should I submit a separate work plan? There seems to be more information in the attached link, but I don't have permission to access it. Thank you!

@thehowl
Copy link
Member

thehowl commented Oct 5, 2024

separate please! smaller PRs are better in general :)

once the issue is fully addressed, we'll propose how we intend to distribute the bounty (mostly in case you're not the only once who contributed to it) :)

@thehowl thehowl closed this Oct 5, 2024
@thehowl thehowl reopened this Oct 5, 2024
@thehowl
Copy link
Member

thehowl commented Oct 5, 2024

apologies, misclicked.

@notJoon
Copy link
Member Author

notJoon commented Oct 5, 2024

separate please! smaller PRs are better in general :)

Good. I'll get this done as quickly as possible 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 🤖 gnovm Issues or PRs gnovm related
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

gno test -cover ...
3 participants