Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it more clear which module is being tested when running cargo test #9195

Merged
merged 2 commits into from
Feb 24, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/cargo/ops/cargo_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::ffi::OsString;

use crate::core::compiler::{Compilation, CompileKind, Doctest, UnitOutput};
use crate::core::shell::Verbosity;
use crate::core::Workspace;
use crate::core::{TargetKind, Workspace};
use crate::ops;
use crate::util::errors::CargoResult;
use crate::util::{CargoTestError, Config, ProcessError, Test};
Expand Down Expand Up @@ -85,7 +85,24 @@ fn run_unit_tests(
} in compilation.tests.iter()
{
let test = unit.target.name().to_string();
let exe_display = path.strip_prefix(cwd).unwrap_or(path).display();

let test_path = unit.target.src_path().path().unwrap();
let exe_display = if let TargetKind::Test = unit.target.kind() {
format!(
"{} ({})",
test_path
.strip_prefix(unit.pkg.root())
.unwrap_or(&test_path)
.display(),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this returns an opaque struct that implements Display, which I think makes it harder to collapse these 2 format!'s into 1 unless I to_string() this call and the "unittests" &has str, let me know what people would prefer

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah this seems fine I think, no need to worry too much about perf here!

path.strip_prefix(cwd).unwrap_or(path).display()
)
} else {
format!(
"unittests ({})",
path.strip_prefix(cwd).unwrap_or(path).display()
)
};

let mut cmd = compilation.target_process(path, unit.kind, &unit.pkg, *script_meta)?;
cmd.args(test_args);
if unit.target.harness() && config.shell().verbosity() == Verbosity::Quiet {
Expand Down