Skip to content
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
Diff view
29 changes: 15 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,6 @@ jobs:
sudo apt install -y asciidoctor
sudo gem install asciidoctor asciidoctor-diagram rouge

- name: Install cmake-format
run: |
pipx install cmakelang
pipx inject cmakelang pyyaml

- name: Install python quality tools
run: |
pipx install pytest
pipx inject pytest pytest-forked
pipx inject pytest hypothesis
pipx install mypy
pipx install black
echo "/opt/pipx_bin" >> $GITHUB_PATH

- name: Checkout target branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
Expand All @@ -74,6 +60,21 @@ jobs:
- name: Checkout PR branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: Install python test requirements
run: |
python3 -m venv ${{github.workspace}}/test_venv
source ${{github.workspace}}/test_venv/bin/activate
pip install -r ${{github.workspace}}/requirements.txt
echo "${{github.workspace}}/test_venv/bin" >> $GITHUB_PATH

- name: Install cmake-format
run: |
pip install cmakelang pyyaml

- name: Install python quality tools
run: |
pip install mypy black

- name: Restore CPM cache
env:
cache-name: cpm-cache-0
Expand Down
2 changes: 2 additions & 0 deletions cmake/main.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ option(INFRA_PROVIDE_CLANG_TIDY "Provide .clang-tidy file" ON)
option(INFRA_PROVIDE_CMAKE_FORMAT "Provide .cmake-format.yaml file" ON)
option(INFRA_PROVIDE_PRESETS "Provide cmake presets and toolchains" ON)
option(INFRA_PROVIDE_MULL "Provide mull.yml file" ON)
option(INFRA_PROVIDE_PYTEST_REQS
"Provide pip requirements.txt for python tests" ON)
option(INFRA_PROVIDE_GITIGNORE "Add provided things to .gitignore" ON)
option(INFRA_USE_SYMLINKS "Use symlinks to provide common files" ON)

Expand Down
8 changes: 8 additions & 0 deletions cmake/setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ function(make_gitignore)
list(APPEND GITIGNORE_CONTENTS "mull.yml")
endif()
endif()
if(INFRA_PROVIDE_PYTEST_REQS)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/requirements.txt")
list(APPEND GITIGNORE_CONTENTS "requirements.txt")
endif()
endif()
endif()

string(REPLACE ";" "\n" GITIGNORE_CONTENTS "${GITIGNORE_CONTENTS}")
Expand Down Expand Up @@ -112,6 +117,9 @@ if(PROJECT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
if(INFRA_PROVIDE_MULL)
put_in_project_dir("mull.yml")
endif()
if(INFRA_PROVIDE_PYTEST_REQS)
put_in_project_dir("requirements.txt")
endif()

if(INFRA_PROVIDE_GITHUB_WORKFLOWS)
execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory
Expand Down
4 changes: 2 additions & 2 deletions cmake/test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ function(add_python_test_target name)
set(include_dirs_arg --include_dirs ${include_dirs})
endif()
set(target_test_command
env "PYTHONPYCACHEPREFIX=${CMAKE_BINARY_DIR}/__pycache__" pytest
--forked -o "cache_dir=${CMAKE_BINARY_DIR}/.pytest_cache"
env "PYTHONPYCACHEPREFIX=${CMAKE_BINARY_DIR}/__pycache__" pytest -n
auto -o "cache_dir=${CMAKE_BINARY_DIR}/.pytest_cache"
--rootdir=${CMAKE_SOURCE_DIR} -s ${UNIT_FILES} ${include_files_arg}
${include_dirs_arg} ${UNIT_EXTRA_ARGS})

Expand Down
6 changes: 6 additions & 0 deletions docs/options.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ level, and a `toolchains` directory.

When `ON`, this repository provides a `mull.yml` file at the root level.

*`INFRA_PROVIDE_PYTEST_REQS`*

When `ON`, this repository provides a `requirements.txt` file at the root level.
When used with `pip install -r requirements.txt` this provides the packages
sufficient to run python tests.

*`INFRA_PROVIDE_GITIGNORE`*

When `ON`, this repository provides a `.gitignore` file at the root level. It
Expand Down
4 changes: 4 additions & 0 deletions docs/testing.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ dependencies that are not part of the CMake dependency tree. A `conftest.py`
file in the same directory as any of the `FILE`​s is automatically discovered as
such a dependency.

NOTE: Python tests use several testing packages; these can be installed using
`requirements.txt` which is provided through the `INFRA_PROVIDE_PYTEST_REQS`
option.

=== Fuzz tests

[source,cmake]
Expand Down
15 changes: 15 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# The contents of this file can be generated at latest versions available by running:
#
# $ python3 -m venv ./test_venv
# $ source ./test_venv/bin/activate
# $ pip install pytest pytest-xdist hypothesis | tail -n1 | cut -d' ' -f 3- | tr ' ' '\n' | sed 's/\(.*\)-\(.*\)/\1==\2/'
#
attrs==24.2.0
execnet==2.1.1
hypothesis==6.115.3
iniconfig==2.0.0
packaging==24.1
pluggy==1.5.0
pytest==8.3.3
pytest-xdist==3.6.1
sortedcontainers==2.4.0
Loading