8000 Add session to generate screenshots from html by Spacetown · Pull Request #877 · gcovr/gcovr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add session to generate screenshots from html #877

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

Merged
merged 20 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
8000
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Declare that the script files will always have LF line endings on checkout.
# Otherwise using cygwin and WSL to execute these will fail if checkout is done on Windows.
*.sh text eol=lf
*.csv text eol=crlf
13 changes: 12 additions & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install nox
python -m pip install nox requests
- name: Lint files
run: |
nox --non-interactive --session lint
Expand All @@ -78,6 +78,17 @@ jobs:
- name: Generate documentation
run: |
nox --non-interactive --session doc

# Check if f 8000 iles are modified (outdated screenshots)
Status=$(git status --porcelain | grep -F '.jpeg' || exit 0)
if [ -n "$Status" ] ; then
echo "Following files are modified:"
echo "$Status"

echo "Please regenerate the screenshots!"
exit 1
fi
exit 0
- name: Test bundle of app
run: |
nox --non-interactive --session bundle_app
Expand Down
17 changes: 14 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python3 -m pip install nox
python3 -m pip install nox requests
- name: Lint files
run: |
nox --non-interactive --session lint
Expand Down Expand Up @@ -193,7 +193,18 @@ jobs:
- name: Generate documentation
if: ${{ (! startsWith(matrix.python-version,'pypy')) && (! startsWith(matrix.os,'windows-'))}}
run: |
nox --non-interactive --session doc
nox --non-interactive --session doc || exit 1

# Check if files are modified (outdated screenshots)
Status=$(git status --porcelain | grep -F '.jpeg' || exit 0)
if [ -n "$Status" ] ; then
echo "Following files are modified:"
echo "$Status"

echo "Please regenerate the screenshots!"
exit 1
fi
exit 0
- name: Test bundle of app
run: |
nox --non-interactive --session bundle_app
Expand Down Expand Up @@ -230,7 +241,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python3 -m pip install nox
python3 -m pip install nox requests
- uses: actions/checkout@v4
- name: Build Docker
run: |
Expand Down
37 changes: 21 additions & 16 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Bug fixes and small improvements:

Documentation:

- Add nox session to generate the screenshots from the HTML files. (:issue:`877`)

Internal changes:

- Improve Dockerfile for faster rebuilds by using cache. (:issue:`878`)
Expand All @@ -35,7 +37,7 @@ Breaking changes:

New features and notable changes:

- Add `--html-template-dir` option to use custom Jinja2 templates (:issue:`758`)
- Add `--html-template-dir` option to use custom Jinja2 templates. (:issue:`758`)
- Add block numbers and md5 sums of code lines to data model. (:issue:`764`)
- If the CSS given with :option:`--html-css` contains the string ``/* Comment.Preproc */`` no ``pygments`` CSS is added anymore. (:issue:`786`)
- Add support for ``Devcontainer`` and ``GitHub Codespaces``. (:issue:`771`)
Expand All @@ -47,9 +49,11 @@ New features and notable changes:
- Add support for importing Cobertura XML files with ``--cobertura-add-tracefile`` option. (:issue:`805`)
- Add :option:`--jacoco` to generate JaCoCo XML format. (:issue:`823`))
- Add function coverage to HTML report. (:issue:`828`)
- Improve sorting of data in reports (:issue:`817`):
- Improve sorting of data in reports. (:issue:`817`):

- Sort file names alpha numerical and with casefold (see `str.casefold <https://docs.python.org/3.11/library/stdtypes.html?highlight=str%20casefold#str.casefold>`_) (``file_10.c`` comes after ``file_0.c``).
- Sort file names alpha numerical and with casefold
(see `str.casefold <https://docs.python.org/3.11/library/stdtypes.html?highlight=str%20casefold#str.casefold>`_)
(``file_10.c`` comes after ``file_0.c``).
- Always sort at the end by filename if line or branch coverage is identical for a file.
- Add :option:`--sort-branches` to sort by branches instead of lines, this is the default if :option:`--txt-branches` is used.
- Add :option:`--sort-reverse` to reverse the sort order.
Expand All @@ -71,7 +75,7 @@ New features and notable changes:
than several flags.

