Skip to content

Commit 103817c

Browse files
committed
---
yaml --- r: 5870 b: refs/heads/master c: 3b54dcf h: refs/heads/master v: v3
1 parent 55761e0 commit 103817c

File tree

6 files changed

+154
-145
lines changed

6 files changed

+154
-145
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1abebf042a0dc8fcbf6c313e20046ca68e3d09ed
2+
refs/heads/master: 3b54dcfa79833dc3dc2569cc39d79b6d9ffde0d5

trunk/src/comp/front/test.rs

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,19 @@ fn empty_fn_ty() -> ast::ty {
224224

225225
// The ast::ty of [std::test::test_desc]
226226
fn mk_test_desc_vec_ty(cx: test_ctxt) -> @ast::ty {
227+
let test_fn_ty: ast::ty = nospan(
228+
ast::ty_path(
229+
nospan({
230+
global: false,
231+
idents: ["std", "test", "default_test_fn"],
232+
types: []
233+
}),
234+
cx.next_node_id()));
235+
227236
let test_desc_ty_path: ast::path =
228237
nospan({global: false,
229238
idents: ["std", "test", "test_desc"],
230-
types: []});
239+
types: [@test_fn_ty]});
231240

232241
let test_desc_ty: ast::ty =
233242
nospan(ast::ty_path(test_desc_ty_path, cx.next_node_id()));
@@ -273,8 +282,10 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
273282
node: ast::expr_path(fn_path),
274283
span: span};
275284

285+
let fn_wrapper_expr = mk_test_wrapper(cx, fn_expr, span);
286+
276287
let fn_field: ast::field =
277-
nospan({mut: ast::imm, ident: "fn", expr: @fn_expr});
288+
nospan({mut: ast::imm, ident: "fn", expr: fn_wrapper_expr});
278289

279290
let ignore_lit: ast::lit = nospan(ast::lit_bool(test.ignore));
280291

@@ -293,6 +304,51 @@ fn mk_test_desc_rec(cx: test_ctxt, test: test) -> @ast::expr {
293304
ret @desc_rec;
294305
}
295306

307+
// Produces a bare function that wraps the test function
308+
// FIXME: This can go away once fn is the type of bare function
309+
fn mk_test_wrapper(cx: test_ctxt,
310+
fn_path_expr: ast::expr,
311+
span: span) -> @ast::expr {
312+
let call_expr: ast::expr = {
313+
id: cx.next_node_id(),
314+
node: ast::expr_call(@fn_path_expr, []),
315+
span: span
316+
};
317+
318+
let call_stmt: ast::stmt = nospan(
319+
ast::stmt_expr(@call_expr, cx.next_node_id()));
320+
321+
let wrapper_decl: ast::fn_decl = {
322+
inputs: [],
323+
output: @nospan(ast::ty_nil),
324+
purity: ast::impure_fn,
325+
il: ast::il_normal,
326+
cf: ast::return_val,
327+
constraints: []
328+
};
329+
330+
let wrapper_body: ast::blk = nospan({
331+
stmts: [@call_stmt],
332+
expr: option::none,
333+
id: cx.next_node_id(),
334+
rules: ast::default_blk
335+
});
336+
337+
let wrapper_fn: ast::_fn = {
338+
decl: wrapper_decl,
339+
proto: ast::proto_bare,
340+
body: wrapper_body
341+
};
342+
343+
let wrapper_expr: ast::expr = {
344+
id: cx.next_node_id(),
345+
node: ast::expr_fn(wrapper_fn),
346+
span: span
347+
};
348+
349+
ret @wrapper_expr;
350+
}
351+
296352
fn mk_main(cx: test_ctxt) -> @ast::item {
297353

298354
let args_mt: ast::mt = {ty: @nospan(ast::ty_str), mut: ast::imm};

trunk/src/compiletest/compiletest.rs

Lines changed: 15 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME: The way this module sets up tests is a relic and more convoluted
2+
// than it needs to be
3+
14
import std::option;
25
import std::getopts;
36
import std::test;
@@ -124,8 +127,10 @@ fn test_opts(config: config) -> test::test_opts {
124127
run_ignored: config.run_ignored}
125128
}
126129

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+
};
129134

130135
fn make_tests(cx: cx) -> tests_and_conv_fn {
131136
log #fmt["making tests from %s", cx.config.src_base];
@@ -162,7 +167,7 @@ fn is_test(config: config, testfile: str) -> bool {
162167
}
163168

164169
fn make_test(cx: cx, testfile: str, configport: port<[u8]>) ->
165-
test::test_desc {
170+
test::test_desc<fn()> {
166171
{name: make_test_name(cx.config, testfile),
167172
fn: make_test_closure(testfile, chan(configport)),
168173
ignore: header::is_test_ignored(cx.config, testfile)}
@@ -172,94 +177,31 @@ fn make_test_name(config: config, testfile: str) -> str {
172177
#fmt["[%s] %s", mode_str(config.mode), testfile]
173178
}
174179

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()> {
195182
bind send_config(testfile, configchan)
196183
}
197184

198185
fn send_config(testfile: str, configchan: chan<[u8]>) {
199186
send(configchan, str::bytes(testfile));
200187
}
201188

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-
212189
fn closure_to_task(cx: cx, configport: port<[u8]>, testfn: fn()) ->
213190
test::joinable {
214191
testfn();
215192
let testfile = recv(configport);
216193

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);
237196
}
238197

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])) {
244199

245-
test::configure_test_task();
200+
let (config, procsrv_chan, testfile) = args;
246201

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();
260203

261204
let procsrv = procsrv::from_chan(procsrv_chan);
262-
263205
let cx = {config: config, procsrv: procsrv};
264206

265207
runtest::run(cx, testfile);

trunk/src/compiletest/procsrv.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,14 @@ type response = {pid: int, infd: int, outfd: int, errfd: int};
3737

3838
fn mk() -> handle {
3939
let setupport = port();
40-
let task =
41-
task::spawn_joinable(bind fn (setupchan: chan<chan<request>>) {
42-
let reqport = port();
43-
let reqchan = chan(reqport);
44-
send(setupchan, reqchan);
45-
worker(reqport);
46-
}(chan(setupport)));
40+
let task = task::spawn_joinable2(
41+
chan(setupport),
42+
fn# (setupchan: chan<chan<request>>) {
43+
let reqport = port();
44+
let reqchan = chan(reqport);
45+
send(setupchan, reqchan);
46+
worker(reqport);
47+
});
4748
ret {task: option::some(task), chan: recv(setupport)};
4849
}
4950

0 commit comments

Comments
 (0)