Skip to content

Commit b5372ef

Browse files
committed
apply PR feedback
1 parent d2d68e5 commit b5372ef

1 file changed

Lines changed: 18 additions & 20 deletions

File tree

tools/src/junit_file_attributes.rs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ use std::fs;
1515
use std::io::Cursor;
1616
use std::path::{Path, PathBuf};
1717

18+
/// Package name used for nextest setup scripts in the target lookup.
19+
/// Nextest uses classnames like "@setup-script:script-name" for setup scripts.
20+
const SETUP_SCRIPT_PACKAGE: &str = "@setup-script";
21+
/// Prefix for setup script classnames (includes the colon separator).
22+
const SETUP_SCRIPT_PREFIX: &str = "@setup-script:";
23+
1824
/// Lookup table for resolving test classnames to source files.
1925
///
2026
/// Uses a primary map keyed by `(package_name, target_name)` for all targets.
@@ -61,27 +67,20 @@ impl TargetLookup {
6167
self.targets.insert((package_name, target_name), src_path);
6268
}
6369

64-
/// Insert a test target (integration test).
65-
pub fn insert_test(&mut self, package_name: &str, target_name: &str, src_path: PathBuf) {
66-
let package_name = Self::normalize(package_name);
67-
let target_name = Self::normalize(target_name);
68-
self.targets.insert((package_name, target_name), src_path);
69-
}
70-
71-
/// Insert a binary target.
72-
pub fn insert_bin(&mut self, package_name: &str, target_name: &str, src_path: PathBuf) {
70+
/// Insert a target (integration test or binary).
71+
pub fn insert_target(&mut self, package_name: &str, target_name: &str, src_path: PathBuf) {
7372
let package_name = Self::normalize(package_name);
7473
let target_name = Self::normalize(target_name);
7574
self.targets.insert((package_name, target_name), src_path);
7675
}
7776

7877
/// Insert a setup script entry.
79-
/// Uses "@setup-script" as the package name so it can be looked up from
78+
/// Uses `SETUP_SCRIPT_PACKAGE` as the package name so it can be looked up from
8079
/// classnames like "@setup-script:prebuild-bin-tests".
8180
fn insert_setup_script(&mut self, script_name: &str, src_path: PathBuf) {
8281
// Don't normalize - script names can have hyphens and we want exact match
8382
self.targets.insert(
84-
("@setup-script".to_string(), script_name.to_string()),
83+
(SETUP_SCRIPT_PACKAGE.to_string(), script_name.to_string()),
8584
src_path,
8685
);
8786
}
@@ -92,9 +91,8 @@ impl TargetLookup {
9291
/// - If `target_name` is `None`, tries `(package, package)` first, then checks the alias map
9392
/// for packages where lib name differs from package name
9493
pub fn get(&self, package_name: &str, target_name: Option<&str>) -> Option<&PathBuf> {
95-
// Setup scripts are a bit of a special case. They use "@setup-script" as package name and
96-
// shouldn't be normalized
97-
if package_name == "@setup-script" {
94+
// Setup scripts use SETUP_SCRIPT_PACKAGE as package name and shouldn't be normalized
95+
if package_name == SETUP_SCRIPT_PACKAGE {
9896
let target_name = target_name?;
9997
return self
10098
.targets
@@ -153,10 +151,10 @@ pub fn build_target_lookup(manifest_path: Option<&Path>) -> Result<(TargetLookup
153151
lookup.insert_lib(&package.name, &target.name, src_path);
154152
}
155153
"test" => {
156-
lookup.insert_test(&package.name, &target.name, src_path);
154+
lookup.insert_target(&package.name, &target.name, src_path);
157155
}
158156
"bin" => {
159-
lookup.insert_bin(&package.name, &target.name, src_path);
157+
lookup.insert_target(&package.name, &target.name, src_path);
160158
}
161159
_ => {}
162160
}
@@ -331,7 +329,7 @@ fn resolve_setup_script_path(
331329
targets: &TargetLookup,
332330
workspace_root: &Path,
333331
) -> Option<String> {
334-
let src_path = targets.get("@setup-script", Some(script_name))?;
332+
let src_path = targets.get(SETUP_SCRIPT_PACKAGE, Some(script_name))?;
335333
Some(to_relative_path(src_path, workspace_root))
336334
}
337335

@@ -365,7 +363,7 @@ fn resolve_file_path(
365363
let classname = classname?;
366364

367365
// Handle setup scripts: classname is "@setup-script:script_name"
368-
if let Some(script_name) = classname.strip_prefix("@setup-script:") {
366+
if let Some(script_name) = classname.strip_prefix(SETUP_SCRIPT_PREFIX) {
369367
return resolve_setup_script_path(script_name, targets, workspace_root);
370368
}
371369

@@ -455,7 +453,7 @@ mod tests {
455453
#[test]
456454
fn test_target_lookup_test_target() {
457455
let mut lookup = TargetLookup::new();
458-
lookup.insert_test(
456+
lookup.insert_target(
459457
"libdd-trace-utils",
460458
"test_send_data",
461459
PathBuf::from("/tests/test_send_data.rs"),
@@ -491,7 +489,7 @@ mod tests {
491489
#[test]
492490
fn test_process_junit_xml_integration_test() {
493491
let mut lookup = TargetLookup::new();
494-
lookup.insert_test(
492+
lookup.insert_target(
495493
"my-crate",
496494
"integration_test",
497495
PathBuf::from("/workspace/my-crate/tests/integration_test.rs"),

0 commit comments

Comments
 (0)