From 2a85a3e43c3e5a568fbc2b42a88ee972df9b6086 Mon Sep 17 00:00:00 2001 From: LunarCapsule127 <287847627+LunarCapsule127@users.noreply.github.com> Date: Wed, 2 Dec 2026 02:31:31 +0000 Subject: [PATCH 1/3] Add AGENTS.md with the project's current working rules. --- AGENTS.md | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 AGENTS.md diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..08fecd52d --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,91 @@ +# AGENTS.md + +Guidance for anyone contributing to libCellML, whether a person or an AI coding tool. +It points to the project's documentation for what is already written down, and spells out the rules that are followed in practice but not documented yet. +Some pages in `docs/` were written before the project moved to GitHub Actions and the `main` branch; where they differ from this file, this file describes how the project works today. + +## Where things are written down + +| Topic | Where | +| --- | --- | +| Setting up a development machine (Git, CMake 3.26 or later, compiler, libxml2, zlib, SWIG) | `docs/setup.rst` | +| Dependency versions | `docs/versions.rst` | +| Configuring and building | `docs/configure_and_build.rst`, with the CMake options in `docs/dev_configuration_options.rst` | +| Running tests, coverage and formatting checks | `docs/testing.rst` | +| The contribution process: issues, topic branches, test-driven development, pull requests, review feedback | `docs/contributing.rst` | +| What reviewers check before merging | `docs/review_process.rst` | +| Coding standards: naming, indentation, Doxygen comments, test names | `docs/coding_standards.rst` | +| Developer utilities, such as updating the generator profile SHA-1 values | `docs/dev_utilities.rst` | +| Code formatting | `.clang-format` | +| What CI runs on every pull request | `.github/workflows/ci.yml` and `.github/workflows/spell-check.yml` | +| Code of conduct | `CODE_OF_CONDUCT.rst` | + +## The project + +libCellML is a C++20 library for reading, validating, analysing and generating code from CellML 2.0 models, with Python bindings (SWIG) and JavaScript bindings (Emscripten). + +- `src/`: the library. Public headers are in `src/api/libcellml/`. +- `src/bindings/interface/`: SWIG interface files for the Python bindings. +- `src/bindings/javascript/`: the JavaScript bindings. +- `tests//`: GoogleTest tests, one folder per area (`parser`, `validator`, `generator`, ...). Each folder lists its source files in `tests.cmake`. +- `tests/resources/`: CellML models and expected output used by the tests. +- `tests/bindings/python/` and `tests/bindings/javascript/`: tests for the bindings. + +## Pull requests + +These add to `docs/contributing.rst`, or update it where it is out of date. + +- Pull requests target `main`. Branch from the latest `main` of `cellml/libcellml`; the `develop` branch in the docs no longer exists. +- CI runs on GitHub Actions. The Buildbot mentioned in the docs is no longer used. +- The pull request title becomes its line in the changelog, which is generated from pull request titles at release time. Write the title as a short description of the change. Don't edit `docs/changelogs/` by hand. +- For contributors outside the organisation, GitHub may hold CI runs until a maintainer approves them. +- Pushing new commits dismisses earlier approvals, so reviewers approve again after the last push. +- Maintainers may merge `main` into your branch to keep it up to date. Pull before you push, and don't force-push a branch that is under review. +- When replying to a review comment with a commit SHA, the SHA on its own is enough; reviewers can see what changed. +- Commit messages are short sentences ending with a full stop. Some start with the area they change, for example `Generator: add parentheses around the NOT operand, if needed.` + +## Code + +These add to `docs/coding_standards.rst`. + +- Use British spelling in code, messages and documentation (`analyser`, `behaviour`, `initialise`). +- Warnings are errors by default (the `TWAE` option): `-Wall -W -Werror` with GCC and Clang, and `/W4 /WX` with MSVC. A warning that only one compiler reports fails CI on that platform. +- Keep code comments short and only where they add something. Public API is documented with Doxygen in the headers, so don't repeat that documentation in the source files. +- New source files start with the Apache licence header used in the existing files. +- Validation follows the normative rules of the CellML 2.0 specification. If an example in the specification disagrees with its rule, follow the rule and point out the difference in the pull request. +- Library sources must not include `debug.h`; the `are_debug_utilities_used` test checks this. +- `Issue::ReferenceRule` in `src/api/libcellml/issue.h` and `ruleToInformation` in `src/issue.cpp` must list the same rules in the same order; the `are_issue_reference_rules_consistent` test checks this. + +## Tests + +- In tests, let the test name say what is covered. Comments citing the specification, or repeating what the test name already says, aren't needed. +- Add tests to the existing file for the area. Prefer that to a new file holding a single test. A new file must be listed in that folder's `tests.cmake`. +- Generator tests go in `tests/generator/generator.cpp` and compare whole generated files, not fragments: `model.h` and `model.c` for the C profile, and `model.py` for the Python profile, using `EXPECT_EQ_FILE_CONTENTS`. The model and its expected files share a folder in `tests/resources/generator/`, for example `tests/resources/generator/cellml_leading_plus_sign/`. +- To create or update expected generator files, uncomment `#define NEW_GENERATOR` in `tests/test_utils.cpp`, run the tests, comment it out again, and review the changed files before committing them. +- If you change the default C or Python generator profile, update the stored SHA-1 values with the utility described in `docs/dev_utilities.rst` (configure with `-DENABLE_UTILITIES=ON`, then build `update_generator_profile_sha1_values`). +- If you add to the public API, update the SWIG interface in `src/bindings/interface/` with a docstring for each new item (`test_docstrings.py` fails on a missing one), the JavaScript bindings in `src/bindings/javascript/`, and the binding tests. +- CI needs 100% branch coverage, so every branch must be reachable from a test. Branches that the tests for an area don't reach naturally are covered in `tests/coverage/coverage.cpp`. Don't add defensive checks that no input can reach. + +## Checks + +CI runs all of these on every pull request. Run what you can locally before pushing, on your own machine, in a Python virtual environment or in a container (see "A local environment" below). + +| Check | Command | Passes when | +| --- | --- | --- | +| Build and unit tests | `cmake -G Ninja -S . -B build`, then `cmake --build build` and `ctest --test-dir build --output-on-failure` | Every test passes on Windows, Linux and macOS, static and shared, with and without the Python bindings | +| Formatting | `cmake --build build --target test_clang_format` (the `format_code` target fixes it) | No file needs reformatting | +| Coverage | `cmake --build build --target llvm_coverage` (Clang and LLVM tools needed) | The `TOTAL` row shows `100.00%` in all four columns: regions, functions, lines and branches | +| Memory | `cmake --build build --target memcheck` (Valgrind needed) | No leaks or memory errors | +| Documentation | `cmake --build build --target docs` (Doxygen and Sphinx needed) | The documentation builds | +| JavaScript | Build with Emscripten (`emcmake cmake ...`), then the `jest_test` target | Every test passes | +| Spelling | codespell, run by CI | No misspellings; genuine false positives go in `.codespellexclude` | + +To find lines or branches that coverage misses, build the `llvm_coverage_report` target for an HTML report. + +## A local environment + +The project doesn't ship a container or a virtual environment set-up, so use whichever suits your machine. An isolated environment keeps the tools for these checks apart from the rest of your system, and an AI coding tool can create one from the notes below. AI tools should prefer such an environment to installing packages system-wide. + +- **Python virtual environment.** For the Python bindings, create and activate the virtual environment before configuring CMake, so the bindings are built for the same Python you test with. Python coverage also needs `pip install -r tests/bindings/python/requirements.txt`. +- **Linux container** (for example Docker with Ubuntu). This matches the Linux CI jobs, and it is the easiest way to run `memcheck` from Windows or macOS, since Valgrind runs on Linux. The checks above need a C++20 compiler, CMake, Ninja, the libxml2 and zlib development files, ClangFormat, Valgrind, and Clang with the LLVM tools `llvm-profdata` and `llvm-cov`. +- **Working from Windows.** Check out with LF line endings (`git config core.autocrlf false`). If the source is mounted into a Linux container from a Windows drive, files can appear there as executable, and `test_clang_format` may then report correctly formatted files. Building from a copy inside the container's own file system avoids this. From 0796d18133d110f634f6d565e4016115d8ff3ef8 Mon Sep 17 00:00:00 2001 From: LunarCapsule127 <287847627+LunarCapsule127@users.noreply.github.com> Date: Wed, 2 Dec 2026 14:41:25 +0000 Subject: [PATCH 2/3] Move the pull request and code rules from AGENTS.md into the docs. --- AGENTS.md | 30 ++---------------------------- docs/coding_standards.rst | 30 ++++++++++++++++++++++++++++++ docs/contributing.rst | 35 ++++++++++++++++++++++++----------- 3 files changed, 56 insertions(+), 39 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 08fecd52d..4025726ab 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -2,7 +2,6 @@ Guidance for anyone contributing to libCellML, whether a person or an AI coding tool. It points to the project's documentation for what is already written down, and spells out the rules that are followed in practice but not documented yet. -Some pages in `docs/` were written before the project moved to GitHub Actions and the `main` branch; where they differ from this file, this file describes how the project works today. ## Where things are written down @@ -12,9 +11,9 @@ Some pages in `docs/` were written before the project moved to GitHub Actions an | Dependency versions | `docs/versions.rst` | | Configuring and building | `docs/configure_and_build.rst`, with the CMake options in `docs/dev_configuration_options.rst` | | Running tests, coverage and formatting checks | `docs/testing.rst` | -| The contribution process: issues, topic branches, test-driven development, pull requests, review feedback | `docs/contributing.rst` | +| The contribution process: issues, topic branches, test-driven development, pull requests, commit messages, review feedback, approvals | `docs/contributing.rst` | | What reviewers check before merging | `docs/review_process.rst` | -| Coding standards: naming, indentation, Doxygen comments, test names | `docs/coding_standards.rst` | +| Coding standards: naming, indentation, spelling, compiler warnings, comments, Doxygen comments, test names, rules checked by the tests | `docs/coding_standards.rst` | | Developer utilities, such as updating the generator profile SHA-1 values | `docs/dev_utilities.rst` | | Code formatting | `.clang-format` | | What CI runs on every pull request | `.github/workflows/ci.yml` and `.github/workflows/spell-check.yml` | @@ -31,31 +30,6 @@ libCellML is a C++20 library for reading, validating, analysing and generating c - `tests/resources/`: CellML models and expected output used by the tests. - `tests/bindings/python/` and `tests/bindings/javascript/`: tests for the bindings. -## Pull requests - -These add to `docs/contributing.rst`, or update it where it is out of date. - -- Pull requests target `main`. Branch from the latest `main` of `cellml/libcellml`; the `develop` branch in the docs no longer exists. -- CI runs on GitHub Actions. The Buildbot mentioned in the docs is no longer used. -- The pull request title becomes its line in the changelog, which is generated from pull request titles at release time. Write the title as a short description of the change. Don't edit `docs/changelogs/` by hand. -- For contributors outside the organisation, GitHub may hold CI runs until a maintainer approves them. -- Pushing new commits dismisses earlier approvals, so reviewers approve again after the last push. -- Maintainers may merge `main` into your branch to keep it up to date. Pull before you push, and don't force-push a branch that is under review. -- When replying to a review comment with a commit SHA, the SHA on its own is enough; reviewers can see what changed. -- Commit messages are short sentences ending with a full stop. Some start with the area they change, for example `Generator: add parentheses around the NOT operand, if needed.` - -## Code - -These add to `docs/coding_standards.rst`. - -- Use British spelling in code, messages and documentation (`analyser`, `behaviour`, `initialise`). -- Warnings are errors by default (the `TWAE` option): `-Wall -W -Werror` with GCC and Clang, and `/W4 /WX` with MSVC. A warning that only one compiler reports fails CI on that platform. -- Keep code comments short and only where they add something. Public API is documented with Doxygen in the headers, so don't repeat that documentation in the source files. -- New source files start with the Apache licence header used in the existing files. -- Validation follows the normative rules of the CellML 2.0 specification. If an example in the specification disagrees with its rule, follow the rule and point out the difference in the pull request. -- Library sources must not include `debug.h`; the `are_debug_utilities_used` test checks this. -- `Issue::ReferenceRule` in `src/api/libcellml/issue.h` and `ruleToInformation` in `src/issue.cpp` must list the same rules in the same order; the `are_issue_reference_rules_consistent` test checks this. - ## Tests - In tests, let the test name say what is covered. Comments citing the specification, or repeating what the test name already says, aren't needed. diff --git a/docs/coding_standards.rst b/docs/coding_standards.rst index fe881d163..7ff60fe3a 100644 --- a/docs/coding_standards.rst +++ b/docs/coding_standards.rst @@ -16,6 +16,24 @@ The following is a list of exceptions/deviations from the Google style guide tha * :wikipedia:`camelCase` class method names. * Indent core code four spaces at a time (no tabs); for CMake files use two space indentation. +Spelling and licence +==================== + + * Use British spelling in code, messages and documentation, for example :code:`analyser`, :code:`behaviour` and :code:`initialise`. + * New source files start with the Apache licence header used in the existing files. + +Compiler warnings +================= + + * Warnings are treated as errors by default (the :code:`TWAE` CMake option): :code:`-Wall -W -Werror` with GCC and Clang, and :code:`/W4 /WX` with MSVC. + A warning that only one compiler reports fails CI on that platform. + +Code comments +============= + + * Keep code comments short and only where they add something. + * Public API is documented with Doxygen in the headers, so don't repeat that documentation in the source files. + Doxygen comments ================ @@ -42,3 +60,15 @@ Weak pointers ============= * The return value of :code:`std::weak_ptr::lock()` should only be tested if it may be equal to :code:`nullptr`. + +Following the CellML specification +================================== + + * Validation follows the normative rules of the CellML 2.0 specification. + If an example in the specification disagrees with its rule, follow the rule and point out the difference in the pull request. + +Rules checked by the tests +========================== + + * Library sources must not include :code:`debug.h`; the :code:`are_debug_utilities_used` test checks this. + * :code:`Issue::ReferenceRule` in :code:`src/api/libcellml/issue.h` and :code:`ruleToInformation` in :code:`src/issue.cpp` must list the same rules in the same order; the :code:`are_issue_reference_rules_consistent` test checks this. diff --git a/docs/contributing.rst b/docs/contributing.rst index 045eaddf7..7006b7528 100644 --- a/docs/contributing.rst +++ b/docs/contributing.rst @@ -16,9 +16,10 @@ The issue can be used to discuss the topic and clarify any problems related to i Once progress has been made towards addressing the issue, a pull request is created that references the issue. Reviewers provide feedback on the changes by adding comments to the pull request or associated commits. -The :buildbot:`Buildbot<>` :code:`build/test` procedure will run each time changes are pushed to the pull request's branch, and the results are displayed in the pull request view. +The continuous integration (CI) checks run on GitHub Actions each time changes are pushed to the pull request's branch, and the results are displayed in the pull request view. +The checks are defined in :code:`.github/workflows/`. -Once all the changes and reviews are complete, one of the :term:`prime repository` owners will merge the pull request into the prime repository, onto the :code:`develop` branch. +Once all the changes and reviews are complete, one of the :term:`prime repository` owners will merge the pull request into the prime repository, onto the :code:`main` branch. Note that a bug is just a type of issue, and that resolving the bug should have both the implementation to fix the bug and a test that triggers the bug. @@ -66,7 +67,7 @@ Topic branches A topic or feature branch is a branch that is local to you (and anyone you collaborate with), it is a branch that will not be available from the :term:`prime repository`. All development work should be carried out on a topic branch, for example any major feature that you work on or minor bug fix. -Before creating a local topic branch, pull the latest changes from the :term:`prime repository` :code:`develop` branch, to make sure that you're working from the most up-to-date version of the code. +Before creating a local topic branch, pull the latest changes from the :term:`prime repository` :code:`main` branch, to make sure that you're working from the most up-to-date version of the code. .. figure:: ./images/libCellMLProcesses-GitBranching.png :align: center @@ -75,13 +76,13 @@ Before creating a local topic branch, pull the latest changes from the :term:`pr How branching in a Git repository works. -Following this process will make it easier to have multiple topic branches at once and keep them in-sync with the :term:`prime repository` :code:`develop` branch, which will in turn make it easier to manage multiple pull requests. +Following this process will make it easier to have multiple topic branches at once and keep them in-sync with the :term:`prime repository` :code:`main` branch, which will in turn make it easier to manage multiple pull requests. The following Git commands show an example of how to create a topic branch for fixing a (hypothetical) bug described in `issue #123`:: - git fetch prime develop - git checkout develop # Not required if already on develop branch - git merge prime/develop + git fetch prime main + git checkout main # Not required if already on main branch + git merge prime/main git checkout -b issue123 @@ -102,10 +103,13 @@ For simple or obvious bugs which have fallen through the testing gaps, simply su GitHub pull requests ==================== Once some changes have been made and local commits committed, push your changes to your Github libCellML repository (refer to :numref:`git_branching`). -From there, create a pull request from your topic branch to the :term:`prime repository` :code:`develop` branch. +From there, create a pull request from your topic branch to the :term:`prime repository` :code:`main` branch. When creating the pull request, make sure to add in the comment :code:`Addresses issue #123` (of course, replace the number 123 with the actual number of the issue you are addressing), or something to that effect. This will create a link between the issue and the pull request enabling other people to see that you are working on this issue and comment on your work. +The title of the pull request becomes its line in the changelog, which is generated from pull request titles at release time. +Write the title as a short description of the change, and don't edit the files in :code:`docs/changelogs/` by hand. + The following Git commands show an example of how to add all files, commit the changes, and push them to a Github repository for the first time:: git add . @@ -116,7 +120,11 @@ The following Git commands show an example of how to add all files, commit the c The :code:`git add` and :code:`git commit` commands should be obvious, the :code:`git push` command sets the local branch :code:`issue123` to be linked with the remote branch :code:`issue123` in the origin (the default shorthand for your libCellML repository on Github) repository. This branch will be created in the origin repository if it does not already exist. +Commit messages are short sentences ending with a full stop. +Some start with the area they change, for example :code:`Generator: add parentheses around the NOT operand, if needed.` + To create a pull request from one Github repository to another, follow the instructions for :github_help:`creating Github pull requests`. +For contributors from outside the organisation, GitHub may hold the CI runs until a repository owner approves them. Reviewing ========= @@ -128,12 +136,17 @@ Satisfying the feedback ======================= It is important to respond to all feedback appropriately, the review process will check to make sure that all comments have been dealt with. Feel free to respond to comments as appropriate, e.g. through code changes, posting a direct reply, etc. -Where you need to change code in response to a comment, be sure to include the commit code (a 7 digit hex number) in your reply, so that others can see where and how the changes were made. +Where you need to change code in response to a comment, be sure to include the commit code (a 7 digit hex number) in your reply, so that others can see where and how the changes were made. +The commit code on its own is enough, as reviewers can see what changed. + +The repository owners may merge :code:`main` into your branch to keep it up to date. +Pull before you push, and don't force-push a branch that is under review. Completing ========== -To complete the process, it is required to have two owners of the :term:`prime repository` comment on the pull request that they are satisfied that the work on the issue is complete and also that the feedback has been addressed, in essence that they are happy to merge the submission. -For small submissions, it is sufficient for the second owner to show satisfaction by performing the merge. +To complete the process, two owners of the :term:`prime repository` need to approve the pull request on GitHub, to show that they are satisfied that the work on the issue is complete and also that the feedback has been addressed, in essence that they are happy to merge the submission. +GitHub requires both approvals before the pull request can be merged. +Pushing new commits dismisses earlier approvals, so the owners approve again after the last push. For larger submissions one of the owners will post a comment on the issue notifying subscribers that they intend to merge the pull request. If no further objections are raised, the pull request will be merged and closed. From 955a255d440963f74b8adafd5e77f2b62d1d3f3d Mon Sep 17 00:00:00 2001 From: LunarCapsule127 <287847627+LunarCapsule127@users.noreply.github.com> Date: Thu, 3 Dec 2026 04:22:54 +0000 Subject: [PATCH 3/3] Move the test rules and the CI checks from AGENTS.md into docs/testing.rst. --- AGENTS.md | 36 +++-------------- docs/testing.rst | 100 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 79 insertions(+), 57 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 4025726ab..e1d3b101c 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,7 +1,7 @@ # AGENTS.md Guidance for anyone contributing to libCellML, whether a person or an AI coding tool. -It points to the project's documentation for what is already written down, and spells out the rules that are followed in practice but not documented yet. +It points to the project's documentation, where the rules and the process are written down, and adds notes on setting up a local environment for the checks. ## Where things are written down @@ -10,7 +10,7 @@ It points to the project's documentation for what is already written down, and s | Setting up a development machine (Git, CMake 3.26 or later, compiler, libxml2, zlib, SWIG) | `docs/setup.rst` | | Dependency versions | `docs/versions.rst` | | Configuring and building | `docs/configure_and_build.rst`, with the CMake options in `docs/dev_configuration_options.rst` | -| Running tests, coverage and formatting checks | `docs/testing.rst` | +| Running the tests and every CI check locally, and the rules for writing tests | `docs/testing.rst` | | The contribution process: issues, topic branches, test-driven development, pull requests, commit messages, review feedback, approvals | `docs/contributing.rst` | | What reviewers check before merging | `docs/review_process.rst` | | Coding standards: naming, indentation, spelling, compiler warnings, comments, Doxygen comments, test names, rules checked by the tests | `docs/coding_standards.rst` | @@ -30,36 +30,10 @@ libCellML is a C++20 library for reading, validating, analysing and generating c - `tests/resources/`: CellML models and expected output used by the tests. - `tests/bindings/python/` and `tests/bindings/javascript/`: tests for the bindings. -## Tests - -- In tests, let the test name say what is covered. Comments citing the specification, or repeating what the test name already says, aren't needed. -- Add tests to the existing file for the area. Prefer that to a new file holding a single test. A new file must be listed in that folder's `tests.cmake`. -- Generator tests go in `tests/generator/generator.cpp` and compare whole generated files, not fragments: `model.h` and `model.c` for the C profile, and `model.py` for the Python profile, using `EXPECT_EQ_FILE_CONTENTS`. The model and its expected files share a folder in `tests/resources/generator/`, for example `tests/resources/generator/cellml_leading_plus_sign/`. -- To create or update expected generator files, uncomment `#define NEW_GENERATOR` in `tests/test_utils.cpp`, run the tests, comment it out again, and review the changed files before committing them. -- If you change the default C or Python generator profile, update the stored SHA-1 values with the utility described in `docs/dev_utilities.rst` (configure with `-DENABLE_UTILITIES=ON`, then build `update_generator_profile_sha1_values`). -- If you add to the public API, update the SWIG interface in `src/bindings/interface/` with a docstring for each new item (`test_docstrings.py` fails on a missing one), the JavaScript bindings in `src/bindings/javascript/`, and the binding tests. -- CI needs 100% branch coverage, so every branch must be reachable from a test. Branches that the tests for an area don't reach naturally are covered in `tests/coverage/coverage.cpp`. Don't add defensive checks that no input can reach. - -## Checks - -CI runs all of these on every pull request. Run what you can locally before pushing, on your own machine, in a Python virtual environment or in a container (see "A local environment" below). - -| Check | Command | Passes when | -| --- | --- | --- | -| Build and unit tests | `cmake -G Ninja -S . -B build`, then `cmake --build build` and `ctest --test-dir build --output-on-failure` | Every test passes on Windows, Linux and macOS, static and shared, with and without the Python bindings | -| Formatting | `cmake --build build --target test_clang_format` (the `format_code` target fixes it) | No file needs reformatting | -| Coverage | `cmake --build build --target llvm_coverage` (Clang and LLVM tools needed) | The `TOTAL` row shows `100.00%` in all four columns: regions, functions, lines and branches | -| Memory | `cmake --build build --target memcheck` (Valgrind needed) | No leaks or memory errors | -| Documentation | `cmake --build build --target docs` (Doxygen and Sphinx needed) | The documentation builds | -| JavaScript | Build with Emscripten (`emcmake cmake ...`), then the `jest_test` target | Every test passes | -| Spelling | codespell, run by CI | No misspellings; genuine false positives go in `.codespellexclude` | - -To find lines or branches that coverage misses, build the `llvm_coverage_report` target for an HTML report. - ## A local environment -The project doesn't ship a container or a virtual environment set-up, so use whichever suits your machine. An isolated environment keeps the tools for these checks apart from the rest of your system, and an AI coding tool can create one from the notes below. AI tools should prefer such an environment to installing packages system-wide. +The project doesn't ship a container or a virtual environment set-up, so use whichever suits your machine. An isolated environment keeps the tools for the checks in `docs/testing.rst` apart from the rest of your system, and an AI coding tool can create one from the notes below. AI tools should prefer such an environment to installing packages system-wide. -- **Python virtual environment.** For the Python bindings, create and activate the virtual environment before configuring CMake, so the bindings are built for the same Python you test with. Python coverage also needs `pip install -r tests/bindings/python/requirements.txt`. -- **Linux container** (for example Docker with Ubuntu). This matches the Linux CI jobs, and it is the easiest way to run `memcheck` from Windows or macOS, since Valgrind runs on Linux. The checks above need a C++20 compiler, CMake, Ninja, the libxml2 and zlib development files, ClangFormat, Valgrind, and Clang with the LLVM tools `llvm-profdata` and `llvm-cov`. +- **Python virtual environment.** For the Python bindings, create and activate the virtual environment before configuring CMake, so the bindings are built for the same Python you test with. Install the packages for Python coverage into the same environment. +- **Linux container** (for example Docker with Ubuntu). This matches the Linux CI jobs, and it is the easiest way to run `memcheck` from Windows or macOS, since Valgrind runs on Linux. The checks need a C++20 compiler, CMake, Ninja, the libxml2 and zlib development files, ClangFormat, Valgrind, and Clang with the LLVM tools `llvm-profdata` and `llvm-cov`. - **Working from Windows.** Check out with LF line endings (`git config core.autocrlf false`). If the source is mounted into a Linux container from a Windows drive, files can appear there as executable, and `test_clang_format` may then report correctly formatted files. Building from a copy inside the container's own file system avoids this. diff --git a/docs/testing.rst b/docs/testing.rst index 2d8a875c3..069582bfa 100644 --- a/docs/testing.rst +++ b/docs/testing.rst @@ -7,33 +7,81 @@ Testing libCellML Every pull request against the libCellML prime repository is tested as a matter of course, but there might be times when you'd like to test your own code without making a pull request. There are two ways you can do this. -Using the Buildbot site ------------------------ -:buildbot:`Buildbot<>` has the capacity to build a libCellML compliant repository through the use of a :forcescheduler:`ForceScheduler<>` . -To make use of this facility, you will need to authenticate with the :buildbot:`Buildbot<>` system. -Access granted on request to David Nickerson d.nickerson@auckland.ac.nz. -The :buildbot:`Buildbot<>` system uses MD5 encrypted passwords as created by :htpasswd:`htpasswd<>`. -With your request to David include the output of this command:: +On your fork with GitHub Actions +-------------------------------- +The CI checks are defined in :code:`.github/workflows/ci.yml` and run on GitHub Actions for every pull request against :code:`main`. +The CI workflow can also be started by hand. +On your fork of libCellML, enable GitHub Actions in the :code:`Actions` tab, select the :code:`CI` workflow, and use :code:`Run workflow` on your topic branch. +The spelling check in :code:`.github/workflows/spell-check.yml` only runs on pull requests to the :term:`prime repository`. - htpasswd -n +Manually on your local computer +------------------------------- +Every check that CI runs can also be run from a local build, configured as described in :ref:`Building `. +The commands below use a build directory called :code:`build`, created with :code:`cmake -G Ninja -S . -B build`. +CMake only creates the target for a check when it finds the tools that the check needs, and the check is then enabled by default. +Unit tests +~~~~~~~~~~ +Build with :code:`cmake --build build`, then run all the tests with :code:`ctest --test-dir build --output-on-failure`. +In CI, every test must pass on Windows, Linux and macOS, with static and shared builds, and with and without the Python bindings. -The website http://www.htaccesstools.com/htpasswd-generator/ can be used if you do not have access to the htpasswd application. -When your request has been dealt with, you will be able to login to :libcellml_buildbot:`libCellML Buildbot<>` and submit code for testing. +The C++ tests listed in each :code:`tests.cmake` file are built into an executable named after the test, for example :code:`test_parser` for :code:`tests/parser/`, which can also be run on its own. +The Python tests are registered with CTest under names starting with :code:`python_`, so :code:`ctest --test-dir build -R python_` runs only those. -Manually on your local computer -------------------------------- -When your libCellML has built successfully, and with tests included, executables for the tests will be located in the :code:`build/test` directory where your library has been built. - -- **Unit tests** Run all of the unit tests using :code:`make test`. - - Individual C++ unit tests may be run by locating the test executable within the :code:`tests/`, directory. - Unit tests for a given class are named :code:`test_classname`, where :code:`classname` is the lowercase name of the class to test. - These files are executable, so can be run from the command line :code:`tests/test_classname`. - - To run individual Python tests, navigate first into the :code:`tests/bindings/python/` directory. - The test files can then be run individually as needed using :code:`python test_classname.py`, where :code:`classname` is the lowercase name of the class to test. -- **Coverage tests** Coverage tests make sure that each line of code is covered by one or more unit tests. - - A summary of coverage of the C++ code is accessible through :code:`make llvm_coverage`, which result in statistics of line coverage. - - For detailed information regarding specific lines in each file that need test coverage, use the command **TODO**. -- **Formatting tests** Check that the code is correctly formatted using the :code:`make test_clang_format`, if you have CLang installed. - **TODO** Check what other OS use? -- **Memory tests** TODO +Formatting +~~~~~~~~~~ +:code:`cmake --build build --target test_clang_format` checks that every source file is formatted as :code:`.clang-format` describes. +It needs ClangFormat 11 or later, and Git. +:code:`cmake --build build --target format_code` reformats the files in place. + +Coverage +~~~~~~~~ +:code:`cmake --build build --target llvm_coverage` runs the C++ tests and prints a coverage summary of the library. +It needs Clang and the LLVM tools :code:`llvm-profdata` and :code:`llvm-cov`. +CI requires full coverage: the :code:`TOTAL` row must show :code:`100.00%` in all four columns, for regions, functions, lines and branches. + +:code:`cmake --build build --target llvm_coverage_report` writes an HTML report that shows the lines and branches no test reaches, and prints where the report is. + +The :code:`python_coverage` and :code:`python_coverage_report` targets do the same for the Python bindings. +They need the packages in :code:`tests/bindings/python/requirements.txt`, and CI doesn't run them. + +Memory +~~~~~~ +:code:`cmake --build build --target memcheck` runs each C++ test executable under Valgrind. +It needs Valgrind and Python. +CI requires no leaks or memory errors. + +Documentation +~~~~~~~~~~~~~ +:code:`cmake --build build --target docs` builds this documentation with Sphinx and the API documentation with Doxygen. +CI requires the documentation to build. + +JavaScript bindings +~~~~~~~~~~~~~~~~~~~ +The JavaScript bindings need a separate build with Emscripten, with libxml2 and zlib built for WebAssembly, as described in :doc:`Building libCellML for use in the Browser `. +With that build in :code:`build-wasm`, :code:`cmake --build build-wasm --target jest_test` runs the tests, which needs npm. +The :code:`JavaScript` job in :code:`.github/workflows/ci.yml` shows the configure options CI uses. + +Spelling +~~~~~~~~ +CI checks the spelling with codespell. +To run it locally, install codespell and use the files to skip and the exclude file listed in :code:`.github/workflows/spell-check.yml`. +Genuine false positives go in :code:`.codespellexclude`. + +Writing tests +------------- + +- Let the test name say what is covered, following the test naming rules in :ref:`Coding standards `. + Comments citing the specification, or repeating what the test name already says, aren't needed. +- Add tests to the existing file for the area, rather than a new file holding a single test. + A new file must be listed in that folder's :code:`tests.cmake`. +- Generator tests go in :code:`tests/generator/generator.cpp` and compare whole generated files, not fragments: :code:`model.h` and :code:`model.c` for the C profile, and :code:`model.py` for the Python profile, using :code:`EXPECT_EQ_FILE_CONTENTS`. + The model and its expected files share a folder in :code:`tests/resources/generator/`, for example :code:`tests/resources/generator/cellml_leading_plus_sign/`. +- To create or update the expected generator files, uncomment :code:`#define NEW_GENERATOR` in :code:`tests/test_utils.cpp`, run the tests, comment it out again, and review the changed files before committing them. +- If you change the default C or Python generator profile, update the stored SHA-1 values with the utility described in :doc:`Developer utilities `. + Configure with :code:`-DENABLE_UTILITIES=ON`, then build the :code:`update_generator_profile_sha1_values` target. +- If you add to the public API, update the SWIG interface in :code:`src/bindings/interface/` with a docstring for each new item, the JavaScript bindings in :code:`src/bindings/javascript/`, and the binding tests. + :code:`test_docstrings.py` fails if a docstring is missing. +- Every branch must be reachable from a test, since CI needs full coverage. + Branches that the tests for an area don't reach naturally are covered in :code:`tests/coverage/coverage.cpp`. + Don't add defensive checks that no input can reach.