Skip to content

Commit ac1b854

Browse files
authored
Merge pull request #1 from python-project-templates/tkp/cov
tweak rust test infra to use nextest and llvm cov to be compatible with stable instead of nightly
2 parents 02f200c + e318deb commit ac1b854

4 files changed

Lines changed: 37 additions & 19 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ publish: dist ## Dist assets to pypi
8282
make -C rust publish
8383

8484
clean: ## Clean the repo
85-
git clean -fdx
85+
git clean -fdx

rust/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@ crate-type = ["rlib"]
1616
[dependencies]
1717
serde = { version = "1.0", features = ["derive"] }
1818
serde_json = "1"
19+
20+
[profile.test.junit]
21+
path = "junit.xml"
22+

rust/Makefile

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
.DEFAULT_GOAL := help
22
.PHONY: dev build lint fix check tests tests-ci develop test format checks help dist publish
33

4-
dev: ## Install required dev dependencies
4+
develop: ## Install required dev dependencies
55
rustup component add rustfmt
66
rustup component add clippy
7-
cargo install cargo2junit
8-
cargo install grcov
7+
cargo install cargo-nextest
8+
cargo install cargo-llvm-cov
99

1010
build: ## Build release
1111
cargo build --release --all-features
@@ -21,17 +21,10 @@ check:
2121
cargo check --all-features
2222

2323
tests: ## Run the tests
24-
cargo test -- --show-output
25-
# cargo test -- -Z unstable-options --format json | cargo2junit > junit.xml
26-
27-
tests-ci: $(eval SHELL:=/bin/bash)
28-
{ \
29-
export CARGO_INCREMENTAL=0;\
30-
export RUSTDOCFLAGS="-Cpanic=abort";\
31-
export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort";\
32-
cargo test -- -Z unstable-options --format json | cargo2junit > junit.xml;\
33-
grcov . --llvm -s . -t cobertura --branch --ignore-not-existing -o ./coverage.xml;\
34-
}
24+
cargo llvm-cov nextest
25+
26+
tests-ci:
27+
cargo llvm-cov --lcov --output-path coverage nextest
3528

3629
dist: ## Create dist
3730
cargo publish --dry-run
@@ -40,7 +33,6 @@ publish: ## Publish to cargo
4033
cargo publish
4134

4235
# aliases
43-
develop: dev
4436
test: tests
4537
format: fix
4638
checks: check

rust/src/lib.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use serde::{Deserialize, Serialize};
2-
3-
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
1+
#[derive(Clone, Debug, Eq, PartialEq)]
42
pub struct Example {
53
pub stuff: String,
64
}
@@ -10,3 +8,27 @@ impl Example {
108
Example { stuff: value }
119
}
1210
}
11+
12+
/**********************************/
13+
#[cfg(test)]
14+
mod example_tests {
15+
use super::*;
16+
17+
#[test]
18+
fn test_new() {
19+
let e = Example::new(String::from("test"));
20+
assert_eq!(e.stuff, String::from("test"));
21+
}
22+
23+
#[test]
24+
fn test_clone_and_eq() {
25+
let e = Example::new(String::from("test"));
26+
assert_eq!(e, e.clone());
27+
}
28+
29+
#[test]
30+
fn test_debug() {
31+
let e = Example::new(String::from("test"));
32+
assert_eq!(format!("{e:?}"), "Example { stuff: \"test\" }");
33+
}
34+
}

0 commit comments

Comments
 (0)