Skip to content

Commit 3a5f4e7

Browse files
committed
Convert the task-comm parts of compiletest to istrs. Issue #855
This reduces the amount of voodoo in compiletest considerably.
1 parent c2eafd2 commit 3a5f4e7

File tree

4 files changed

+108
-61
lines changed

4 files changed

+108
-61
lines changed

src/test/compiletest/common.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,17 @@ type config =
1616
// for running under valgrind
1717
// Flags to pass to the compiler
1818
// Explain what's going on
19-
{compile_lib_path: str,
20-
run_lib_path: str,
21-
rustc_path: str,
22-
src_base: str,
23-
build_base: str,
24-
stage_id: str,
19+
{compile_lib_path: istr,
20+
run_lib_path: istr,
21+
rustc_path: istr,
22+
src_base: istr,
23+
build_base: istr,
24+
stage_id: istr,
2525
mode: mode,
2626
run_ignored: bool,
27-
filter: option::t<str>,
28-
runtool: option::t<str>,
29-
rustcflags: option::t<str>,
27+
filter: option::t<istr>,
28+
runtool: option::t<istr>,
29+
rustcflags: option::t<istr>,
3030
verbose: bool};
3131

3232
type cx = {config: config, procsrv: procsrv::handle};

src/test/compiletest/compiletest.rs

Lines changed: 74 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -46,32 +46,41 @@ fn parse_config(args: &[str]) -> config {
4646
getopts::failure(f) { fail getopts::fail_str(f) }
4747
};
4848

49-
ret {compile_lib_path: getopts::opt_str(match, "compile-lib-path"),
50-
run_lib_path: getopts::opt_str(match, "run-lib-path"),
51-
rustc_path: getopts::opt_str(match, "rustc-path"),
52-
src_base: getopts::opt_str(match, "src-base"),
53-
build_base: getopts::opt_str(match, "build-base"),
54-
stage_id: getopts::opt_str(match, "stage-id"),
49+
let cnv = istr::from_estr;
50+
let cnvo = fn(o: &option::t<str>) -> option::t<istr> {
51+
alt o {
52+
option::some(s) { option::some(istr::from_estr(s)) }
53+
option::none. { option::none }
54+
}
55+
};
56+
57+
ret {compile_lib_path: cnv(getopts::opt_str(match, "compile-lib-path")),
58+
run_lib_path: cnv(getopts::opt_str(match, "run-lib-path")),
59+
rustc_path: cnv(getopts::opt_str(match, "rustc-path")),
60+
src_base: cnv(getopts::opt_str(match, "src-base")),
61+
build_base: cnv(getopts::opt_str(match, "build-base")),
62+
stage_id: cnv(getopts::opt_str(match, "stage-id")),
5563
mode: str_mode(getopts::opt_str(match, "mode")),
5664
run_ignored: getopts::opt_present(match, "ignored"),
5765
filter:
5866
if vec::len(match.free) > 0u {
59-
option::some(match.free[0])
67+
option::some(cnv(match.free[0]))
6068
} else { option::none },
61-
runtool: getopts::opt_maybe_str(match, "runtool"),
62-
rustcflags: getopts::opt_maybe_str(match, "rustcflags"),
69+
runtool: cnvo(getopts::opt_maybe_str(match, "runtool")),
70+
rustcflags: cnvo(getopts::opt_maybe_str(match, "rustcflags")),
6371
verbose: getopts::opt_present(match, "verbose")};
6472
}
6573

6674
fn log_config(config: &config) {
6775
let c = config;
6876
logv(c, #fmt["configuration:"]);
69-
logv(c, #fmt["compile_lib_path: %s", config.compile_lib_path]);
70-
logv(c, #fmt["run_lib_path: %s", config.run_lib_path]);
71-
logv(c, #fmt["rustc_path: %s", config.rustc_path]);
72-
logv(c, #fmt["src_base: %s", config.src_base]);
73-
logv(c, #fmt["build_base: %s", config.build_base]);
74-
logv(c, #fmt["stage_id: %s", config.stage_id]);
77+
logv(c, #fmt["compile_lib_path: %s",
78+
istr::to_estr(config.compile_lib_path)]);
79+
logv(c, #fmt["run_lib_path: %s", istr::to_estr(config.run_lib_path)]);
80+
logv(c, #fmt["rustc_path: %s", istr::to_estr(config.rustc_path)]);
81+
logv(c, #fmt["src_base: %s", istr::to_estr(config.src_base)]);
82+
logv(c, #fmt["build_base: %s", istr::to_estr(config.build_base)]);
83+
logv(c, #fmt["stage_id: %s", istr::to_estr(config.stage_id)]);
7584
logv(c, #fmt["mode: %s", mode_str(config.mode)]);
7685
logv(c, #fmt["run_ignored: %b", config.run_ignored]);
7786
logv(c, #fmt["filter: %s", opt_str(config.filter)]);
@@ -81,12 +90,15 @@ fn log_config(config: &config) {
8190
logv(c, #fmt["\n"]);
8291
}
8392

84-
fn opt_str(maybestr: option::t<str>) -> str {
85-
alt maybestr { option::some(s) { s } option::none. { "(none)" } }
93+
fn opt_str(maybestr: option::t<istr>) -> str {
94+
alt maybestr {
95+
option::some(s) { istr::to_estr(s) }
96+
option::none. { "(none)" }
97+
}
8698
}
8799

88-
fn str_opt(maybestr: str) -> option::t<str> {
89-
if maybestr != "(none)" { option::some(maybestr) } else { option::none }
100+
fn str_opt(maybestr: &istr) -> option::t<istr> {
101+
if maybestr != ~"(none)" { option::some(maybestr) } else { option::none }
90102
}
91103

92104
fn str_mode(s: str) -> mode {
@@ -117,17 +129,23 @@ fn run_tests(config: &config) {
117129
}
118130

119131
fn test_opts(config: &config) -> test::test_opts {
120-
{filter: config.filter, run_ignored: config.run_ignored}
132+
{
133+
filter: alt config.filter {
134+
option::some(s) { option::some(istr::to_estr(s)) }
135+
option::none. { option::none }
136+
},
137+
run_ignored: config.run_ignored
138+
}
121139
}
122140

123141
type tests_and_conv_fn =
124142
{tests: [test::test_desc], to_task: fn(&fn()) -> test::joinable};
125143

126144
fn make_tests(cx: &cx) -> tests_and_conv_fn {
127-
log #fmt["making tests from %s", cx.config.src_base];
145+
log #fmt["making tests from %s", istr::to_estr(cx.config.src_base)];
128146
let configport = port::<[u8]>();
129147
let tests = [];
130-
for file: istr in fs::list_dir(istr::from_estr(cx.config.src_base)) {
148+
for file: istr in fs::list_dir(cx.config.src_base) {
131149
let file = istr::to_estr(file);
132150
log #fmt["inspecting file %s", file];
133151
if is_test(cx.config, file) {
@@ -212,23 +230,43 @@ fn closure_to_task(cx: cx, configport: port<[u8]>, testfn: &fn()) ->
212230
test::joinable {
213231
testfn();
214232
let testfile = recv(configport);
233+
234+
let compile_lib_path = cx.config.compile_lib_path;
235+
let run_lib_path = cx.config.run_lib_path;
236+
let rustc_path = cx.config.rustc_path;
237+
let src_base = cx.config.src_base;
238+
let build_base = cx.config.build_base;
239+
let stage_id = cx.config.stage_id;
240+
let mode = istr::from_estr(mode_str(cx.config.mode));
241+
let run_ignored = cx.config.run_ignored;
242+
let filter = istr::from_estr(opt_str(cx.config.filter));
243+
let runtool = istr::from_estr(opt_str(cx.config.runtool));
244+
let rustcflags = istr::from_estr(opt_str(cx.config.rustcflags));
245+
let verbose = cx.config.verbose;
246+
let chan = cx.procsrv.chan;
247+
215248
let testthunk =
216-
bind run_test_task(cx.config.compile_lib_path, cx.config.run_lib_path,
217-
cx.config.rustc_path, cx.config.src_base,
218-
cx.config.build_base, cx.config.stage_id,
219-
mode_str(cx.config.mode), cx.config.run_ignored,
220-
opt_str(cx.config.filter),
221-
opt_str(cx.config.runtool),
222-
opt_str(cx.config.rustcflags), cx.config.verbose,
223-
cx.procsrv.chan, testfile);
249+
bind run_test_task(compile_lib_path, run_lib_path,
250+
rustc_path, src_base,
251+
build_base, stage_id,
252+
mode,
253+
run_ignored,
254+
filter,
255+
runtool,
256+
rustcflags,
257+
verbose,
258+
chan,
259+
testfile);
224260
ret task::spawn_joinable(testthunk);
225261
}
226262

227-
fn run_test_task(compile_lib_path: str, run_lib_path: str, rustc_path: str,
228-
src_base: str, build_base: str, stage_id: str, mode: str,
229-
run_ignored: bool, opt_filter: str, opt_runtool: str,
230-
opt_rustcflags: str, verbose: bool,
231-
procsrv_chan: procsrv::reqchan, testfile: -[u8]) {
263+
fn run_test_task(compile_lib_path: -istr, run_lib_path: -istr,
264+
rustc_path: -istr,
265+
src_base: -istr, build_base: -istr, stage_id: -istr,
266+
mode: -istr,
267+
run_ignored: -bool, opt_filter: -istr, opt_runtool: -istr,
268+
opt_rustcflags: -istr, verbose: -bool,
269+
procsrv_chan: -procsrv::reqchan, testfile: -[u8]) {
232270

233271
test::configure_test_task();
234272

@@ -239,7 +277,7 @@ fn run_test_task(compile_lib_path: str, run_lib_path: str, rustc_path: str,
239277
src_base: src_base,
240278
build_base: build_base,
241279
stage_id: stage_id,
242-
mode: str_mode(mode),
280+
mode: str_mode(istr::to_estr(mode)),
243281
run_ignored: run_ignored,
244282
filter: str_opt(opt_filter),
245283
runtool: str_opt(opt_runtool),

src/test/compiletest/header.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ fn is_test_ignored(config: &config, testfile: &str) -> bool {
6060
for each ln: str in iter_header(testfile) {
6161
// FIXME: Can't return or break from iterator
6262
found = found
63-
|| parse_name_directive(ln, "xfail-" + config.stage_id);
63+
|| parse_name_directive(ln, "xfail-"
64+
+ istr::to_estr(config.stage_id));
6465
if (config.mode == common::mode_pretty) {
6566
found = found
6667
|| parse_name_directive(ln, "xfail-pretty");

src/test/compiletest/runtest.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn run_pretty_test(cx: &cx, props: &test_props, testfile: &str) {
139139
}
140140

141141
fn make_pp_args(config: &config, _testfile: &str) -> procargs {
142-
let prog = config.rustc_path;
142+
let prog = istr::to_estr(config.rustc_path);
143143
let args = ["-", "--pretty", "normal"];
144144
ret {prog: prog, args: args};
145145
}
@@ -170,7 +170,7 @@ actual:\n\
170170
}
171171

172172
fn make_typecheck_args(config: &config, _testfile: &str) -> procargs {
173-
let prog = config.rustc_path;
173+
let prog = istr::to_estr(config.rustc_path);
174174
let args = ["-", "--no-trans", "--lib"];
175175
ret {prog: prog, args: args};
176176
}
@@ -230,7 +230,7 @@ fn exec_compiled_test(cx: &cx, props: &test_props, testfile: &str) ->
230230
}
231231

232232
fn compose_and_run(cx: &cx, testfile: &str,
233-
make_args: fn(&config, &str) -> procargs, lib_path: &str,
233+
make_args: fn(&config, &str) -> procargs, lib_path: &istr,
234234
input: option::t<str>) -> procres {
235235
let procargs = make_args(cx.config, testfile);
236236
ret program_output(cx, testfile, lib_path, procargs.prog, procargs.args,
@@ -239,9 +239,13 @@ fn compose_and_run(cx: &cx, testfile: &str,
239239

240240
fn make_compile_args(config: &config, props: &test_props, testfile: &str) ->
241241
procargs {
242-
let prog = config.rustc_path;
242+
let prog = istr::to_estr(config.rustc_path);
243243
let args = [testfile, "-o", make_exe_name(config, testfile)];
244-
args += split_maybe_args(config.rustcflags);
244+
let rustcflags = alt config.rustcflags {
245+
option::some(s) { option::some(istr::to_estr(s)) }
246+
option::none. { option::none }
247+
};
248+
args += split_maybe_args(rustcflags);
245249
args += split_maybe_args(props.compile_flags);
246250
ret {prog: prog, args: args};
247251
}
@@ -252,13 +256,15 @@ fn make_exe_name(config: &config, testfile: &str) -> str {
252256

253257
fn make_run_args(config: &config, props: &test_props, testfile: &str) ->
254258
procargs {
255-
let toolargs =
256-
if !props.no_valgrind {
257-
258-
// If we've got another tool to run under (valgrind),
259-
// then split apart its command
260-
split_maybe_args(config.runtool)
261-
} else { [] };
259+
let toolargs = if !props.no_valgrind {
260+
// If we've got another tool to run under (valgrind),
261+
// then split apart its command
262+
let runtool = alt config.runtool {
263+
option::some(s) { option::some(istr::to_estr(s)) }
264+
option::none. { option::none }
265+
};
266+
split_maybe_args(runtool)
267+
} else { [] };
262268

263269
let args = toolargs + [make_exe_name(config, testfile)];
264270
ret {prog: args[0], args: vec::slice(args, 1u, vec::len(args))};
@@ -284,8 +290,9 @@ fn split_maybe_args(argstr: &option::t<str>) -> [str] {
284290
}
285291
}
286292

287-
fn program_output(cx: &cx, testfile: &str, lib_path: &str, prog: &str,
293+
fn program_output(cx: &cx, testfile: &str, lib_path: &istr, prog: &str,
288294
args: &[str], input: option::t<str>) -> procres {
295+
let lib_path = istr::to_estr(lib_path);
289296
let cmdline =
290297
{
291298
let cmdline = make_cmdline(lib_path, prog, args);
@@ -337,15 +344,16 @@ fn make_out_name(config: &config, testfile: &str, extension: &str) -> str {
337344
}
338345

339346
fn output_base_name(config: &config, testfile: &str) -> str {
340-
let base = config.build_base;
347+
let base = istr::to_estr(config.build_base);
341348
let filename =
342349
{
343350
let parts = istr::split(fs::basename(istr::from_estr(testfile)),
344351
'.' as u8);
345352
parts = vec::slice(parts, 0u, vec::len(parts) - 1u);
346353
istr::connect(parts, ~".")
347354
};
348-
#fmt["%s%s.%s", base, istr::to_estr(filename), config.stage_id]
355+
#fmt["%s%s.%s", base, istr::to_estr(filename),
356+
istr::to_estr(config.stage_id)]
349357
}
350358

351359
fn maybe_dump_to_stdout(config: &config, out: &str, err: &str) {

0 commit comments

Comments
 (0)