Skip to content

Commit 4def3be

Browse files
committed
difftest: fix test names on windows
1 parent f9f7b5d commit 4def3be

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

tests/difftests/bin/src/testcase.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@ pub struct TestCase {
1616
pub test_binaries: Vec<TestBinary>,
1717
}
1818

19+
fn path_to_test_name(path: &Path) -> String {
20+
path.to_string_lossy()
21+
.replace("/", "::")
22+
.replace("\\\\", "::")
23+
}
24+
1925
impl TestCase {
2026
pub fn new_empty(root: &Path, relative_path: &Path) -> Self {
2127
TestCase {
22-
name: format!(
23-
"difftests::{}",
24-
relative_path.to_string_lossy().replace("/", "::")
25-
),
28+
name: format!("difftests::{}", path_to_test_name(relative_path)),
2629
absolute_path: root.join(relative_path),
2730
relative_path: relative_path.to_path_buf(),
2831
test_binaries: Vec::new(),
@@ -47,7 +50,7 @@ impl TestCase {
4750
if path.is_dir() && path.join("Cargo.toml").exists() {
4851
debug!("Found binary package candidate: {}", path.display());
4952
self.test_binaries
50-
.push(TestBinary::new(self, PathBuf::from(entry.file_name())));
53+
.push(TestBinary::new(self, Path::new(&entry.file_name())));
5154
}
5255
}
5356
Ok(())
@@ -71,15 +74,15 @@ pub struct TestBinary {
7174
}
7275

7376
impl TestBinary {
74-
pub fn new(test_case: &TestCase, relative_to_test_case: PathBuf) -> Self {
77+
pub fn new(test_case: &TestCase, relative_to_test_case: &Path) -> Self {
7578
Self {
7679
name: format!(
7780
"{}::{}",
7881
test_case.name,
79-
relative_to_test_case.to_string_lossy().replace("/", "::")
82+
path_to_test_name(relative_to_test_case)
8083
),
81-
relative_path: test_case.relative_path.join(&relative_to_test_case),
82-
absolute_path: test_case.absolute_path.join(&relative_to_test_case),
84+
relative_path: test_case.relative_path.join(relative_to_test_case),
85+
absolute_path: test_case.absolute_path.join(relative_to_test_case),
8386
}
8487
}
8588
}
@@ -128,7 +131,7 @@ mod tests {
128131
TestCase::new_empty(Path::new("/home/user/tests"), Path::new("core/group1"));
129132
test_case
130133
.test_binaries
131-
.push(TestBinary::new(&test_case, PathBuf::from("testcase1")));
134+
.push(TestBinary::new(&test_case, Path::new("testcase1")));
132135
assert_eq!(test_case.to_string(), "difftests::core::group1");
133136
assert_eq!(
134137
test_case.test_binaries[0].to_string(),
@@ -161,13 +164,13 @@ mod tests {
161164
.test_binaries
162165
.sort_by(|a, b| a.relative_path.cmp(&b.relative_path));
163166
assert_eq!(
164-
test_case.test_binaries[0].relative_path.to_string_lossy(),
165-
"test_case/pkg1"
167+
test_case.test_binaries[0].relative_path,
168+
Path::new("test_case/pkg1")
166169
);
167170
assert_eq!(test_case.test_binaries[0].absolute_path, pkg1_dir);
168171
assert_eq!(
169-
test_case.test_binaries[1].relative_path.to_string_lossy(),
170-
"test_case/pkg2"
172+
test_case.test_binaries[1].relative_path,
173+
Path::new("test_case/pkg2")
171174
);
172175
assert_eq!(test_case.test_binaries[1].absolute_path, pkg2_dir);
173176
}

0 commit comments

Comments
 (0)