{"id":13730875,"url":"https://github.com/nlohmann/mutate_cpp","last_synced_at":"2025-10-08T15:04:01.694Z","repository":{"id":22902149,"uuid":"112001014","full_name":"nlohmann/mutate_cpp","owner":"nlohmann","description":"C++ Mutation Test Environment","archived":false,"fork":false,"pushed_at":"2024-06-30T18:24:14.000Z","size":4746,"stargazers_count":179,"open_issues_count":10,"forks_count":24,"subscribers_count":16,"default_branch":"master","last_synced_at":"2025-04-09T23:24:04.415Z","etag":null,"topics":["c-plus-plus","mutation-testing"],"latest_commit_sha":null,"homepage":"","language":"CSS","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nlohmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"nlohmann","custom":"http://paypal.me/nlohmann"}},"created_at":"2017-11-25T12:13:42.000Z","updated_at":"2025-04-08T09:00:13.000Z","dependencies_parsed_at":"2024-10-25T18:39:04.962Z","dependency_job_id":"40b5e966-9dfd-408e-ae6d-c6de13ff883b","html_url":"https://github.com/nlohmann/mutate_cpp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nlohmann/mutate_cpp","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlohmann%2Fmutate_cpp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlohmann%2Fmutate_cpp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlohmann%2Fmutate_cpp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlohmann%2Fmutate_cpp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nlohmann","download_url":"https://codeload.github.com/nlohmann/mutate_cpp/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nlohmann%2Fmutate_cpp/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278963821,"owners_count":26076544,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-plus-plus","mutation-testing"],"created_at":"2024-08-03T02:01:20.705Z","updated_at":"2025-10-08T15:04:01.645Z","avatar_url":"https://github.com/nlohmann.png","language":"CSS","readme":"# Mutate++ - A C++ Mutation Test Environment\n\n[Mutation testing](https://en.wikipedia.org/wiki/Mutation_testing) is a technique to detect bugs in a program by\nchanging its source code (called \"mutation\") and checking whether the program's test suite detects this mutation. The\nmutations are designed to mimic typical programming errors (e.g., off-by-one errors). If such errors are not noticed\nby the test suite, the \"survived\" mutation can be used to create an additional test that would detect it.\n\n- [Overview](#overview)\n- [Installation](#installation)\n- [Example](#example)\n- [Further features](#further-features)\n- [Command-line tools](#command-line-tools)\n- [Help!](#help)\n- [Used third-party tools](#used-third-party-tools)\n- [License](#license)\n\n\n## Overview\n\nMutate++ is a mutation test environment for C++ programs. It supports you with the following tasks:\n\n- create mutations of the source code\n- execute the test suite for each mutation\n- evaluate the outcome of the tests\n\nMutate++ is a web app that runs locally on your machine. All computation is locally, and no data is shared with anyone.\n\n\n## Installation\n\nYou need Python 3 which can be [downloaded here](https://www.python.org/downloads/) or installed by your operating\nsystems's package manager.\n\nAfter checking out the sources from this repository, you need to create a\n[virtual environment](https://docs.python.org/3/tutorial/venv.html) and install the required packages:\n\n```bash\nvirtualenv -p python3 venv\nvenv/bin/pip install -r requirements.txt\n```\n\nNext, we need to create a database where mutations and the results are stored:\n\n```bash\nvenv/bin/python3 db_create.py\n```\n\nThe database file is an SQLite3 database `app/app.db`. You can then run the app with\n\n```bash\nvenv/bin/python3 run.py\n```\n\nand open it in your browser with the URL \u003chttp://127.0.0.1:5000\u003e.\n\n\n## Example\n\nWe use a small [example project](https://github.com/bast/cmake-example) to demonstrate the required steps to set up a\nproject in Mutate++. We assume that you have git, CMake, make, and a C++ compiler installed.\n\n\n### 1. Prepare the project\n\nMutate++ will run the following (simplified) workflow:\n\n![Workflow](doc/workflow.png)\n\nWe now set up the project so that we can build and test the project ourselves.\n\n```bash\ncd /tmp\ngit clone https://github.com/bast/cmake-example.git\ncd cmake-example\nmkdir build\ncd build\ncmake ..\n```\n\nWe now have two directories we will be referring to later:\n\n- the working directory `/tmp/cmake-example/build`: this is the directory where we will execute the build and test\n  commands\n- the source directory `/tmp/cmake-example/src`: this is the directory with the source code\n\nLet's try building and testing:\n\n```bash\ncd /tmp/cmake-example/build\nmake\nctest\n```\n\nWe see that 100% of the tests passed.\n\nIn the following, we shall refer to these commands as:\n\n- the build command `make`: this is the command that builds the project from source\n- the test command `ctest`: this is the command that executes the test suite\n\n\n### 2. Create project in Mutate++\n\n![Workflow](doc/1_create_project.png)\n\n- Open \u003chttp://127.0.0.1:5000\u003e in your browser.\n- Click on [\"Projects\"](http://127.0.0.1:5000/projects).\n- Click on [\"New Project](http://127.0.0.1:5000/projects/create).\n- Enter `Example project` as project name.\n- Enter `/tmp/cmake-example/build` as working directory.\n- Enter `make` as build command.\n- Leave \"Quickcheck command\" and \"Quickcheck timeout\" empty.\n- Enter `ctest` as test command.\n- Leave `Test timeout` and `Clean command` empty.\n- Click on \"Create project\".\n\n![Workflow](doc/2_create_project_dialog.png)\n\nNote that we assume the build and test command to succeed if they end with exit code `0`. This is the default for most\ntools like CMake, CTest, Ninja, etc.\n\n![Workflow](doc/3_project_overview.png)\n\nWe are now in the [project overview](http://127.0.0.1:5000/projects/1) and see the workflow Mutate++ will execute,\nconsisting of the steps \"build\" and \"test\". We see that no files have been added yet, and also the patches overview is\nempty.\n\n\n### 3. Add a file\n\n![Workflow](doc/4_add_file.png)\n\n- Click on [\"Add file\"](http://127.0.0.1:5000/projects/1/files/add).\n- In the \"Add file to project\" dialog, enter the filename `/tmp/cmake-example/src/example.cpp`.\n- Click \"Add file\".\n\nWe are back in the [project overview](http://127.0.0.1:5000/projects/1), but see `example.cpp` added to the files. When\nwe click on [example.cpp](http://127.0.0.1:5000/projects/1/files/1), we see the source code. Go back to the\n[project overview](http://127.0.0.1:5000/projects/1).\n\n\n### 4. Generate patches\n\n![Workflow](doc/5_generate_patches.png)\n\n- Next to \"example.cpp\", click on [\"generate patches\"](http://127.0.0.1:5000/projects/1/files/1/generate).\n- Leave \"first line\" and \"last line\" empty to mutate the whole file.\n- Right now, none of the check boxes are actually implemented, so you can ignore all of them - all mutations will be\n  used by default.\n- Click on \"Generate patches\".\n\nBack in the [project overview](http://127.0.0.1:5000/projects/1), you see that 14 patches have been generated. You can\ninspect them back clicking on [\"14 patches\"](http://127.0.0.1:5000/projects/1/patches) in the \"Patches\" section. In\nthis overview, you see the individual patches with their line, kind, state and confirmation:\n\n- The kind describes the nature of the patch, e.g. \"lineDeletion\" or \"arithmeticOperator\". If you click on a kind, the\n  list of patches will be filtered accordingly.\n- The state describes whether the patch was analyzed so far; that is, whether the code has been mutated accordingly and\n  the test suite has been executed. So far, all patches are incomplete.\n- The confirmation describes whether you have been evaluated the results so far. All patches are \"unknown\" so far.\n\n![Workflow](doc/6_patch.png)\n\nLet's now click on [\"4\"](http://127.0.0.1:5000/projects/1/patches/4) to have a look at the details of a patch:\n\n- In the top, you see the actual patch: We see that the patch replaces `return f1 + f2;` by `return f1 * f2;`.\n- The description provides a summary of the patch.\n- You could set the confirmation, but this would not make sense as we have not executed the patch so far.\n- Finally, we see that no runs have been executed so far.\n\nGo back to the [project overview](http://127.0.0.1:5000/projects/1).\n\n\n### 5. Execute patches\n\n![Workflow](doc/7_queue.png)\n\nNow it is time to actually apply the patches:\n\n- In the top navigation, click on [\"Queue\"](http://127.0.0.1:5000/queue). We see the 14 patches from before.\n- Click on [\"Resume\"](http://127.0.0.1:5000/queue/start) to start the execution.\n- When you reload the page, you see that after a few seconds, the queue is empty.\n\n![Workflow](doc/8_queue_running.png)\n\nWhat happened? Mutate++ executed the workflow described above for each patch. That is, it applied the patch to the\nsource file `/tmp/cmake-example/src/example.cpp`, executed the build command `make` in the working directory\n`/tmp/cmake-example/build`, and then executed the test command `ctest` in the same directory. As we have a trivial\nproject with just 14 patches, this is just a matter of seconds.\n\nGo back to the [project overview](http://127.0.0.1:5000/projects/1) by clicking on\n[\"Projects\"](http://127.0.0.1:5000/projects) and [\"Example project\"](http://127.0.0.1:5000/projects/1).\n\n\n### 6. Evaluate results\n\n![Workflow](doc/9_patches_overview.png)\n\nThe Patches second got more colorful now. We see a graph that describes the breakdown of the patches:\n\n- 14 patches were generated in total.\n- 13 patches were killed; meaning they have been detected by the test suite or the code did not compile.\n- 13 of these patches were killed due to a failure. There are other reasons a patch could have been killed which we\n  describe later.\n- 1 patch survived, meaning the mutated source code could be compiled and tested without problems.\n\nLet's investigate this by clicking on [\"1 survived\"](http://127.0.0.1:5000/projects/1/patches?patch_state=survived) to\nsee the list of survived patches. We see that patch 14 survived. Click on\n[\"14\"](http://127.0.0.1:5000/projects/1/patches/14).\n\nIn the patch overview, we see what happened:\n\n- The patch deleted line 16 of file `/tmp/cmake-example/src/example.cpp`, resulting in function\n  `multiply_numbers` not returning anything.\n- In the run overview, we see the individual steps of the workflow:\n  - [Run 22](http://127.0.0.1:5000/projects/1/patches/14/runs/22) shows the output of the build command. Maybe some\n    stricter compiler settings could have warned about the mutation, but instead the code was built successfully.\n  - [Run 23](http://127.0.0.1:5000/projects/1/patches/14/runs/23) shows that also the test suite was executed\n    successfully.\n\nWhy is this an issue? Because no one noticed that we deleted the multiplication! The easiest way to fix this is by\nadding a respective test case. In larger projects, we do not want to switch back and forth between evaluating patches\nand fixing the test suite, so we set the patch \"confirm\" and press \"Submit\".\n\nIn some cases, the patch would change the source code in ways that it is natural that the test suite would not\ndetect it, e.g. in parts of the code that are skipped by preprocessor directives (e.g. with `#ifdef` commands) or when,\nthe patch results in equivalent code. In that cases, set the patch to \"ignore\".\n\nLater, you can filter to show only the\n[confirmed](http://127.0.0.1:5000/projects/1/patches?patch_state=survived\u0026confirmation_state=confirmed) patches and\nadjust your test suite accordingly.\n\nIn the [project overview](http://127.0.0.1:5000/projects/1), you also get some statistics on the execution: We see that\n5 patches failed during the build, whereas 9 built successfully. From these 9, 8 failed the tests, and\n[1 patch](http://127.0.0.1:5000/projects/1/patches/14) succeeded.\n\n\n## Further features\n\n- **Timeouts**. Mutating the code can create infinite loops. Therefore, it is wise to set a timeout for the tests in\n  the \"Create Project\" dialog. Tests that take longer than this timeout are treated as if the test failed.\n- **Quickchecks**. A lot of test suites can be split into tests that run very quickly and the full test suite which\n  may take many minutes to execute. In the \"Create Project\" dialog, you can define a \"Quickcheck command\" to execute\n  this quicker test suite first. A lot of patches may be detected quicker this way.\n- **Cleaning up**. Some test suites may required cleaning up afterward. You can provide a \"Clean command\" in the\n  \"Create Project\" dialog. It will be executed after processing each patch. Note that the example project implements\n  a `make clean` command, but adding this as clean command would only increase the build times, because all source\n  files would be re-compiled even if only one was changed.\n- **Hashing binaries**. Optimizing compilers may create exactly the same binary for programs that differ syntactically,\n  but have the same semantics. Therefore, it can be helpful to calculate a hash of the generated binaries and compare\n  it to reference values. If the hashes are the same, then you know the test suite will create the same result. To\n  avoid waiting for such a false positive, Mutate++ can stop the evaluation of such patches if the test command or\n  quickcheck command return exit code `77`.\n\n\n## Command-line tools\n\nMutate++ provides some command-line scripts to facilitate its usage without the web interface.\nThese scripts can be found in the `cli` directory, and should be run from the root directory.\n\n### `create_project.py`\nThis script will create a project and add it to the database.\n\nExample usage:\n```bash\nvenv/bin/python3 cli/create_project.py --name \"Example project\" --workdir \"/tmp/cmake-example/build\" --build-command \"make\" --test-command \"ctest\"\n```\n\n### `add_files.py`\nThis script will add files to an existing project.\n\nExample usage:\n```bash\nvenv/bin/python3 cli/add_files.py --project \"Example project\" /tmp/cmake-example/src/*.cpp\n```\n\n### `generate_patches.py`\nThis script will generate patches for all files in a project.\n\nExample usage:\n```bash\nvenv/bin/python3 cli/generate_patches.py --project \"Example project\"\n```\n\n### `queue_control.py`\nThis script allows you to control the queue and view its state.\n\nExample usage:\n```bash\nvenv/bin/python3 cli/queue_control.py start\n```\n\n## Help!\n\nMutate++ is in a very early stage, and there is a lot to do. In particular, we are aware of severe limitations:\n\n- Mutations are created very naively on a purely syntactical level and often result in code that fails compilation.\n  Using, for instance, LLVM-based tools could help to use more type information to create mutations which are more\n  likely to result in valid C++ programs.\n- The web app has a terrible UX, and should be overworked by someone who knows more about this...\n\nThat said, pull requests and issues are more than welcome!\n\n\n## Used third-party tools\n\nMutate++ contains the following libraries for the frontend:\n\n- [Bootstrap](http://getbootstrap.com) for the frontend components\n- [Font Awesome](http://fontawesome.io) for the icons\n- [highlight.js](https://highlightjs.org) for source code syntax highlighting\n- [jQuery](https://jquery.com) for some custom JavaScript code\n\nThe web app uses [Flask](http://flask.pocoo.org) and [SQLAlchemy](https://www.sqlalchemy.org), and a lot of\n[other packages](requirements.txt).\n\n\n## License\n\n\u003cimg align=\"right\" src=\"http://opensource.org/trademarks/opensource/OSI-Approved-License-100x137.png\"\u003e\n\nMutate++ is licensed under the [MIT License](http://opensource.org/licenses/MIT):\n\nCopyright \u0026copy; 2017 [Niels Lohmann](http://nlohmann.me)\n\nPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\ndocumentation files (the “Software”), to deal in the Software without restriction, including without limitation the\nrights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit\npersons to whom the Software is furnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all copies or substantial portions of the\nSoftware.\n\nTHE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\nWARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\nCOPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\nOTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":["https://github.com/sponsors/nlohmann","http://paypal.me/nlohmann"],"categories":["Mutation Testing","C++"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlohmann%2Fmutate_cpp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnlohmann%2Fmutate_cpp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnlohmann%2Fmutate_cpp/lists"}