Skip to content

Commit

Permalink
Have workcache::test put foo.c in the same directory it runs in.
Browse files Browse the repository at this point in the history
This prevents a stray `foo.c` from being left lying around after tests
run, and it's more consistent with the rest of the code.
  • Loading branch information
lkuper committed Sep 16, 2013
1 parent 2de2fb1 commit a7515c8
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/libextra/workcache.rs
Expand Up @@ -496,16 +496,23 @@ fn test() {
use std::io::WriterUtil;
use std::{os, run};

let pth = Path("foo.c");
// Create a path to a new file 'filename' in the directory in which
// this test is running.
fn make_path(filename: ~str) -> Path {
let pth = os::self_exe_path().expect("workcache::test failed").pop().push(filename);
if os::path_exists(&pth) {
os::remove_file(&pth);
}
return pth;
}

let pth = make_path(~"foo.c");
{
let r = io::file_writer(&pth, [io::Create]);
r.unwrap().write_str("int main() { return 0; }");
}

let db_path = os::self_exe_path().expect("workcache::test failed").pop().push("db.json");
if os::path_exists(&db_path) {
os::remove_file(&db_path);
}
let db_path = make_path(~"db.json");

let cx = Context::new(RWArc::new(Database::new(db_path)),
RWArc::new(Logger::new()),
Expand All @@ -514,17 +521,19 @@ fn test() {
let s = do cx.with_prep("test1") |prep| {

let subcx = cx.clone();
let pth = pth.clone();

prep.declare_input("file", pth.to_str(), digest_file(&pth));
do prep.exec |_exe| {
let out = Path("foo.o");
run::process_status("gcc", [~"foo.c", ~"-o", out.to_str()]);
let out = make_path(~"foo.o");
run::process_status("gcc", [pth.to_str(), ~"-o", out.to_str()]);

let _proof_of_concept = subcx.prep("subfn");
// Could run sub-rules inside here.

out.to_str()
}
};

io::println(s);
}

5 comments on commit a7515c8

@bors
Copy link
Contributor

@bors bors commented on a7515c8 Sep 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from alexcrichton
at lkuper@a7515c8

@bors
Copy link
Contributor

@bors bors commented on a7515c8 Sep 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging lkuper/rust/workcache = a7515c8 into auto

@bors
Copy link
Contributor

@bors bors commented on a7515c8 Sep 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lkuper/rust/workcache = a7515c8 merged ok, testing candidate = 250c3d4

@bors
Copy link
Contributor

@bors bors commented on a7515c8 Sep 16, 2013

@bors
Copy link
Contributor

@bors bors commented on a7515c8 Sep 16, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 250c3d4

Please sign in to comment.