- The development branch is renamed from ``master`` to ``main``. (:issue:`829`, :issue:`873`)
- Add support for decision coverage metric in text report (:issue:`864`)
- Add support for decision coverage metric in text report. (:issue:`864`)
- Split list of functions into tables with maximum 10000 rows to fix rendering issues. (:issue:`858`)

Bug fixes and small improvements:
Expand All @@ -91,22 +95,22 @@ Bug fixes and small improvements:

Documentation:

- Fix wrong command in ``How to create a standalone application`` docs (:issue:`792`)
- Update output html to add github style themes (:issue:`818`)
- Fix wrong command in ``How to create a standalone application`` docs. (:issue:`792`)
- Update output html to add github style themes. (:issue:`818`)

Internal changes:

- Do not scrub versions in reference data. (:issue:`747`)
- Add interface for the different formats to easily add new formats. (:issue:`755`)
- All options have now a prefix of the format and all long option names can be used in a configuration file. (:issue:`755`)

- :option:`--txt-summary` in addition to :option:`--print-summary`
- :option:`--json-add-tracefile` in addition to :option:`--add-tracefile`
- :option:`--gcov-delete` in addition to :option:`--delete`
- :option:`--gcov-keep` in addition to :option:`--keep`
- :option:`--gcov-object-directory` in addition to :option:`--object-directory`
- :option:`--gcov-exclude-directories` in addition to :option:`--exclude-directories`
- :option:`--gcov-use-existing-files` in addition to :option:`--use-gcov-files`
- :option:`--txt-summary` in addition to :option:`--print-summary`.
- :option:`--json-add-tracefile` in addition to :option:`--add-tracefile`.
- :option:`--gcov-delete` in addition to :option:`--delete`.
- :option:`--gcov-keep` in addition to :option:`--keep`.
- :option:`--gcov-object-directory` in addition to :option:`--object-directory`.
- :option:`--gcov-exclude-directories` in addition to :option:`--exclude-directories`.
- :option:`--gcov-use-existing-files` in addition to :option:`--use-gcov-files`.

- Use interactive terminal for docker (support of Ctrl-C to interrupt). (:issue:`767`)
- Use separate session for flake8 and us this session in lint. (:issue:`768`)
Expand All @@ -118,6 +122,7 @@ Internal changes:
- Add support for ``clang-15`` in our test suite and fix test with write protection under Mac OS. (:issue:`853`)
- Add test for parallel execution of multiple gcovr instances. (:issue:`832`)


6.0 (08 March 2023)
-------------------

Expand All @@ -130,7 +135,7 @@ Breaking changes:
- Remove "noncode" entries in JSON reports. (:issue:`663`)
- New :option:`--exclude-noncode-lines` to exclude noncode lines. Noncode lines are not excluded by default anymore. (:issue:`704`, :issue:`705`)
- Changed :option:`--gcov-ignore-parse-errors` to accept list of errors to ignore. (:issue:`701`)
- The default filename for :option:`--cobertura` is changed from coverage.xml to cobertura.xml (:issue:`721`)
- The default filename for :option:`--cobertura` is changed from coverage.xml to cobertura.xml. (:issue:`721`)
- Handling of ``gcov`` errors:

