Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@macetw
Copy link
Contributor

@macetw macetw commented Oct 25, 2022

This change implements a hierarchical (aka cascaded) directory-based html report. It adds a new argument: --html-cascaded-directories

This change re-implements how we sort the lists of source files in html, that it uses Jinja to sort, using data stored with what we pass to the template. This way, the sorting can also take into account the subdirectories that have aggregated statistical data that goes with it.

This change needed to implement a new class that manages different directories and the source files they go in. This class also knows about the parent directory that it is inside and the statistics for all of the given directory's contents.

#160

Closes #544

@macetw macetw force-pushed the hierarchical_html_new_data_model branch from bb26f9e to 848fe3c Compare October 25, 2022 19:24
@macetw macetw force-pushed the hierarchical_html_new_data_model branch from 848fe3c to 47fd53e Compare October 25, 2022 19:48
@macetw macetw added this to the Upcoming release milestone Oct 25, 2022
@macetw macetw requested a review from latk October 25, 2022 20:03
@macetw macetw force-pushed the hierarchical_html_new_data_model branch 2 times, most recently from 3043093 to 71df7c5 Compare October 25, 2022 22:04
@codecov
Copy link

codecov bot commented Oct 25, 2022

Codecov Report

Base: 94.39% // Head: 95.55% // Increases project coverage by +1.15% 🎉

Coverage data is based on head (3280267) compared to base (451b176).
Patch coverage: 92.62% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #687      +/-   ##
==========================================
+ Coverage   94.39%   95.55%   +1.15%     
==========================================
  Files          27       28       +1     
  Lines        3498     3736     +238     
  Branches      605      640      +35     
==========================================
+ Hits         3302     3570     +268     
+ Misses        125       93      -32     
- Partials       71       73       +2     
Flag Coverage Δ
ubuntu-20.04 94.50% <91.66%> (+0.11%) ⬆️
windows-2019 95.22% <92.17%> (?)

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

Impacted Files Coverage Δ
gcovr/configuration.py 99.68% <ø> (ø)
gcovr/tests/test_args.py 98.91% <ø> (+0.04%) ⬆️
gcovr/tests/test_coverage.py 100.00% <ø> (ø)
gcovr/utils.py 92.61% <ø> (+9.19%) ⬆️
gcovr/writer/csv.py 100.00% <ø> (ø)
gcovr/writer/html.py 95.43% <ø> (+0.41%) ⬆️
gcovr/writer/json.py 97.05% <ø> (ø)
gcovr/writer/txt.py 97.33% <ø> (ø)
gcovr/__main__.py 93.67% <57.14%> (-1.07%) ⬇️
gcovr/coverage.py 97.52% <94.78%> (-1.53%) ⬇️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@macetw macetw force-pushed the hierarchical_html_new_data_model branch from 71df7c5 to 1236637 Compare October 25, 2022 23:02
@Spacetown
Copy link
Member

For the Windows specific data you have to download the artefacts and override the files locally.

@macetwatargo
Copy link
Contributor

For the Windows specific data you have to download the artefacts and override the files locally.

I wish I had a windows box to practice on. :-/ I'll have to come up with something.

@macetw macetw force-pushed the hierarchical_html_new_data_model branch from 1236637 to cdce979 Compare October 26, 2022 23:35
@Spacetown
Copy link
Member

Please don't force push. After this we don't see the changes since last review.

Copy link
Member

@Spacetown Spacetown left a comment

Choose a reason for hiding this comment

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

Looks good, only some little comments.

Some general questions:

  • Shall directories always be at the top or sorted between the files? Reflect this in the test.
  • What shall be done if only one file is in a directory? Is the directory needed in this case or shall the file be added directly, removing one hierarchy level?

@macetw
Copy link
Contributor Author

macetw commented Oct 31, 2022

Looks good, only some little comments.

