-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cargo-make with the ability to run code coverage locally (#291)
This adds cargo-make as a dependency for the project, and allows for running commands locally from a central location.
- Loading branch information
Showing
5 changed files
with
148 additions
and
7 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 |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
**/*.rs.bk | ||
Cargo.lock | ||
.DS_Store | ||
coverage |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
[tasks.clean] | ||
command = "cargo" | ||
args = ["clean"] | ||
workspace = false | ||
|
||
[tasks.install-grcov] | ||
command = "cargo" | ||
args = ["install", "grcov"] | ||
workspace = false | ||
|
||
[tasks.install-llvm] | ||
command = "rustup" | ||
args = ["component", "add", "llvm-tools-preview"] | ||
workspace = false | ||
|
||
# This actually runs the tests and generates the .profraw file. | ||
[tasks.coverage-run-tests] | ||
workspace = false | ||
command = "cargo" | ||
args = ["test", "--all-features"] | ||
# toolchain = "nightly" | ||
env = { RUSTFLAGS = "-Cinstrument-coverage", RUSTDOCFLAGS = "-Cinstrument-coverage", LLVM_PROFILE_FILE = "llvm_profile-%p-%m.profraw" } | ||
|
||
# After generating the .profraw, this step creates the html report. | ||
# Important! Keep in grcov flags in sync with Makefile.internal.toml. | ||
[tasks.coverage-run-grcov] | ||
workspace = false | ||
command = "grcov" | ||
args = [ | ||
".", | ||
"--binary-path", "target/debug/deps/", | ||
"--source-dir", ".", | ||
"--branch", # Enables parsing branch coverage information | ||
"--ignore-not-existing", | ||
"--ignore", "fluent-testing/*", # Test-only fixtures. | ||
"--ignore", "fluent-syntax/src/bin/*", # Small binary utility that doesn't require testing. | ||
"--output-type", "html", | ||
"--output-path", "coverage", | ||
"--excl-start", "^#\\[cfg\\(test\\)\\]|^// coverage\\(off\\)", | ||
"--excl-br-start", "^#\\[cfg\\(test\\)\\]|^// coverage\\(off\\)", | ||
"--excl-stop", "^// coverage\\(on\\)", | ||
"--excl-br-stop", "^// coverage\\(on\\)", | ||
"--excl-line", "\\#\\[derive\\(|// cov\\(skip\\)", | ||
"--excl-br-line", "\\#\\[derive\\(|// cov\\(skip\\)", | ||
] | ||
env = { LLVM_PROFILE_FILE = "llvm_profile-%p-%m.profraw" } | ||
|
||
# Cleans up all of the .profraw files left over after running -C instrument-coverage | ||
[tasks.coverage-clean-profraw] | ||
workspace = false | ||
command = "find" | ||
args = [ | ||
".", | ||
"-name", "*.profraw", | ||
"-maxdepth", "2", | ||
"-delete" | ||
] | ||
|
||
# Notify the user the report is ready. | ||
[tasks.coverage-notify-completed] | ||
workspace = false | ||
command = "echo" | ||
args = ["\nThe coverage report is ready:\n./coverage\n"] |
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This file includes all of the documented and runnable commands. | ||
# See the Makefile.internal.toml for the internal implementation details of the commands. | ||
|
||
# Command implementation details: | ||
extend = "./Makefile.internal.toml" | ||
|
||
[env] | ||
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true | ||
|
||
# Run all of the tests in all of the packages. | ||
[tasks.test] | ||
command = "cargo" | ||
args = ["test", "--all-features"] | ||
|
||
# Installs any tools needed for running commands, like for code coverage. | ||
[tasks.install-tools] | ||
workspace = false | ||
dependencies = [ | ||
"install-grcov", | ||
"install-llvm" | ||
] | ||
|
||
# Create a local test coverage report that outputs as html to ./coverage | ||
# You may need to run `cargo make install-tools` first and make sure that | ||
# the llvm tools are on your path. | ||
[tasks.coverage] | ||
workspace = false | ||
dependencies = [ | ||
"clean", | ||
"coverage-run-tests", | ||
"coverage-run-grcov", | ||
"coverage-clean-profraw", | ||
"coverage-notify-completed" | ||
] |
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