- Do not ignore return code of ``gcov``. (:issue:`653`)
Expand All @@ -143,7 +148,7 @@ New features and notable changes:
- New :option:`--html-nested` for reports that summarize subdirectories with aggregated statistics per directory. (:issue:`687`)
- Accept `NAN %` which is used in GCOV 7.5.0 instead of an invalid value. (:issue:`651`)
- New :option:`--json-base` to define a base bath used in JSON reports. (:issue:`656`)
- New :option:`--calls` to report call coverage: function calls invoked/total (:issue:`666`)
- New :option:`--calls` to report call coverage: function calls invoked/total. (:issue:`666`)
- New nox session to generate a portable application with pyinstaller, see :ref:`standalone application`. (:issue:`661`)
- Print a warning if root directory contains symlinks. (:issue:`652`)
- Change :option:`--keep` when calling gcov internaly. (:issue:`703`)
Expand Down Expand Up @@ -178,7 +183,7 @@ Internal changes:
- Detect ``gcc`` version for running tests. (:issue:`686`)
- Use scrubbed data for ``--update_reference`` option. (:issue:`698`)
- Install ninja with package manager instead of GitHub action. (:issue:`699`)
- Rename the reference files coverage.xml to cobertura.xml and the test from xml to cobertura (:issue:`721`)
- Rename the reference files coverage.xml to cobertura.xml and the test from xml to cobertura. (:issue:`721`)
- Add support for ``clang-14`` in our test suite and improve startup performance of docker image. (:issue:`731`)
- Compare files by extension in test suite. (:issue:`733`)
- Split HTML templates into one file for each part of the page. (:issue:`735`)
Expand Down
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ text summaries and XML reports.

Example HTML summary:

.. image:: ./doc/images/screenshot-html.png
.. image:: ./doc/images/screenshot-html.jpeg

Example HTML details:

Expand Down
6 changes: 3 additions & 3 deletions admin/Dockerfile.qa
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ else
fi
python3 --version

# Install pip and nox
# Install pip, nox and requests
if [ "$DOCKER_OS" = "ubuntu:23.04" ]; then
apt-get install -y python3-pip python3-nox
apt-get install -y python3-pip python3-nox python3-requests
else
# Install dependencies.
#
Expand All @@ -55,7 +55,7 @@ else
python3 get-pip.py
rm get-pip.py
python3 -m pip install --upgrade pip
python3 -m pip install --no-cache-dir nox
python3 -m pip install --no-cache-dir nox requests
fi
EOS

Expand Down
23 changes: 7 additions & 16 deletions doc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,25 @@ SOURCEDIR = source
BUILDDIR = build

PYTHON ?= python
SCREENSHOT_FROM_HTML = wkhtmltoimage --width 700 --quality 5
SCREENSHOTS = images/screenshot-html.png images/screenshot-html-details.example.cpp.png

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile all outputs clean tests clean-images

# keep the screenshots
.PRECIOUS: $(SCREENSHOTS)
.PHONY: help Makefile all clean outputs tests

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile $(SCREENSHOTS) outputs
%: Makefile outputs tests
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

images/screenshot-%.png: examples/example-%.html
$(SCREENSHOT_FROM_HTML) $< $@

examples/example-%.html:
cd examples; ./example_html.sh

outputs:
gcovr -h > examples/gcovr.out

tests:
$(PYTHON) -m pytest examples -v
if [ "$(GCOVR_ISOLATED_TEST)" != "zkQEVaBpXF1i" ] ; then \
cd .. ; \
nox -s 'docker_build_compiler(gcc-8)' ; \
nox -s 'docker_run_compiler(gcc-8)' -- -s tests -- -k test_example ; \
fi

clean-images:
rm -f $(SCREENSHOTS)
2 changes: 1 addition & 1 deletion doc/examples/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ g++ -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
#END run

#BEGIN gcovr
gcovr
gcovr --txt example.txt
#END gcovr

rm -f program *.gc*
2 changes: 1 addition & 1 deletion doc/examples/example_branches.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ${CXX:-g++} -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
./program

#BEGIN gcovr
gcovr --branches
gcovr --txt-metric branch --txt example_branches.txt
#END gcovr

