Skip to content

Commit 6eaec91

Browse files
committed
[cargo-nextest] fix test runs from within a crate
1 parent 11a1abc commit 6eaec91

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-nextest/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "cargo-nextest"
33
description = "A next-generation test runner for Rust."
4-
version = "0.9.1"
4+
version = "0.9.2"
55
readme = "README.md"
66
license = "Apache-2.0 OR MIT"
77
repository = "https://github.com/nextest-rs/nextest"

cargo-nextest/src/dispatch.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,15 @@ struct TestBuildFilter {
177177
}
178178

179179
impl TestBuildFilter {
180-
fn compute<'g>(&self, graph: &'g PackageGraph, output: OutputContext) -> Result<TestList<'g>> {
181-
let manifest_path = graph.workspace().root().join("Cargo.toml");
182-
let mut cargo_cli = CargoCli::new("test", Some(&manifest_path), output);
180+
fn compute<'g>(
181+
&self,
182+
manifest_path: Option<&'g Utf8Path>,
183+
graph: &'g PackageGraph,
184+
output: OutputContext,
185+
) -> Result<TestList<'g>> {
186+
// Don't use the manifest path from the graph to ensure that if the user cd's into a
187+
// particular crate and runs cargo nextest, then it behaves identically to cargo test.
188+
let mut cargo_cli = CargoCli::new("test", manifest_path, output);
183189

184190
// Only build tests in the cargo test invocation, do not run them.
185191
cargo_cli.add_args(["--no-run", "--message-format", "json-render-diagnostics"]);
@@ -309,7 +315,8 @@ impl AppImpl {
309315
build_filter,
310316
message_format,
311317
} => {
312-
let mut test_list = build_filter.compute(&graph, output)?;
318+
let mut test_list =
319+
build_filter.compute(self.manifest_path.as_deref(), &graph, output)?;
313320
if output.color.should_colorize(Stream::Stdout) {
314321
test_list.colorize();
315322
}
@@ -332,7 +339,8 @@ impl AppImpl {
332339
std::fs::create_dir_all(&store_dir)
333340
.wrap_err_with(|| format!("failed to create store dir '{}'", store_dir))?;
334341

335-
let test_list = build_filter.compute(&graph, output)?;
342+
let test_list =
343+
build_filter.compute(self.manifest_path.as_deref(), &graph, output)?;
336344

337345
let mut reporter = reporter_opts
338346
.to_builder(no_capture)

site/src/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
This page documents new features and bugfixes for cargo-nextest. Please see the [stability
44
policy](book/stability.md) for how versioning works with cargo-nextest.
55

6+
## [0.9.2] - 2022-02-14
7+
8+
### Fixed
9+
10+
- Running cargo nextest from within a crate now runs tests for just that crate, similar to cargo
11+
test. Thanks [Yaron Wittenstein](https://twitter.com/RealWittenstein/status/1493291441384210437)
12+
for reporting this!
13+
614
## [0.9.1] - 2022-02-14
715

816
### Fixed

0 commit comments

Comments
 (0)