4
4
//! This will hopefully make it easier to migrate away from libtest someday.
5
5
6
6
use std:: borrow:: Cow ;
7
- use std:: io;
8
7
use std:: sync:: Arc ;
9
8
10
9
use crate :: common:: { Config , TestPaths } ;
11
10
12
- /// Delegates to libtest to run the list of collected tests.
13
- ///
14
- /// Returns `Ok(true)` if all tests passed, or `Ok(false)` if one or more tests failed.
15
- pub ( crate ) fn execute_tests ( config : & Config , tests : Vec < CollectedTest > ) -> io:: Result < bool > {
16
- let opts = test_opts ( config) ;
17
- let tests = tests. into_iter ( ) . map ( |t| t. into_libtest ( ) ) . collect :: < Vec < _ > > ( ) ;
18
-
19
- test:: run_tests_console ( & opts, tests)
20
- }
11
+ pub ( crate ) mod libtest;
21
12
22
13
/// Information needed to create a `test::TestDescAndFn`.
23
14
pub ( crate ) struct CollectedTest {
@@ -35,45 +26,6 @@ pub(crate) struct CollectedTestDesc {
35
26
pub ( crate ) should_panic : ShouldPanic ,
36
27
}
37
28
38
- impl CollectedTest {
39
- fn into_libtest ( self ) -> test:: TestDescAndFn {
40
- let Self { desc, config, testpaths, revision } = self ;
41
- let CollectedTestDesc { name, ignore, ignore_message, should_panic } = desc;
42
-
43
- // Libtest requires the ignore message to be a &'static str, so we might
44
- // have to leak memory to create it. This is fine, as we only do so once
45
- // per test, so the leak won't grow indefinitely.
46
- let ignore_message = ignore_message. map ( |msg| match msg {
47
- Cow :: Borrowed ( s) => s,
48
- Cow :: Owned ( s) => & * String :: leak ( s) ,
49
- } ) ;
50
-
51
- let desc = test:: TestDesc {
52
- name : test:: DynTestName ( name) ,
53
- ignore,
54
- ignore_message,
55
- source_file : "" ,
56
- start_line : 0 ,
57
- start_col : 0 ,
58
- end_line : 0 ,
59
- end_col : 0 ,
60
- should_panic : should_panic. to_libtest ( ) ,
61
- compile_fail : false ,
62
- no_run : false ,
63
- test_type : test:: TestType :: Unknown ,
64
- } ;
65
-
66
- // This closure is invoked when libtest returns control to compiletest
67
- // to execute the test.
68
- let testfn = test:: DynTestFn ( Box :: new ( move || {
69
- crate :: runtest:: run ( config, & testpaths, revision. as_deref ( ) ) ;
70
- Ok ( ( ) )
71
- } ) ) ;
72
-
73
- test:: TestDescAndFn { desc, testfn }
74
- }
75
- }
76
-
77
29
/// Whether console output should be colored or not.
78
30
#[ derive( Copy , Clone , Default , Debug ) ]
79
31
pub enum ColorConfig {
@@ -83,16 +35,6 @@ pub enum ColorConfig {
83
35
NeverColor ,
84
36
}
85
37
86
- impl ColorConfig {
87
- fn to_libtest ( self ) -> test:: ColorConfig {
88
- match self {
89
- Self :: AutoColor => test:: ColorConfig :: AutoColor ,
90
- Self :: AlwaysColor => test:: ColorConfig :: AlwaysColor ,
91
- Self :: NeverColor => test:: ColorConfig :: NeverColor ,
92
- }
93
- }
94
- }
95
-
96
38
/// Format of the test results output.
97
39
#[ derive( Copy , Clone , Debug , Default , PartialEq , Eq ) ]
98
40
pub enum OutputFormat {
@@ -105,52 +47,9 @@ pub enum OutputFormat {
105
47
Json ,
106
48
}
107
49
108
- impl OutputFormat {
109
- fn to_libtest ( self ) -> test:: OutputFormat {
110
- match self {
111
- Self :: Pretty => test:: OutputFormat :: Pretty ,
112
- Self :: Terse => test:: OutputFormat :: Terse ,
113
- Self :: Json => test:: OutputFormat :: Json ,
114
- }
115
- }
116
- }
117
-
118
50
/// Whether test is expected to panic or not.
119
51
#[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash ) ]
120
52
pub ( crate ) enum ShouldPanic {
121
53
No ,
122
54
Yes ,
123
55
}
124
-
125
- impl ShouldPanic {
126
- fn to_libtest ( self ) -> test:: ShouldPanic {
127
- match self {
128
- Self :: No => test:: ShouldPanic :: No ,
129
- Self :: Yes => test:: ShouldPanic :: Yes ,
130
- }
131
- }
132
- }
133
-
134
- fn test_opts ( config : & Config ) -> test:: TestOpts {
135
- test:: TestOpts {
136
- exclude_should_panic : false ,
137
- filters : config. filters . clone ( ) ,
138
- filter_exact : config. filter_exact ,
139
- run_ignored : if config. run_ignored { test:: RunIgnored :: Yes } else { test:: RunIgnored :: No } ,
140
- format : config. format . to_libtest ( ) ,
141
- logfile : None ,
142
- run_tests : true ,
143
- bench_benchmarks : true ,
144
- nocapture : config. nocapture ,
145
- color : config. color . to_libtest ( ) ,
146
- shuffle : false ,
147
- shuffle_seed : None ,
148
- test_threads : None ,
149
- skip : config. skip . clone ( ) ,
150
- list : false ,
151
- options : test:: Options :: new ( ) ,
152
- time_options : None ,
153
- force_run_in_process : false ,
154
- fail_fast : config. fail_fast ,
155
- }
156
- }
0 commit comments