-
-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add --test-workspace and --test-packages (#425)
Allows testing packages that get some test coverage from another package in the workspace Fixes #394
- Loading branch information
Showing
25 changed files
with
1,122 additions
and
521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,49 @@ | ||
# Workspace and package support | ||
|
||
cargo-mutants supports testing Cargo workspaces that contain multiple packages. The entire workspace tree is copied. | ||
cargo-mutants supports testing Cargo workspaces that contain multiple packages. | ||
|
||
By default, cargo-mutants has [the same behavior as Cargo](https://doc.rust-lang.org/cargo/reference/workspaces.html): | ||
The entire workspace tree is copied to the temporary directory (unless `--in-place` is used). | ||
|
||
* If `--workspace` is given, all packages in the workspace are tested. | ||
* If `--package` is given, the named packages are tested. | ||
* If the starting directory (or `-d` directory) is in a package, that package is tested. | ||
* Otherwise, the starting directory must be in a virtual workspace. If it specifies default members, they are tested. Otherwise, all packages are tested. | ||
In workspaces with multiple packages, there are two considerations: | ||
|
||
For each mutant, only the containing package's tests are run, on the theory that | ||
each package's tests are responsible for testing the package's code. | ||
1. Which packages to generate mutants in, and | ||
2. Which tests to run on those mutants. | ||
|
||
The baseline tests exercise all and only the packages for which mutants will | ||
be generated. | ||
## Selecting packages to mutate | ||
|
||
By default, cargo-mutants selects packages to mutate using [similar heuristics to other Cargo commands](https://doc.rust-lang.org/cargo/reference/workspaces.html). | ||
|
||
These rules work from the "starting directory", which is the directory selected by `--dir` or the current working directory. | ||
|
||
* If `--workspace` is given, all packages in the workspace are mutated. | ||
* If `--package` is given, the named packages are mutated. | ||
* If the starting directory is in a package, that package is mutated. Concretely, this means: if the starting directory or its parents contain a `Cargo.toml` containing a `[package]` section. | ||
* If the starting directory's parents contain a `Cargo.toml` with a `[workspace]` section but no `[package]` section, then the directory is said to be in a "virtual workspace". If the `[workspace]` section has a `default-members` key then these packages are mutated. Otherwise, all packages are mutated. | ||
|
||
Selection of packages can be combined with [`--file`](skip_files.md) and other filters. | ||
|
||
You can also use the `--file` options to restrict cargo-mutants to testing only files | ||
from some subdirectory, e.g. with `-f "utils/**/*.rs"`. (Remember to quote globs | ||
on the command line, so that the shell doesn't expand them.) You can use `--list` or | ||
`--list-files` to preview the effect of filters. | ||
|
||
## Selecting tests to run | ||
|
||
For each baseline and mutant scenario, cargo-mutants selects some tests to see if the mutant is caught. | ||
These selections turn into `--package` or `--workspace` arguments to `cargo test`. | ||
|
||
There are different behaviors for the baseline tests (before mutation), which run once for all packages, and then for the tests applied to each mutant. | ||
|
||
These behaviors can be controlled by the `--test-workspace` and `--test-package` command line options and the corresponding configuration options. | ||
|
||
By default, the baseline runs the tests from all and only the packages for which mutants will be generated. That is, if the whole workspace is being tested, then it runs `cargo test --workspace`, and otherwise runs tests for each selected package. | ||
|
||
By default, each mutant runs only the tests from the package that's being mutated. | ||
|
||
If the `--test-workspace=true` argument or `test_workspace` configuration key is set, then all tests from the workspace are run for the baseline and against each mutant. | ||
|
||
If the `--test-package` argument or `test_package` configuration key is set then the specified packages are tested for the baseline and all mutants. | ||
|
||
As for other options, the command line arguments have priority over the configuration file. | ||
|
||
Like `--package`, the argument to `--test-package` can be a comma-separated list, or the option can be repeated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.