1
+ // FIXME: The way this module sets up tests is a relic and more convoluted
2
+ // than it needs to be
3
+
1
4
import std:: option;
2
5
import std:: getopts;
3
6
import std:: test;
@@ -124,8 +127,10 @@ fn test_opts(config: config) -> test::test_opts {
124
127
run_ignored : config. run_ignored }
125
128
}
126
129
127
- type tests_and_conv_fn =
128
- { tests: [ test:: test_desc] , to_task : fn ( fn ( ) ) -> test:: joinable} ;
130
+ type tests_and_conv_fn = {
131
+ tests: [ test:: test_desc<fn ( ) >] ,
132
+ to_task : fn ( fn ( ) ) -> test:: joinable
133
+ } ;
129
134
130
135
fn make_tests ( cx : cx ) -> tests_and_conv_fn {
131
136
log #fmt[ "making tests from %s" , cx. config . src_base ] ;
@@ -162,7 +167,7 @@ fn is_test(config: config, testfile: str) -> bool {
162
167
}
163
168
164
169
fn make_test ( cx : cx , testfile : str , configport : port < [ u8 ] > ) ->
165
- test:: test_desc {
170
+ test:: test_desc < fn ( ) > {
166
171
{ name: make_test_name ( cx. config , testfile) ,
167
172
fn : make_test_closure( testfile , chan ( configport ) ) ,
168
173
ignore: header:: is_test_ignored ( cx. config , testfile) }
@@ -172,94 +177,31 @@ fn make_test_name(config: config, testfile: str) -> str {
172
177
#fmt[ "[%s] %s" , mode_str ( config. mode ) , testfile]
173
178
}
174
179
175
- /*
176
- So this is kind of crappy:
177
-
178
- A test is just defined as a function, as you might expect, but tests have to
179
- run in their own tasks. Unfortunately, if your test needs dynamic data then it
180
- needs to be a closure, and transferring closures across tasks without
181
- committing a host of memory management transgressions is just impossible.
182
-
183
- To get around this, the standard test runner allows you the opportunity do
184
- your own conversion from a test function to a task. It gives you your function
185
- and you give it back a task.
186
-
187
- So that's what we're going to do. Here's where it gets stupid. To get the
188
- the data out of the test function we are going to run the test function,
189
- which will do nothing but send the data for that test to a port we've set
190
- up. Then we'll spawn that data into another task and return the task.
191
- Really convoluted. Need to think up of a better definition for tests.
192
- */
193
-
194
- fn make_test_closure ( testfile : str , configchan : chan < [ u8 ] > ) -> test:: test_fn {
180
+ fn make_test_closure ( testfile : str ,
181
+ configchan : chan < [ u8 ] > ) -> test:: test_fn < fn ( ) > {
195
182
bind send_config ( testfile, configchan)
196
183
}
197
184
198
185
fn send_config ( testfile : str , configchan : chan < [ u8 ] > ) {
199
186
send ( configchan, str:: bytes ( testfile) ) ;
200
187
}
201
188
202
- /*
203
- FIXME: Good god forgive me.
204
-
205
- So actually shuttling structural data across tasks isn't possible at this
206
- time, but we can send strings! Sadly, I need the whole config record, in the
207
- test task so, instead of fixing the mechanism in the compiler I'm going to
208
- break up the config record and pass everything individually to the spawned
209
- function.
210
- */
211
-
212
189
fn closure_to_task ( cx : cx , configport : port < [ u8 ] > , testfn : fn ( ) ) ->
213
190
test:: joinable {
214
191
testfn ( ) ;
215
192
let testfile = recv ( configport) ;
216
193
217
- let compile_lib_path = cx. config . compile_lib_path ;
218
- let run_lib_path = cx. config . run_lib_path ;
219
- let rustc_path = cx. config . rustc_path ;
220
- let src_base = cx. config . src_base ;
221
- let build_base = cx. config . build_base ;
222
- let stage_id = cx. config . stage_id ;
223
- let mode = mode_str ( cx. config . mode ) ;
224
- let run_ignored = cx. config . run_ignored ;
225
- let filter = opt_str ( cx. config . filter ) ;
226
- let runtool = opt_str ( cx. config . runtool ) ;
227
- let rustcflags = opt_str ( cx. config . rustcflags ) ;
228
- let verbose = cx. config . verbose ;
229
- let chan = cx. procsrv . chan ;
230
-
231
- let testthunk =
232
- bind run_test_task ( compile_lib_path, run_lib_path, rustc_path,
233
- src_base, build_base, stage_id, mode, run_ignored,
234
- filter, runtool, rustcflags, verbose, chan,
235
- testfile) ;
236
- ret task:: spawn_joinable ( testthunk) ;
194
+ ret task:: spawn_joinable2 (
195
+ ( cx. config , cx. procsrv . chan , testfile) , run_test_task) ;
237
196
}
238
197
239
- fn run_test_task ( -compile_lib_path : str , -run_lib_path : str , -rustc_path : str ,
240
- -src_base : str , -build_base : str , -stage_id : str , -mode : str ,
241
- -run_ignored : bool , -opt_filter : str , -opt_runtool : str ,
242
- -opt_rustcflags : str , -verbose : bool ,
243
- -procsrv_chan : procsrv:: reqchan , -testfile : [ u8 ] ) {
198
+ fn # run_test_task ( args : ( common:: config , procsrv:: reqchan , [ u8 ] ) ) {
244
199
245
- test :: configure_test_task ( ) ;
200
+ let ( config , procsrv_chan , testfile ) = args ;
246
201
247
- let config =
248
- { compile_lib_path: compile_lib_path,
249
- run_lib_path: run_lib_path,
250
- rustc_path: rustc_path,
251
- src_base: src_base,
252
- build_base: build_base,
253
- stage_id: stage_id,
254
- mode: str_mode ( mode) ,
255
- run_ignored: run_ignored,
256
- filter: str_opt ( opt_filter) ,
257
- runtool: str_opt ( opt_runtool) ,
258
- rustcflags: str_opt ( opt_rustcflags) ,
259
- verbose: verbose} ;
202
+ test:: configure_test_task ( ) ;
260
203
261
204
let procsrv = procsrv:: from_chan ( procsrv_chan) ;
262
-
263
205
let cx = { config: config, procsrv: procsrv} ;
264
206
265
207
runtest:: run ( cx, testfile) ;
0 commit comments