Some general questions:

  • Shall directories always be at the top or sorted between the files? Reflect this in the test.
  • What shall be done if only one file is in a directory? Is the directory needed in this case or shall the file be added directly, removing one hierarchy level?
  1. The directories will always be sorted based on the sorting method the user supplied. See function row_sort_keys(), which respects this. This translates into the sorting style applied at the Jinja level.
    https://github.com/macetw/gcovr/blob/cdce979872c61b89363e997e8b6bf1f5dcc132aa/gcovr/writer/html.py#L612
    https://github.com/macetw/gcovr/blob/cdce979872c61b89363e997e8b6bf1f5dcc132aa/gcovr/templates/directory_page.html#L142

  2. If there is only one file in a directory ... or only one directory in a directory, these conditions cause the hierarchy to be collapsed. It is tested on the tests I put in. The "nested" test case that was already there exercises this, and I tested different sort methods on the cascaded case.
    https://github.com/macetw/gcovr/blob/cdce979872c61b89363e997e8b6bf1f5dcc132aa/gcovr/coverage.py#L364
    https://github.com/macetw/gcovr/tree/hierarchical_html_new_data_model/gcovr/tests/nested/subdir/A/C/D
    https://github.com/macetw/gcovr/tree/hierarchical_html_new_data_model/gcovr/tests/nested/subdir/B

@macetw
Copy link
Contributor Author

macetw commented Nov 30, 2022

Looks good, only some little comments.
Some general questions:

  • Shall directories always be at the top or sorted between the files? Reflect this in the test.
  • What shall be done if only one file is in a directory? Is the directory needed in this case or shall the file be added directly, removing one hierarchy level?
  1. The directories will always be sorted based on the sorting method the user supplied. See function row_sort_keys(), which respects this. This translates into the sorting style applied at the Jinja level.
    https://github.com/macetw/gcovr/blob/cdce979872c61b89363e997e8b6bf1f5dcc132aa/gcovr/writer/html.py#L612
    https://github.com/macetw/gcovr/blob/cdce979872c61b89363e997e8b6bf1f5dcc132aa/gcovr/templates/directory_page.html#L142
  2. If there is only one file in a directory ... or only one directory in a directory, these conditions cause the hierarchy to be collapsed. It is tested on the tests I put in. The "nested" test case that was already there exercises this, and I tested different sort methods on the cascaded case.
    https://github.com/macetw/gcovr/blob/cdce979872c61b89363e997e8b6bf1f5dcc132aa/gcovr/coverage.py#L364
    https://github.com/macetw/gcovr/tree/hierarchical_html_new_data_model/gcovr/tests/nested/subdir/A/C/D
    https://github.com/macetw/gcovr/tree/hierarchical_html_new_data_model/gcovr/tests/nested/subdir/B

Update:
With the most recent commits, the row_sort_keys() function no longer exists, but the sort_coverage() function is made to sort using the same strategies for files as for directories. Note that the line_coverage() and branch_coverage() functions with DirectoryCoverage had to be implemented but are simple wrapper functions.

Copy link
Member

@Spacetown Spacetown left a comment

Choose a reason for hiding this comment

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

Some suggestions regarding path normalization.

@macetw
Copy link
Contributor Author

macetw commented Dec 6, 2022

Looks good, only some little comments.
Some general questions:

  • Shall directories always be at the top or sorted between the files? Reflect this in the test.
  • What shall be done if only one file is in a directory? Is the directory needed in this case or shall the file be added directly, removing one hierarchy level?
  1. The directories will always be sorted based on the sorting method the user supplied. See function row_sort_keys(), which respects this. This translates into the sorting style applied at the Jinja level.
    https://github.com/macetw/gcovr/blob/cdce979872c61b89363e997e8b6bf1f5dcc132aa/gcovr/writer/html.py#L612
    https://github.com/macetw/gcovr/blob/cdce979872c61b89363e997e8b6bf1f5dcc132aa/gcovr/templates/directory_page.html#L142
  2. If there is only one file in a directory ... or only one directory in a directory, these conditions cause the hierarchy to be collapsed. It is tested on the tests I put in. The "nested" test case that was already there exercises this, and I tested different sort methods on the cascaded case.
    https://github.com/macetw/gcovr/blob/cdce979872c61b89363e997e8b6bf1f5dcc132aa/gcovr/coverage.py#L364
    https://github.com/macetw/gcovr/tree/hierarchical_html_new_data_model/gcovr/tests/nested/subdir/A/C/D
    https://github.com/macetw/gcovr/tree/hierarchical_html_new_data_model/gcovr/tests/nested/subdir/B

