@@ -2,27 +2,35 @@ use crate::runner::RunnerResult;
22use std:: fmt:: { Display , Formatter } ;
33use std:: fs;
44use std:: path:: { Path , PathBuf } ;
5- use std:: sync:: Arc ;
65use tracing:: debug;
76
87/// A test case containing multiple test binaries that should produce the same output
98pub 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
1819impl 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
4957impl 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
5664pub 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
6573impl 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
7987impl 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