Skip to content

Commit 61a31bc

Browse files
committed
Auto merge of #9236 - kornelski:track-assert, r=Eh2406
track_caller on custom assert functions This makes test helper functions point to the failing test, rather than internals of a function that did some checking.
2 parents e4aebf0 + 3f7f094 commit 61a31bc

File tree

8 files changed

+13
-0
lines changed

8 files changed

+13
-0
lines changed

crates/cargo-test-support/src/install.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ use std::path::{Path, PathBuf};
66
/// has been installed. Example usage:
77
///
88
/// assert_has_installed_exe(cargo_home(), "foo");
9+
#[track_caller]
910
pub fn assert_has_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
1011
assert!(check_has_installed_exe(path, name));
1112
}
1213

14+
#[track_caller]
1315
pub fn assert_has_not_installed_exe<P: AsRef<Path>>(path: P, name: &'static str) {
1416
assert!(!check_has_installed_exe(path, name));
1517
}

crates/cargo-test-support/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,7 @@ impl Execs {
732732
self
733733
}
734734

735+
#[track_caller]
735736
pub fn run(&mut self) {
736737
self.ran = true;
737738
let p = (&self.process_builder).clone().unwrap();
@@ -740,6 +741,7 @@ impl Execs {
740741
}
741742
}
742743

744+
#[track_caller]
743745
pub fn run_output(&mut self, output: &Output) {
744746
self.ran = true;
745747
if let Err(e) = self.match_output(output) {

crates/resolver-tests/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,12 +969,14 @@ fn meta_test_multiple_versions_strategy() {
969969
}
970970

971971
/// Assert `xs` contains `elems`
972+
#[track_caller]
972973
pub fn assert_contains<A: PartialEq>(xs: &[A], elems: &[A]) {
973974
for elem in elems {
974975
assert!(xs.contains(elem));
975976
}
976977
}
977978

979+
#[track_caller]
978980
pub fn assert_same<A: PartialEq>(a: &[A], b: &[A]) {
979981
assert_eq!(a.len(), b.len());
980982
assert_contains(b, a);

tests/testsuite/bad_manifest_path.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use cargo_test_support::{basic_bin_manifest, main_file, project};
44

5+
#[track_caller]
56
fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) {
67
let p = project()
78
.file("Cargo.toml", &basic_bin_manifest("foo"))
@@ -20,6 +21,7 @@ fn assert_not_a_cargo_toml(command: &str, manifest_path_argument: &str) {
2021
.run();
2122
}
2223

24+
#[track_caller]
2325
fn assert_cargo_toml_doesnt_exist(command: &str, manifest_path_argument: &str) {
2426
let p = project().build();
2527
let expected_path = manifest_path_argument

tests/testsuite/clean.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ fn package_cleans_all_the_things() {
409409
}
410410

411411
// Ensures that all files for the package have been deleted.
412+
#[track_caller]
412413
fn assert_all_clean(build_dir: &Path) {
413414
let walker = walkdir::WalkDir::new(build_dir).into_iter();
414415
for entry in walker.filter_entry(|e| {

tests/testsuite/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ fn symlink_config_to_config_toml() {
189189
t!(symlink_file(&toml_path, &symlink_path));
190190
}
191191

192+
#[track_caller]
192193
pub fn assert_error<E: Borrow<anyhow::Error>>(error: E, msgs: &str) {
193194
let causes = error
194195
.borrow()
@@ -206,6 +207,7 @@ pub fn assert_error<E: Borrow<anyhow::Error>>(error: E, msgs: &str) {
206207
assert_match(msgs, &causes);
207208
}
208209

210+
#[track_caller]
209211
pub fn assert_match(expected: &str, actual: &str) {
210212
if !normalized_lines_match(expected, actual, None) {
211213
panic!(

tests/testsuite/dep_info.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::path::Path;
1313
use std::str;
1414

1515
// Helper for testing dep-info files in the fingerprint dir.
16+
#[track_caller]
1617
fn assert_deps(project: &Project, fingerprint: &str, test_cb: impl Fn(&Path, &[(u8, &str)])) {
1718
let mut files = project
1819
.glob(fingerprint)

tests/testsuite/lockfile_compat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ fn oldest_lockfile_still_works() {
1212
}
1313
}
1414

15+
#[track_caller]
1516
fn assert_lockfiles_eq(expected: &str, actual: &str) {
1617
for (l, r) in expected.lines().zip(actual.lines()) {
1718
assert!(lines_match(l, r), "Lines differ:\n{}\n\n{}", l, r);

0 commit comments

Comments
 (0)