-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rustpkg: Factor out tests; use a condition instead of returning an op…
…tion Pulled out tests into their own modules inside the files they test, as per the draft style guidelines. Started a new module, path_util, for utility functions to do with paths and directories. Changed default_dest_dir to use a condition and return Path instead of Option<Path>.
- Loading branch information
1 parent
74fee15
commit 884c7c9
Showing
5 changed files
with
138 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Useful conditions | ||
|
||
pub use core::path::Path; | ||
|
||
condition! { | ||
bad_path: (super::Path, ~str) -> super::Path; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// rustpkg utilities having to do with paths and directories | ||
|
||
use core::path::*; | ||
use core::os; | ||
use util::PkgId; | ||
|
||
/// Returns the output directory to use. | ||
/// Right now is always the default, should | ||
/// support changing it. | ||
pub fn dest_dir(pkgid: PkgId) -> Path { | ||
default_dest_dir(&pkgid.path) | ||
} | ||
|
||
/// Returns the default output directory for compilation. | ||
/// Creates that directory if it doesn't exist. | ||
pub fn default_dest_dir(pkg_dir: &Path) -> Path { | ||
use core::libc::consts::os::posix88::{S_IRUSR, S_IWUSR, S_IXUSR}; | ||
use conditions::bad_path::cond; | ||
|
||
// For now: assumes that pkg_dir exists and is relative | ||
// to the CWD. Change this later when we do path searching. | ||
let rslt = pkg_dir.push("build"); | ||
let is_dir = os::path_is_dir(&rslt); | ||
if os::path_exists(&rslt) { | ||
if is_dir { | ||
rslt | ||
} | ||
else { | ||
cond.raise((rslt, ~"Path names a file that isn't a directory")) | ||
} | ||
} | ||
else { | ||
// Create it | ||
if os::make_dir(&rslt, (S_IRUSR | S_IWUSR | S_IXUSR) as i32) { | ||
rslt | ||
} | ||
else { | ||
cond.raise((rslt, ~"Could not create directory")) | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use core::{os, rand}; | ||
use core::path::Path; | ||
use core::rand::RngUtil; | ||
use path_util::*; | ||
|
||
// Helper function to create a directory name that doesn't exist | ||
pub fn mk_nonexistent(tmpdir: &Path, suffix: &str) -> Path { | ||
let r = rand::Rng(); | ||
for 1000.times { | ||
let p = tmpdir.push(r.gen_str(16) + suffix); | ||
if !os::path_exists(&p) { | ||
return p; | ||
} | ||
} | ||
fail!(~"Couldn't compute a non-existent path name; this is worrisome") | ||
} | ||
#[test] | ||
fn default_dir_ok() { | ||
let the_path = os::tmpdir(); | ||
let substitute_path = Path("xyzzy"); | ||
assert!(default_dest_dir(&the_path) == the_path.push(~"build")); | ||
let nonexistent_path = mk_nonexistent(&the_path, "quux"); | ||
let bogus = do ::conditions::bad_path::cond.trap(|_| { | ||
substitute_path | ||
}).in { default_dest_dir(&nonexistent_path) }; | ||
assert!(bogus == substitute_path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// rustpkg unit tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
884c7c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from graydon
at catamorphism@884c7c9
884c7c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging catamorphism/rust/rustpkg = 884c7c9 into auto
884c7c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
catamorphism/rust/rustpkg = 884c7c9 merged ok, testing candidate = 0cde4ffd
884c7c9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some tests failed:
http://buildbot.rust-lang.org/builders/auto-linux/builds/839