Skip to content

Commit 8ebe416

Browse files
committed
Merge pull request #1564 from elly/cargo
[cargo] refactor test_one_crate
2 parents 1ce288d + 4bd713b commit 8ebe416

File tree

1 file changed

+26
-12
lines changed

1 file changed

+26
-12
lines changed

src/cargo/cargo.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -357,23 +357,37 @@ fn for_each_package(c: cargo, b: block(source, package)) {
357357

358358
// FIXME: deduplicate code with install_one_crate
359359
fn test_one_crate(c: cargo, _path: str, cf: str, _p: pkg) {
360-
let name = fs::basename(cf);
361-
let ri = str::index(name, '.' as u8);
362-
if ri != -1 {
363-
name = str::slice(name, 0u, ri as uint);
364-
}
365-
#debug("Installing: %s", name);
366-
let old = fs::list_dir(".");
367-
let p = run::program_output("rustc", ["--test", name + ".rc"]);
360+
let buildpath = fs::connect(_path, "/test");
361+
need_dir(buildpath);
362+
#debug("Testing: %s -> %s", cf, buildpath);
363+
let p = run::program_output("rustc", ["--out-dir", buildpath, "--test",
364+
cf]);
365+
if p.status != 0 {
366+
error(#fmt["rustc failed: %d\n%s\n%s", p.status, p.err, p.out]);
367+
ret;
368+
}
369+
let new = fs::list_dir(buildpath);
370+
let exec_suffix = os::exec_suffix();
371+
for ct: str in new {
372+
if (exec_suffix != "" && str::ends_with(ct, exec_suffix)) ||
373+
(exec_suffix == "" && !str::starts_with(ct, "./lib")) {
374+
run::run_program(ct, []);
375+
}
376+
}
377+
}
378+
379+
fn install_one_crate(c: cargo, _path: str, cf: str, _p: pkg) {
380+
let buildpath = fs::connect(_path, "/build");
381+
need_dir(buildpath);
382+
#debug("Installing: %s -> %s", cf, buildpath);
383+
let p = run::program_output("rustc", ["--out-dir", buildpath, cf]);
368384
if p.status != 0 {
369385
error(#fmt["rustc failed: %d\n%s\n%s", p.status, p.err, p.out]);
370386
ret;
371387
}
372-
let new = fs::list_dir(".");
373-
let created =
374-
vec::filter::<str>(new, { |n| !vec::member::<str>(n, old) });
388+
let new = fs::list_dir(buildpath);
375389
let exec_suffix = os::exec_suffix();
376-
for ct: str in created {
390+
for ct: str in new {
377391
if (exec_suffix != "" && str::ends_with(ct, exec_suffix)) ||
378392
(exec_suffix == "" && !str::starts_with(ct, "./lib")) {
379393
// FIXME: need libstd fs::copy or something

0 commit comments

Comments
 (0)