Skip to content

Commit a7515c8

Browse files
committed
Have workcache::test put foo.c in the same directory it runs in.
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.
1 parent 2de2fb1 commit a7515c8

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

Diff for: src/libextra/workcache.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -496,16 +496,23 @@ fn test() {
496496
use std::io::WriterUtil;
497497
use std::{os, run};
498498

499-
let pth = Path("foo.c");
499+
// Create a path to a new file 'filename' in the directory in which
500+
// this test is running.
501+
fn make_path(filename: ~str) -> Path {
502+
let pth = os::self_exe_path().expect("workcache::test failed").pop().push(filename);
503+
if os::path_exists(&pth) {
504+
os::remove_file(&pth);
505+
}
506+
return pth;
507+
}
508+
509+
let pth = make_path(~"foo.c");
500510
{
501511
let r = io::file_writer(&pth, [io::Create]);
502512
r.unwrap().write_str("int main() { return 0; }");
503513
}
504514

505-
let db_path = os::self_exe_path().expect("workcache::test failed").pop().push("db.json");
506-
if os::path_exists(&db_path) {
507-
os::remove_file(&db_path);
508-
}
515+
let db_path = make_path(~"db.json");
509516

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

516523
let subcx = cx.clone();
524+
let pth = pth.clone();
517525

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

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

526534
out.to_str()
527535
}
528536
};
537+
529538
io::println(s);
530539
}

0 commit comments

Comments
 (0)