Skip to content

Commit e6e3964

Browse files
committed
difftest: fix test mod paths with subdirectories
1 parent 7882524 commit e6e3964

File tree

2 files changed

+37
-38
lines changed

2 files changed

+37
-38
lines changed

tests/difftests/bin/src/runner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ impl Runner {
255255
let pkg_name = self.get_package_name(&manifest_path)?;
256256
debug!("Package '{}' detected", pkg_name);
257257

258-
let package_out = self.output_dir.join(package.path_from_root());
258+
let package_out = self.output_dir.join(&package.relative_path);
259259
fs::create_dir_all(&package_out)?;
260260
debug!("Writing output to '{}'", package_out.display());
261261
let config_file = package_out.join("config.json");

tests/difftests/bin/src/testcase.rs

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,35 @@ use crate::runner::RunnerResult;
22
use std::fmt::{Display, Formatter};
33
use std::fs;
44
use std::path::{Path, PathBuf};
5-
use std::sync::Arc;
65
use tracing::debug;
76

87
/// A test case containing multiple test binaries that should produce the same output
98
pub struct TestCase {
10-
/// the relative path from the base difftest dir
11-
pub relative_path: Arc<PathBuf>,
9+
/// The name of the testcase, as a rust mod path
10+
pub name: String,
11+
/// the relative path from the base `difftest` dir
12+
pub relative_path: PathBuf,
1213
/// the absolute path
1314
pub absolute_path: PathBuf,
1415
/// All the test binaries of this single test case.
1516
pub test_binaries: Vec<TestBinary>,
1617
}
1718

1819
impl TestCase {
19-
pub fn try_new(root: &Path, relative_path: &Path) -> RunnerResult<Option<Self>> {
20-
let absolute_path = root.join(relative_path);
21-
let mut test_case = TestCase {
22-
absolute_path,
23-
relative_path: Arc::new(relative_path.to_path_buf()),
20+
pub fn new_empty(root: &Path, relative_path: &Path) -> Self {
21+
TestCase {
22+
name: format!(
23+
"difftests::{}",
24+
relative_path.to_string_lossy().replace("/", "::")
25+
),
26+
absolute_path: root.join(relative_path),
27+
relative_path: relative_path.to_path_buf(),
2428
test_binaries: Vec::new(),
25-
};
29+
}
30+
}
31+
32+
pub fn try_new(root: &Path, relative_path: &Path) -> RunnerResult<Option<Self>> {
33+
let mut test_case = Self::new_empty(root, relative_path);
2634
test_case.collect_test_binaries()?;
2735
if test_case.test_binaries.len() > 0 {
2836
debug!("Test case found: {}", relative_path.display());
@@ -48,42 +56,37 @@ impl TestCase {
4856

4957
impl Display for TestCase {
5058
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
51-
write!(f, "difftests::{}", self.relative_path.to_string_lossy())
59+
f.write_str(&self.name)
5260
}
5361
}
5462

5563
/// A test binary that can be executed
5664
pub struct TestBinary {
57-
/// the relative path from the test case
65+
/// The name of the testcase, as a rust mod path
66+
pub name: String,
67+
/// the relative path from the base `difftest` dir
5868
pub relative_path: PathBuf,
59-
/// the relative path from the test case
60-
pub test_case_relative_path: Arc<PathBuf>,
6169
/// the absolute path
6270
pub absolute_path: PathBuf,
6371
}
6472

6573
impl TestBinary {
66-
pub fn new(test_case: &TestCase, relative_path: PathBuf) -> Self {
74+
pub fn new(test_case: &TestCase, relative_to_test_case: PathBuf) -> Self {
6775
Self {
68-
absolute_path: test_case.absolute_path.join(&relative_path),
69-
test_case_relative_path: test_case.relative_path.clone(),
70-
relative_path,
76+
name: format!(
77+
"{}::{}",
78+
test_case.name,
79+
relative_to_test_case.to_string_lossy().replace("/", "::")
80+
),
81+
relative_path: test_case.relative_path.join(&relative_to_test_case),
82+
absolute_path: test_case.absolute_path.join(&relative_to_test_case),
7183
}
7284
}
73-
74-
pub fn path_from_root(&self) -> PathBuf {
75-
self.test_case_relative_path.join(&self.relative_path)
76-
}
7785
}
7886

7987
impl Display for TestBinary {
8088
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
81-
write!(
82-
f,
83-
"difftests::{}::{}",
84-
self.test_case_relative_path.to_string_lossy(),
85-
self.relative_path.to_string_lossy()
86-
)
89+
f.write_str(&self.name)
8790
}
8891
}
8992

@@ -121,19 +124,15 @@ mod tests {
121124

122125
#[test]
123126
fn test_format_test_name() {
124-
let test_case_relative_path = Arc::new(PathBuf::from("group1"));
125-
let mut test_case = TestCase {
126-
absolute_path: PathBuf::from("/home/user/tests/group1"),
127-
relative_path: test_case_relative_path,
128-
test_binaries: Vec::new(),
129-
};
127+
let mut test_case =
128+
TestCase::new_empty(Path::new("/home/user/tests"), Path::new("core/group1"));
130129
test_case
131130
.test_binaries
132131
.push(TestBinary::new(&test_case, PathBuf::from("testcase1")));
133-
assert_eq!(test_case.to_string(), "difftests::group1");
132+
assert_eq!(test_case.to_string(), "difftests::core::group1");
134133
assert_eq!(
135134
test_case.test_binaries[0].to_string(),
136-
"difftests::group1::testcase1"
135+
"difftests::core::group1::testcase1"
137136
);
138137
}
139138

@@ -163,12 +162,12 @@ mod tests {
163162
.sort_by(|a, b| a.relative_path.cmp(&b.relative_path));
164163
assert_eq!(
165164
test_case.test_binaries[0].relative_path.to_string_lossy(),
166-
"pkg1"
165+
"test_case/pkg1"
167166
);
168167
assert_eq!(test_case.test_binaries[0].absolute_path, pkg1_dir);
169168
assert_eq!(
170169
test_case.test_binaries[1].relative_path.to_string_lossy(),
171-
"pkg2"
170+
"test_case/pkg2"
172171
);
173172
assert_eq!(test_case.test_binaries[1].absolute_path, pkg2_dir);
174173
}

0 commit comments

Comments
 (0)