rm -f program *.gc*
2 changes: 1 addition & 1 deletion doc/examples/example_cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ cd $BLD_DIR
(
#BEGIN cmake_gcovr
cd $BLD_DIR
gcovr -r $SRC_DIR .
gcovr -r $SRC_DIR . --txt example_cmake.txt
#END cmake_gcovr
)
2 changes: 1 addition & 1 deletion doc/examples/example_cobertura.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ${CXX:-g++} -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
./program

#BEGIN gcovr
gcovr --cobertura-pretty
gcovr --cobertura-pretty example_cobertura.xml
#END gcovr

if [[ "$OSTYPE" != "msys" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/example_csv.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ${CXX:-g++} -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
./program

#BEGIN gcovr
gcovr --csv
gcovr --csv example_csv.csv
#END gcovr

rm -f program *.gc*
2 changes: 1 addition & 1 deletion doc/examples/example_html.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ${CXX:-g++} -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
./program

#BEGIN gcovr html
gcovr --html
gcovr --html example_html.html
#END gcovr html

#BEGIN gcovr html details
Expand Down
2 changes: 1 addition & 1 deletion doc/examples/example_json_summary.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ${CXX:-g++} -fprofile-arcs -ftest-coverage -fPIC -O0 example.cpp -o program
./program

#BEGIN gcovr
gcovr --json-summary-pretty --json-summary
gcovr --json-summary-pretty --json-summary example_json_summary.json
#END gcovr

rm -f program *.gc*
23 changes: 9 additions & 14 deletions doc/examples/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import platform
import pytest
import subprocess
import sys

from gcovr.tests.test_gcovr import SCRUBBERS, assert_equals

Expand All @@ -47,7 +46,7 @@ def is_compiler(actual: str, *expected: str) -> bool:


def find_test_cases():
if sys.platform.startswith("win"):
if platform.system() == "Windows":
return
for script in glob.glob(datadir + "/*.sh"):
basename = os.path.basename(script)
Expand Down Expand Up @@ -75,22 +74,18 @@ def test_example(example):
cmd = example.script
baseline_file = example.baseline
scrub = SCRUBBERS[example.format]
# Read old file
with open(baseline_file, newline="") as f:
baseline = scrub(f.read())

startdir = os.getcwd()
os.chdir(datadir)
output = subprocess.check_output(cmd).decode().replace("\r\n", "\n")
scrubbed_output = scrub(output)
with open(baseline_file) as f:
baseline = scrub(f.read())
subprocess.run(cmd)
with open(baseline_file, newline="") as f:
current = scrub(f.read())
current = scrub(current)

try:
assert_equals(
baseline_file, baseline, "<STDOUT>", scrubbed_output, encoding="utf8"
)
except AssertionError: # pragma: no cover
with open(baseline_file, "w", encoding="utf8") as out:
out.write(output)
raise
assert_equals(baseline_file, baseline, "<STDOUT>", current, encoding="utf8")
os.chdir(startdir)


Expand Down
Binary file added doc/images/screenshot-html-default-blue-src.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/images/screenshot-html-default-green-src.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/images/screenshot-html-details.example.cpp.png
Binary file not shown.
Binary file added doc/images/screenshot-html-github-blue-src.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/images/screenshot-html-github-blue-src.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/images/screenshot-html-github-dark-blue-src.png
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/images/screenshot-html-github-dark-green-src.png
Binary file not shown.
Binary file added doc/images/screenshot-html-github-green-src.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/images/screenshot-html-github-green-src.png
Binary file not shown.
Binary file added doc/images/screenshot-html.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed doc/images/screenshot-html.png
Binary file not shown.
5 changes: 5 additions & 0 deletions doc/source/output/csv.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@ This generates an CSV:
.. include:: ../../examples/example_csv.csv
:literal:

Be carefule if you print the output of a CSV to STDOUT and redirect it to
a file. According to `RFC4180 <RFC4180_>`_ the line endings must be CRLF.

.. _RFC4180: https://datatracker.ietf.org/doc/html/rfc4180

.. versionadded:: 5.0
Added :option:`--csv<gcovr --csv>`.
Loading
0