Skip to content

Commit 0a198ee

Browse files
authored
Add cargo-make with the ability to run code coverage locally (projectfluent#291)
This adds cargo-make as a dependency for the project, and allows for running commands locally from a central location.
1 parent 64191a3 commit 0a198ee

File tree

5 files changed

+148
-7
lines changed

5 files changed

+148
-7
lines changed

.github/workflows/test.yaml

+19-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,25 @@ jobs:
5252
RUSTFLAGS: '-Zinstrument-coverage'
5353
- name: Run grcov
5454
if: matrix.rust-version == 'nightly' && matrix.cargo-args == '--all-features'
55-
run: grcov . --binary-path target/debug/deps/ -s . -t lcov --branch --ignore-not-existing --ignore '../**' --ignore '/*' -o coverage.lcov
55+
# Important! Keep in grcov flags in sync with Makefile.internal.toml.
56+
run: >
57+
grcov .
58+
--binary-path target/debug/deps/
59+
--source-dir .
60+
--branch
61+
--ignore-not-existing
62+
--ignore '../**'
63+
--ignore '/*'
64+
--ignore 'fluent-testing/*'
65+
--ignore 'fluent-syntax/src/bin/*'
66+
--output-type 'lcov'
67+
--output-path 'coverage.lcov'
68+
--excl-start '^#\[cfg\(test\)\]|^// coverage\(off\)'
69+
--excl-br-start '^#\[cfg\(test\)\]|^// coverage\(off\)'
70+
--excl-stop '^// coverage\(on\)'
71+
--excl-br-stop '^// coverage\(on\)'
72+
--excl-line '\#\[derive\(|// cov\(skip\)'
73+
--excl-br-line '\#\[derive\(|// cov\(skip\)'
5674
- name: Coveralls upload
5775
if: matrix.rust-version == 'nightly' && matrix.cargo-args == '--all-features'
5876
uses: coverallsapp/github-action@master

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
**/*.rs.bk
44
Cargo.lock
55
.DS_Store
6+
coverage

Makefile.internal.toml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
[tasks.clean]
2+
command = "cargo"
3+
args = ["clean"]
4+
workspace = false
5+
6+
[tasks.install-grcov]
7+
command = "cargo"
8+
args = ["install", "grcov"]
9+
workspace = false
10+
11+
[tasks.install-llvm]
12+
command = "rustup"
13+
args = ["component", "add", "llvm-tools-preview"]
14+
workspace = false
15+
16+
# This actually runs the tests and generates the .profraw file.
17+
[tasks.coverage-run-tests]
18+
workspace = false
19+
command = "cargo"
20+
args = ["test", "--all-features"]
21+
# toolchain = "nightly"
22+
env = { RUSTFLAGS = "-Cinstrument-coverage", RUSTDOCFLAGS = "-Cinstrument-coverage", LLVM_PROFILE_FILE = "llvm_profile-%p-%m.profraw" }
23+
24+
# After generating the .profraw, this step creates the html report.
25+
# Important! Keep in grcov flags in sync with Makefile.internal.toml.
26+
[tasks.coverage-run-grcov]
27+
workspace = false
28+
command = "grcov"
29+
args = [
30+
".",
31+
"--binary-path", "target/debug/deps/",
32+
"--source-dir", ".",
33+
"--branch", # Enables parsing branch coverage information
34+
"--ignore-not-existing",
35+
"--ignore", "fluent-testing/*", # Test-only fixtures.
36+
"--ignore", "fluent-syntax/src/bin/*", # Small binary utility that doesn't require testing.
37+
"--output-type", "html",
38+
"--output-path", "coverage",
39+
"--excl-start", "^#\\[cfg\\(test\\)\\]|^// coverage\\(off\\)",
40+
"--excl-br-start", "^#\\[cfg\\(test\\)\\]|^// coverage\\(off\\)",
41+
"--excl-stop", "^// coverage\\(on\\)",
42+
"--excl-br-stop", "^// coverage\\(on\\)",
43+
"--excl-line", "\\#\\[derive\\(|// cov\\(skip\\)",
44+
"--excl-br-line", "\\#\\[derive\\(|// cov\\(skip\\)",
45+
]
46+
env = { LLVM_PROFILE_FILE = "llvm_profile-%p-%m.profraw" }
47+
48+
# Cleans up all of the .profraw files left over after running -C instrument-coverage
49+
[tasks.coverage-clean-profraw]
50+
workspace = false
51+
command = "find"
52+
args = [
53+
".",
54+
"-name", "*.profraw",
55+
"-maxdepth", "2",
56+
"-delete"
57+
]
58+
59+
# Notify the user the report is ready.
60+
[tasks.coverage-notify-completed]
61+
workspace = false
62+
command = "echo"
63+
args = ["\nThe coverage report is ready:\n./coverage\n"]

Makefile.toml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file includes all of the documented and runnable commands.
2+
# See the Makefile.internal.toml for the internal implementation details of the commands.
3+
4+
# Command implementation details:
5+
extend = "./Makefile.internal.toml"
6+
7+
[env]
8+
CARGO_MAKE_EXTEND_WORKSPACE_MAKEFILE = true
9+
10+
# Run all of the tests in all of the packages.
11+
[tasks.test]
12+
command = "cargo"
13+
args = ["test", "--all-features"]
14+
15+
# Installs any tools needed for running commands, like for code coverage.
16+
[tasks.install-tools]
17+
workspace = false
18+
dependencies = [
19+
"install-grcov",
20+
"install-llvm"
21+
]
22+
23+
# Create a local test coverage report that outputs as html to ./coverage
24+
# You may need to run `cargo make install-tools` first and make sure that
25+
# the llvm tools are on your path.
26+
[tasks.coverage]
27+
workspace = false
28+
dependencies = [
29+
"clean",
30+
"coverage-run-tests",
31+
"coverage-run-grcov",
32+
"coverage-clean-profraw",
33+
"coverage-notify-completed"
34+
]

README.md

+31-6
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,53 @@
22

33
`fluent-rs` is a collection of Rust crates implementing [Project Fluent](https://projectfluent.org).
44

5+
## Packages
6+
57
The crates perform the following functions:
68

7-
## fluent [![crates.io](https://img.shields.io/crates/v/fluent.svg)](https://crates.io/crates/fluent)
9+
### fluent [![crates.io](https://img.shields.io/crates/v/fluent.svg)](https://crates.io/crates/fluent)
810

911
Umbrella crate combining crates that are ready to be used in production.
1012

11-
## fluent-syntax [![crates.io](https://img.shields.io/crates/v/fluent_syntax.svg)](https://crates.io/crates/fluent_syntax)
13+
### fluent-syntax [![crates.io](https://img.shields.io/crates/v/fluent_syntax.svg)](https://crates.io/crates/fluent_syntax)
1214

1315
Low level Fluent Syntax AST and parser API.
1416

15-
## fluent-bundle [![crates.io](https://img.shields.io/crates/v/fluent_bundle.svg)](https://crates.io/crates/fluent_bundle)
17+
### fluent-bundle [![crates.io](https://img.shields.io/crates/v/fluent_bundle.svg)](https://crates.io/crates/fluent_bundle)
1618

1719
Implementation of the low-level Fluent Localization System providing localization capabilities for any Rust project.
1820

19-
## fluent-fallback [![crates.io](https://img.shields.io/crates/v/fluent_fallback.svg)](https://crates.io/crates/fluent_fallback)
21+
### fluent-fallback [![crates.io](https://img.shields.io/crates/v/fluent_fallback.svg)](https://crates.io/crates/fluent_fallback)
2022

2123
Implementation of the high-level Fluent Localization System providing localization capabilities for any Rust project.
2224

23-
## fluent-resmgr [![crates.io](https://img.shields.io/crates/v/fluent_resmgr.svg)](https://crates.io/crates/fluent_resmgr)
25+
### fluent-resmgr [![crates.io](https://img.shields.io/crates/v/fluent_resmgr.svg)](https://crates.io/crates/fluent_resmgr)
2426

2527
Resource Manager for localization resources.
2628

27-
## fluent-cli
29+
### fluent-cli
2830

2931
Collection of command line tools for Fluent.
32+
33+
## Running the project
34+
35+
Each `fluent-*` directory works with the typical `cargo` commands. In addition there are some general `cargo-make` commands that can be run. First install `cargo-make` via `cargo install --force cargo-make`. The commands are documented in [Makefile.toml](Makefile.toml).
36+
37+
### Tests
38+
39+
To run all of the tests for the repo run:
40+
41+
```sh
42+
cargo make test
43+
```
44+
45+
For local code coverage reports run:
46+
47+
```sh
48+
# Install the tools first if you haven't done so. The llvm tools must be available
49+
# on the path for this to work correctly.
50+
cargo make install-tools
51+
52+
# Then coverage can be run like so:
53+
cargo make coverage
54+
```

0 commit comments

Comments
 (0)