@@ -101,49 +101,124 @@ fn run_mode(cfg: &mut compiletest::Config) {
101
101
compiletest:: run_tests ( & cfg) ;
102
102
}
103
103
104
- #[ allow( clippy:: identity_conversion) ]
105
- fn run_ui_toml_tests ( config : & compiletest:: Config , mut tests : Vec < tester:: TestDescAndFn > ) -> Result < bool , io:: Error > {
106
- let mut result = true ;
107
- let opts = compiletest:: test_opts ( config) ;
108
- for dir in fs:: read_dir ( & config. src_base ) ? {
109
- let dir = dir?;
110
- if !dir. file_type ( ) ?. is_dir ( ) {
111
- continue ;
112
- }
113
- let dir_path = dir. path ( ) ;
114
- set_var ( "CARGO_MANIFEST_DIR" , & dir_path) ;
115
- for file in fs:: read_dir ( & dir_path) ? {
116
- let file = file?;
117
- let file_path = file. path ( ) ;
118
- if file. file_type ( ) ?. is_dir ( ) {
104
+ fn run_ui_toml ( config : & mut compiletest:: Config ) {
105
+ fn run_tests ( config : & compiletest:: Config , mut tests : Vec < tester:: TestDescAndFn > ) -> Result < bool , io:: Error > {
106
+ let mut result = true ;
107
+ let opts = compiletest:: test_opts ( config) ;
108
+ for dir in fs:: read_dir ( & config. src_base ) ? {
109
+ let dir = dir?;
110
+ if !dir. file_type ( ) ?. is_dir ( ) {
119
111
continue ;
120
112
}
121
- if file_path. extension ( ) != Some ( OsStr :: new ( "rs" ) ) {
122
- continue ;
113
+ let dir_path = dir. path ( ) ;
114
+ set_var ( "CARGO_MANIFEST_DIR" , & dir_path) ;
115
+ for file in fs:: read_dir ( & dir_path) ? {
116
+ let file = file?;
117
+ let file_path = file. path ( ) ;
118
+ if file. file_type ( ) ?. is_dir ( ) {
119
+ continue ;
120
+ }
121
+ if file_path. extension ( ) != Some ( OsStr :: new ( "rs" ) ) {
122
+ continue ;
123
+ }
124
+ let paths = compiletest:: common:: TestPaths {
125
+ file : file_path,
126
+ base : config. src_base . clone ( ) ,
127
+ relative_dir : dir_path. file_name ( ) . unwrap ( ) . into ( ) ,
128
+ } ;
129
+ let test_name = compiletest:: make_test_name ( & config, & paths) ;
130
+ let index = tests
131
+ . iter ( )
132
+ . position ( |test| test. desc . name == test_name)
133
+ . expect ( "The test should be in there" ) ;
134
+ result &= tester:: run_tests_console ( & opts, vec ! [ tests. swap_remove( index) ] ) ?;
123
135
}
124
- let paths = compiletest:: common:: TestPaths {
125
- file : file_path,
126
- base : config. src_base . clone ( ) ,
127
- relative_dir : dir_path. file_name ( ) . unwrap ( ) . into ( ) ,
128
- } ;
129
- let test_name = compiletest:: make_test_name ( & config, & paths) ;
130
- let index = tests
131
- . iter ( )
132
- . position ( |test| test. desc . name == test_name)
133
- . expect ( "The test should be in there" ) ;
134
- result &= tester:: run_tests_console ( & opts, vec ! [ tests. swap_remove( index) ] ) ?;
135
136
}
137
+ Ok ( result)
136
138
}
137
- Ok ( result)
138
- }
139
139
140
- fn run_ui_toml ( config : & mut compiletest:: Config ) {
141
140
config. mode = TestMode :: Ui ;
142
141
config. src_base = Path :: new ( "tests" ) . join ( "ui-toml" ) . canonicalize ( ) . unwrap ( ) ;
143
142
144
143
let tests = compiletest:: make_tests ( & config) ;
145
144
146
- let res = run_ui_toml_tests ( & config, tests) ;
145
+ let res = run_tests ( & config, tests) ;
146
+ match res {
147
+ Ok ( true ) => { } ,
148
+ Ok ( false ) => panic ! ( "Some tests failed" ) ,
149
+ Err ( e) => {
150
+ println ! ( "I/O failure during tests: {:?}" , e) ;
151
+ } ,
152
+ }
153
+ }
154
+
155
+ fn run_ui_cargo ( config : & mut compiletest:: Config ) {
156
+ fn run_tests (
157
+ config : & compiletest:: Config ,
158
+ filter : & Option < String > ,
159
+ mut tests : Vec < tester:: TestDescAndFn > ,
160
+ ) -> Result < bool , io:: Error > {
161
+ let mut result = true ;
162
+ let opts = compiletest:: test_opts ( config) ;
163
+
164
+ for dir in fs:: read_dir ( & config. src_base ) ? {
165
+ let dir = dir?;
166
+ if !dir. file_type ( ) ?. is_dir ( ) {
167
+ continue ;
168
+ }
169
+
170
+ // Use the filter if provided
171
+ let dir_path = dir. path ( ) ;
172
+ match & filter {
173
+ Some ( name) if !dir_path. ends_with ( name) => continue ,
174
+ _ => { } ,
175
+ }
176
+
177
+ for case in & [ "pass" , "fail" ] {
178
+ let tail: PathBuf = [ case, "src" ] . iter ( ) . collect ( ) ;
179
+ let src_path = dir_path. join ( tail) ;
180
+ env:: set_current_dir ( & src_path) ?;
181
+
182
+ for file in fs:: read_dir ( & src_path) ? {
183
+ let file = file?;
184
+ if file. file_type ( ) ?. is_dir ( ) {
185
+ continue ;
186
+ }
187
+
188
+ // Search for the main file to avoid running a test for each file in the project
189
+ let file_path = file. path ( ) ;
190
+ match file_path. file_name ( ) . and_then ( OsStr :: to_str) {
191
+ Some ( "main.rs" ) => { } ,
192
+ _ => continue ,
193
+ }
194
+
195
+ let paths = compiletest:: common:: TestPaths {
196
+ file : file_path,
197
+ base : config. src_base . clone ( ) ,
198
+ relative_dir : src_path. strip_prefix ( & config. src_base ) . unwrap ( ) . into ( ) ,
199
+ } ;
200
+ let test_name = compiletest:: make_test_name ( & config, & paths) ;
201
+ let index = tests
202
+ . iter ( )
203
+ . position ( |test| test. desc . name == test_name)
204
+ . expect ( "The test should be in there" ) ;
205
+ result &= tester:: run_tests_console ( & opts, vec ! [ tests. swap_remove( index) ] ) ?;
206
+ }
207
+ }
208
+ }
209
+ Ok ( result)
210
+ }
211
+
212
+ config. mode = TestMode :: Ui ;
213
+ config. src_base = Path :: new ( "tests" ) . join ( "ui-cargo" ) . canonicalize ( ) . unwrap ( ) ;
214
+
215
+ let tests = compiletest:: make_tests ( & config) ;
216
+
217
+ let current_dir = env:: current_dir ( ) . unwrap ( ) ;
218
+ let filter = env:: var ( "TESTNAME" ) . ok ( ) ;
219
+ let res = run_tests ( & config, & filter, tests) ;
220
+ env:: set_current_dir ( current_dir) . unwrap ( ) ;
221
+
147
222
match res {
148
223
Ok ( true ) => { } ,
149
224
Ok ( false ) => panic ! ( "Some tests failed" ) ,
@@ -165,4 +240,5 @@ fn compile_test() {
165
240
let mut config = default_config ( ) ;
166
241
run_mode ( & mut config) ;
167
242
run_ui_toml ( & mut config) ;
243
+ run_ui_cargo ( & mut config) ;
168
244
}
0 commit comments