Since I wrote this, I changed the sorting method to run python-based sort_coverage() even within the subdirectory level, based on feedback on this PR. I think there's still a future improvement that a client-user would like to sort based on any column, that it would be javascript/typescript-based sort, but that's just for future-thinking.

@Spacetown
Copy link
Member

Only one last question before merging this PR.
In the test cascaded-no-details only folder A is shown without more information. I think this doesn't make sense. Three ideas how to prevent this:

  • The option --html-cascaded-directories implies --html-details (my prefered solution).
  • The option --html-cascaded-directories is ignored (with a warning) if --html-details is missing.
  • The option --html-cascaded-directories without --html-details will raise an error.

If you agree that the cascading directories only make sens with the details I would also suggest to rename the option to --html-details-cascaded-directories to show that it's related to the details.

@latk
Copy link
Member

latk commented Dec 11, 2022

Naming command line options is the kind of thing where we only have one attempt to get it right – once some behaviour is implemented, people will depend on that for the next half decade or so.

I agree with @Spacetown that cascaded-directories will typically imply detail-pages.

I expect that this option will be used quite frequently, and will replace --html-details as the typical way to get HTML output. Thus, the command line options to get a cascaded report should be short and easy to type.

My preferred solution would be three levels of detail in the HTML report, with each level including the content of the previous levels:

  • --html for a summary of the entire project in a single HTML file
  • --html-details for that summary plus annotated per-source-file reports
  • --html-nested for per-directory summaries plus annotated per-source-file reports, intended for large projects where summarizing all coverage data in a single HTML file would be overwhelming

If we want to enable nested summaries without per-source-file annotated reports, I'd rather do this via something like --html-nested --no-html-details, but I'm not sure if our configuration data model can express that (since these options aren't boolean flags, but take a destination filename).

@Spacetown
Copy link
Member

My preferred solution would be three levels of detail in the HTML report, with each level including the content of the previous levels:

* `--html` for a summary of the entire project in a single HTML file

* `--html-details` for that summary plus annotated per-source-file reports

* `--html-nested` for per-directory summaries plus annotated per-source-file reports, intended for large projects where summarizing all coverage data in a single HTML file would be overwhelming

I think this options are the way we should go. Since nested without details will hide the needed information someone needs good arguments to request this.

- The option is changed from a flag to a output option (same as --html-details). Use all possibilities to set the output file.
- Add --html-syntax-highlighting as main name for --html-details-syntax-highlighting since it is used for details and for nested reports.
@Spacetown Spacetown force-pushed the hierarchical_html_new_data_model branch from 218ef00 to e0c775a Compare January 6, 2023 23:20
@Spacetown Spacetown force-pushed the hierarchical_html_new_data_model branch from e0c775a to 93c7b4a Compare January 6, 2023 23:34
@Spacetown
Copy link
Member

@macetw I've pushded the open changes on your branch. If you don't have pending changes I can merge the PR.

@macetw
Copy link
Contributor Author

macetw commented Jan 7, 2023

For what it's worth, these additional changes by @Spacetown look good. Thank you.

@macetw
Copy link
Contributor Author

macetw commented Jan 7, 2023

@macetw I've pushded the open changes on your branch. If you don't have pending changes I can merge the PR.

Please proceed as you see fit. Thank you

@Spacetown
Copy link
Member

@macetw Thanks for implementing this long requested feature.

@Spacetown Spacetown merged commit dce78fc into gcovr:master Jan 7, 2023
D-Walther pushed a commit to D-Walther/gcovr that referenced this pull request Jun 16, 2025
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.

HTML index by folder Is it possible to hyperlink and nest directories in --html-details output?

4 participants