@@ -2,27 +2,35 @@ use crate::runner::RunnerResult;
2
2
use std:: fmt:: { Display , Formatter } ;
3
3
use std:: fs;
4
4
use std:: path:: { Path , PathBuf } ;
5
- use std:: sync:: Arc ;
6
5
use tracing:: debug;
7
6
8
7
/// A test case containing multiple test binaries that should produce the same output
9
8
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 ,
12
13
/// the absolute path
13
14
pub absolute_path : PathBuf ,
14
15
/// All the test binaries of this single test case.
15
16
pub test_binaries : Vec < TestBinary > ,
16
17
}
17
18
18
19
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 ( ) ,
24
28
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) ;
26
34
test_case. collect_test_binaries ( ) ?;
27
35
if test_case. test_binaries . len ( ) > 0 {
28
36
debug ! ( "Test case found: {}" , relative_path. display( ) ) ;
@@ -48,42 +56,37 @@ impl TestCase {
48
56
49
57
impl Display for TestCase {
50
58
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 )
52
60
}
53
61
}
54
62
55
63
/// A test binary that can be executed
56
64
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
58
68
pub relative_path : PathBuf ,
59
- /// the relative path from the test case
60
- pub test_case_relative_path : Arc < PathBuf > ,
61
69
/// the absolute path
62
70
pub absolute_path : PathBuf ,
63
71
}
64
72
65
73
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 {
67
75
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) ,
71
83
}
72
84
}
73
-
74
- pub fn path_from_root ( & self ) -> PathBuf {
75
- self . test_case_relative_path . join ( & self . relative_path )
76
- }
77
85
}
78
86
79
87
impl Display for TestBinary {
80
88
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 )
87
90
}
88
91
}
89
92
@@ -121,19 +124,15 @@ mod tests {
121
124
122
125
#[ test]
123
126
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" ) ) ;
130
129
test_case
131
130
. test_binaries
132
131
. 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" ) ;
134
133
assert_eq ! (
135
134
test_case. test_binaries[ 0 ] . to_string( ) ,
136
- "difftests::group1::testcase1"
135
+ "difftests::core:: group1::testcase1"
137
136
) ;
138
137
}
139
138
@@ -163,12 +162,12 @@ mod tests {
163
162
. sort_by ( |a, b| a. relative_path . cmp ( & b. relative_path ) ) ;
164
163
assert_eq ! (
165
164
test_case. test_binaries[ 0 ] . relative_path. to_string_lossy( ) ,
166
- "pkg1"
165
+ "test_case/ pkg1"
167
166
) ;
168
167
assert_eq ! ( test_case. test_binaries[ 0 ] . absolute_path, pkg1_dir) ;
169
168
assert_eq ! (
170
169
test_case. test_binaries[ 1 ] . relative_path. to_string_lossy( ) ,
171
- "pkg2"
170
+ "test_case/ pkg2"
172
171
) ;
173
172
assert_eq ! ( test_case. test_binaries[ 1 ] . absolute_path, pkg2_dir) ;
174
173
}
0 commit comments