}
fn opt_path(m: &getopts::Matches, nm: &str) -> Path {
- Path::new(m.opt_str(nm).unwrap())
+ Path::init(m.opt_str(nm).unwrap())
}
config {
compile_lib_path: matches.opt_str("compile-lib-path").unwrap(),
run_lib_path: matches.opt_str("run-lib-path").unwrap(),
rustc_path: opt_path(matches, "rustc-path"),
- clang_path: matches.opt_str("clang-path").map(|s| Path::new(s)),
- llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::new(s)),
+ clang_path: matches.opt_str("clang-path").map(|s| Path::init(s)),
+ llvm_bin_path: matches.opt_str("llvm-bin-path").map(|s| Path::init(s)),
src_base: opt_path(matches, "src-base"),
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
} else {
None
},
- logfile: matches.opt_str("logfile").map(|s| Path::new(s)),
- save_metrics: matches.opt_str("save-metrics").map(|s| Path::new(s)),
+ logfile: matches.opt_str("logfile").map(|s| Path::init(s)),
+ save_metrics: matches.opt_str("save-metrics").map(|s| Path::init(s)),
ratchet_metrics:
- matches.opt_str("ratchet-metrics").map(|s| Path::new(s)),
+ matches.opt_str("ratchet-metrics").map(|s| Path::init(s)),
ratchet_noise_percent:
matches.opt_str("ratchet-noise-percent").and_then(|s| from_str::<f64>(s)),
runtool: matches.opt_str("runtool"),
fn parse_pp_exact(line: &str, testfile: &Path) -> Option<Path> {
match parse_name_value_directive(line, ~"pp-exact") {
- Some(s) => Some(Path::new(s)),
+ Some(s) => Some(Path::init(s)),
None => {
if parse_name_directive(line, "pp-exact") {
- testfile.filename().map(|s| Path::new(s))
+ testfile.filename().map(|s| Path::init(s))
} else {
None
}
// We're going to be dumping a lot of info. Start on a new line.
print!("\n\n");
}
- let testfile = Path::new(testfile);
+ let testfile = Path::init(testfile);
debug!("running {}", testfile.display());
let props = load_props(&testfile);
debug!("loaded props");
}
fn output_testname(testfile: &Path) -> Path {
- Path::new(testfile.filestem().unwrap())
+ Path::init(testfile.filestem().unwrap())
}
fn output_base_name(config: &config, testfile: &Path) -> Path {
// calculate root this way to handle volume-relative Windows paths correctly
let mut root = os::getcwd();
- let pat_root = Path::new(pattern).root_path();
+ let pat_root = Path::init(pattern).root_path();
if pat_root.is_some() {
if check_windows_verbatim(pat_root.get_ref()) {
// XXX: How do we want to handle verbatim paths? I'm inclined to return nothing,
#[test]
fn test_matches_path() {
- // on windows, (Path::new("a/b").as_str().unwrap() == "a\\b"), so this
+ // on windows, (Path::init("a/b").as_str().unwrap() == "a\\b"), so this
// tests that / and \ are considered equivalent on windows
- assert!(Pattern::new("a/b").matches_path(&Path::new("a/b")));
+ assert!(Pattern::new("a/b").matches_path(&Path::init("a/b")));
}
}
// Find search directory
match getenv("TERMINFO") {
- Some(dir) => dirs_to_search.push(Path::new(dir)),
+ Some(dir) => dirs_to_search.push(Path::init(dir)),
None => {
if homedir.is_some() {
// ncurses compatability;
match getenv("TERMINFO_DIRS") {
Some(dirs) => for i in dirs.split(':') {
if i == "" {
- dirs_to_search.push(Path::new("/usr/share/terminfo"));
+ dirs_to_search.push(Path::init("/usr/share/terminfo"));
} else {
- dirs_to_search.push(Path::new(i.to_owned()));
+ dirs_to_search.push(Path::init(i.to_owned()));
}
},
// Found nothing, use the default paths
// /usr/share/terminfo is the de facto location, but it seems
// Ubuntu puts it in /lib/terminfo
None => {
- dirs_to_search.push(Path::new("/usr/share/terminfo"));
- dirs_to_search.push(Path::new("/lib/terminfo"));
+ dirs_to_search.push(Path::init("/usr/share/terminfo"));
+ dirs_to_search.push(Path::init("/lib/terminfo"));
}
}
}
let run_ignored = matches.opt_present("ignored");
let logfile = matches.opt_str("logfile");
- let logfile = logfile.map(|s| Path::new(s));
+ let logfile = logfile.map(|s| Path::init(s));
let run_benchmarks = matches.opt_present("bench");
let run_tests = ! run_benchmarks ||
matches.opt_present("test");
let ratchet_metrics = matches.opt_str("ratchet-metrics");
- let ratchet_metrics = ratchet_metrics.map(|s| Path::new(s));
+ let ratchet_metrics = ratchet_metrics.map(|s| Path::init(s));
let ratchet_noise_percent = matches.opt_str("ratchet-noise-percent");
let ratchet_noise_percent = ratchet_noise_percent.map(|s| from_str::<f64>(s).unwrap());
let save_metrics = matches.opt_str("save-metrics");
- let save_metrics = save_metrics.map(|s| Path::new(s));
+ let save_metrics = save_metrics.map(|s| Path::init(s));
let test_shard = matches.opt_str("test-shard");
let test_shard = opt_shard(test_shard);
let install_prefix = env!("CFG_PREFIX");
let tlib = filesearch::relative_target_lib_path(target_triple);
- let mut path = Path::new(install_prefix);
+ let mut path = Path::init(install_prefix);
path.push(&tlib);
let path = os::make_absolute(&path);
// FIXME (#9639): This needs to handle non-utf8 paths
#[test]
fn test_prefix_rpath() {
let res = get_install_prefix_rpath("triple");
- let mut d = Path::new(env!("CFG_PREFIX"));
+ let mut d = Path::init(env!("CFG_PREFIX"));
d.push("lib/rustc/triple/lib");
debug!("test_prefix_path: {} vs. {}",
res,
#[test]
fn test_prefix_rpath_abs() {
let res = get_install_prefix_rpath("triple");
- assert!(Path::new(res).is_absolute());
+ assert!(Path::init(res).is_absolute());
}
#[test]
fn test_rpath_relative() {
let o = abi::OsLinux;
let res = get_rpath_relative_to_output(o,
- &Path::new("bin/rustc"), &Path::new("lib/libstd.so"));
+ &Path::init("bin/rustc"), &Path::init("lib/libstd.so"));
assert_eq!(res.as_slice(), "$ORIGIN/../lib");
}
fn test_rpath_relative() {
let o = abi::OsFreebsd;
let res = get_rpath_relative_to_output(o,
- &Path::new("bin/rustc"), &Path::new("lib/libstd.so"));
+ &Path::init("bin/rustc"), &Path::init("lib/libstd.so"));
assert_eq!(res.as_slice(), "$ORIGIN/../lib");
}
fn test_rpath_relative() {
let o = abi::OsMacos;
let res = get_rpath_relative_to_output(o,
- &Path::new("bin/rustc"),
- &Path::new("lib/libstd.so"));
+ &Path::init("bin/rustc"),
+ &Path::init("lib/libstd.so"));
assert_eq!(res.as_slice(), "@loader_path/../lib");
}
#[test]
fn test_get_absolute_rpath() {
- let res = get_absolute_rpath(&Path::new("lib/libstd.so"));
- let lib = os::make_absolute(&Path::new("lib"));
+ let res = get_absolute_rpath(&Path::init("lib/libstd.so"));
+ let lib = os::make_absolute(&Path::init("lib"));
debug!("test_get_absolute_rpath: {} vs. {}",
res.to_str(), lib.display());
} else if matches.opt_present("emit-llvm") {
link::output_type_bitcode
} else { link::output_type_exe };
- let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path::new(m));
+ let sysroot_opt = matches.opt_str("sysroot").map(|m| @Path::init(m));
let target = matches.opt_str("target").unwrap_or(host_triple());
let target_cpu = matches.opt_str("target-cpu").unwrap_or(~"generic");
let target_feature = matches.opt_str("target-feature").unwrap_or(~"");
let statik = debugging_opts & session::statik != 0;
let addl_lib_search_paths = matches.opt_strs("L").map(|s| {
- Path::new(s.as_slice())
+ Path::init(s.as_slice())
}).move_iter().collect();
let linker = matches.opt_str("linker");
let linker_args = matches.opt_strs("link-args").flat_map( |a| {
let src = str::from_utf8(io::stdin().read_to_end());
str_input(src.to_managed())
} else {
- file_input(Path::new(ifile))
+ file_input(Path::init(ifile))
}
}
_ => early_error(demitter, "multiple input filenames provided")
let sopts = build_session_options(binary, matches, demitter);
let sess = build_session(sopts, demitter);
- let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
- let ofile = matches.opt_str("o").map(|o| Path::new(o));
+ let odir = matches.opt_str("out-dir").map(|o| Path::init(o));
+ let ofile = matches.opt_str("o").map(|o| Path::init(o));
let cfg = build_configuration(sess);
let pretty = matches.opt_default("pretty", "normal").map(|a| {
parse_pretty(sess, a)
let meta_items = match path_opt {
None => meta_items.clone(),
Some((p, _path_str_style)) => {
- let p_path = Path::new(p);
+ let p_path = Path::init(p);
match p_path.filestem_str() {
None|Some("") =>
e.diag.span_bug(i.span, "Bad package path in `extern mod` item"),
};
let (lident, ldata) = loader::load_library_crate(&load_ctxt);
- let cfilename = Path::new(lident);
+ let cfilename = Path::init(lident);
let cdata = ldata;
let attrs = decoder::get_crate_attributes(cdata);
pub fn relative_target_lib_path(target_triple: &str) -> Path {
let dir = libdir();
- let mut p = Path::new(dir.as_slice());
+ let mut p = Path::init(dir.as_slice());
assert!(p.is_relative());
p.push("rustc");
p.push(target_triple);
Some(env_path) => {
let env_path_components: ~[&str] =
env_path.split_str(PATH_ENTRY_SEPARATOR).collect();
- env_path_components.map(|&s| Path::new(s))
+ env_path_components.map(|&s| Path::init(s))
}
None => ~[]
};
/// static HTML tree.
// FIXME (#9639): The closure should deal with &[u8] instead of &str
fn clean_srcpath(src: &[u8], f: |&str|) {
- let p = Path::new(src);
+ let p = Path::init(src);
if p.as_vec() != bytes!(".") {
for c in p.str_components().map(|x|x.unwrap()) {
if ".." == c {
impl<'self> SourceCollector<'self> {
/// Renders the given filename into its corresponding HTML source file.
fn emit_source(&mut self, filename: &str) -> bool {
- let p = Path::new(filename);
+ let p = Path::init(filename);
// Read the contents of the file
let mut contents = ~[];
info!("going to format");
let started = time::precise_time_ns();
- let output = matches.opt_str("o").map(|s| Path::new(s));
+ let output = matches.opt_str("o").map(|s| Path::init(s));
match matches.opt_str("w") {
Some(~"html") | None => {
- html::render::run(crate, output.unwrap_or(Path::new("doc")))
+ html::render::run(crate, output.unwrap_or(Path::init("doc")))
}
Some(~"json") => {
- json_output(crate, res, output.unwrap_or(Path::new("doc.json")))
+ json_output(crate, res, output.unwrap_or(Path::init("doc.json")))
}
Some(s) => {
println!("unknown output format: {}", s);
let mut plugins = matches.opt_strs("plugins");
// First, parse the crate and extract all relevant information.
- let libs = Cell::new(matches.opt_strs("L").map(|s| Path::new(s.as_slice())));
+ let libs = Cell::new(matches.opt_strs("L").map(|s| Path::init(s.as_slice())));
let cfgs = Cell::new(matches.opt_strs("cfg"));
- let cr = Cell::new(Path::new(cratefile));
+ let cr = Cell::new(Path::init(cratefile));
info!("starting to run rustc");
let (crate, analysis) = do std::task::try {
let cr = cr.take();
// Load all plugins/passes into a PluginManager
let path = matches.opt_str("plugin-path").unwrap_or(~"/tmp/rustdoc_ng/plugins");
- let mut pm = plugins::PluginManager::new(Path::new(path));
+ let mut pm = plugins::PluginManager::new(Path::init(path));
for pass in passes.iter() {
let plugin = match PASSES.iter().position(|&(p, _, _)| p == *pass) {
Some(i) => PASSES[i].n1(),
/// This input format purely deserializes the json output file. No passes are
/// run over the deserialized output.
fn json_input(input: &str) -> Result<Output, ~str> {
- let input = match File::open(&Path::new(input)) {
+ let input = match File::open(&Path::init(input)) {
Some(f) => f,
None => return Err(format!("couldn't open {} for reading", input)),
};
}
fn file_is_fresh(path: &str, in_hash: &str) -> bool {
- let path = Path::new(path);
+ let path = Path::init(path);
path.exists() && in_hash == digest_file_with_date(&path)
}
fn binary_is_fresh(path: &str, in_hash: &str) -> bool {
- let path = Path::new(path);
+ let path = Path::init(path);
path.exists() && in_hash == digest_only_date(&path)
}
let pkgid = PkgId::new(package_name);
let workspaces = pkg_parent_workspaces(context, &pkgid);
if workspaces.is_empty() {
- bad_pkg_id.raise((Path::new(package_name), package_name.to_owned()));
+ bad_pkg_id.raise((Path::init(package_name), package_name.to_owned()));
}
workspaces[0]
}
})
});
// We always *run* the package script
- let (cfgs, hook_result) = PkgScript::run_custom(&Path::new(pkg_exe), &sysroot);
+ let (cfgs, hook_result) = PkgScript::run_custom(&Path::init(pkg_exe), &sysroot);
debug!("Command return code = {:?}", hook_result);
if !hook_result.success() {
fail!("Error running custom build command")
// Find crates inside the workspace
Everything => pkg_src.find_crates(),
// Find only tests
- Tests => pkg_src.find_crates_with_filter(|s| { is_test(&Path::new(s)) }),
+ Tests => pkg_src.find_crates_with_filter(|s| { is_test(&Path::init(s)) }),
// Don't infer any crates -- just build the one that was requested
JustOne(ref p) => {
// We expect that p is relative to the package source's start directory,
let result = self.install_no_build(pkg_src.build_workspace(),
build_inputs,
&pkg_src.destination_workspace,
- &id).map(|s| Path::new(s.as_slice()));
+ &id).map(|s| Path::init(s.as_slice()));
installed_files = installed_files + result;
note(format!("Installed package {} to {}",
id.to_str(),
}
fn init(&self) {
- fs::mkdir_recursive(&Path::new("src"), io::UserRWX);
- fs::mkdir_recursive(&Path::new("bin"), io::UserRWX);
- fs::mkdir_recursive(&Path::new("lib"), io::UserRWX);
- fs::mkdir_recursive(&Path::new("build"), io::UserRWX);
+ fs::mkdir_recursive(&Path::init("src"), io::UserRWX);
+ fs::mkdir_recursive(&Path::init("bin"), io::UserRWX);
+ fs::mkdir_recursive(&Path::init("lib"), io::UserRWX);
+ fs::mkdir_recursive(&Path::init("build"), io::UserRWX);
}
fn uninstall(&self, _id: &str, _vers: Option<~str>) {
let mut remaining_args: ~[~str] = remaining_args.map(|s| (*s).clone()).collect();
remaining_args.shift();
let sroot = match supplied_sysroot {
- Some(s) => Path::new(s),
+ Some(s) => Path::init(s),
_ => filesearch::get_or_default_sysroot()
};
}
};
- let path = Path::new(s);
+ let path = Path::init(s);
if !path.is_relative() {
return cond.raise((path, ~"absolute pkgid"));
}
let last = self.components.pop();
self.remaining.unshift(last);
// converting to str and then back is a little unfortunate
- Some((Path::new(self.components.connect("/")),
- Path::new(self.remaining.connect("/"))))
+ Some((Path::init(self.components.connect("/")),
+ Path::init(self.remaining.connect("/"))))
}
}
}
it.nth(prefix-1); // skip elements
}
assert!(it.peek().is_some());
- let mut sub = Path::new(".");
+ let mut sub = Path::init(".");
for c in it {
sub.push(c);
}
(k.clone(), p.as_str().unwrap().to_owned()));
prep.exec(proc(exec) {
for &(ref kind, ref p) in inputs.iter() {
- let pth = Path::new(p.clone());
+ let pth = Path::init(p.clone());
exec.discover_input(*kind, *p, if *kind == ~"file" {
digest_file_with_date(&pth)
} else if *kind == ~"binary" {
- digest_only_date(&Path::new(p.clone()))
+ digest_only_date(&Path::init(p.clone()))
} else {
fail!("Bad kind in build_crates")
});
fn fake_pkg() -> PkgId {
let sn = ~"bogus";
PkgId {
- path: Path::new(sn.as_slice()),
+ path: Path::init(sn.as_slice()),
short_name: sn,
version: NoVersion
}
fn git_repo_pkg() -> PkgId {
PkgId {
- path: Path::new("mockgithub.com/catamorphism/test-pkg"),
+ path: Path::init("mockgithub.com/catamorphism/test-pkg"),
short_name: ~"test-pkg",
version: NoVersion
}
fn git_repo_pkg_with_tag(a_tag: ~str) -> PkgId {
PkgId {
- path: Path::new("mockgithub.com/catamorphism/test-pkg"),
+ path: Path::init("mockgithub.com/catamorphism/test-pkg"),
short_name: ~"test-pkg",
version: Tagged(a_tag)
}
fn lib_output_file_name(workspace: &Path, short_name: &str) -> Path {
debug!("lib_output_file_name: given {} and short name {}",
workspace.display(), short_name);
- library_in_workspace(&Path::new(short_name),
+ library_in_workspace(&Path::init(short_name),
short_name,
Build,
workspace,
});
cond.trap(|(p, e)| {
- let abs = os::make_absolute(&Path::new("foo/bar/quux"));
+ let abs = os::make_absolute(&Path::init("foo/bar/quux"));
assert_eq!(p, abs);
assert!("absolute pkgid" == e);
whatever.clone()
}).inside(|| {
- let zp = os::make_absolute(&Path::new("foo/bar/quux"));
+ let zp = os::make_absolute(&Path::init("foo/bar/quux"));
// FIXME (#9639): This needs to handle non-utf8 paths
let z = PkgId::new(zp.as_str().unwrap());
assert_eq!(~"foo-0.1", z.to_str());
#[test]
fn test_package_version() {
let local_path = "mockgithub.com/catamorphism/test_pkg_version";
- let repo = init_git_repo(&Path::new(local_path));
+ let repo = init_git_repo(&Path::init(local_path));
let repo = repo.path();
let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test_pkg_version"]);
debug!("Writing files in: {}", repo_subdir.display());
#[test]
fn test_package_request_version() {
let local_path = "mockgithub.com/catamorphism/test_pkg_version";
- let repo = init_git_repo(&Path::new(local_path));
+ let repo = init_git_repo(&Path::init(local_path));
let repo = repo.path();
let repo_subdir = repo.join_many(["mockgithub.com", "catamorphism", "test_pkg_version"]);
debug!("Writing files in: {}", repo_subdir.display());
command_line_test([~"install", format!("{}\\#0.3", local_path)], repo);
- assert!(match installed_library_in_workspace(&Path::new("test_pkg_version"),
+ assert!(match installed_library_in_workspace(&Path::init("test_pkg_version"),
&repo.join(".rust")) {
Some(p) => {
debug!("installed: {}", p.display());
== repo.join_many([".rust", "bin", "test_pkg_version"]));
let mut dir = target_build_dir(&repo.join(".rust"));
- dir.push(&Path::new("src/mockgithub.com/catamorphism/test_pkg_version-0.3"));
+ dir.push(&Path::init("src/mockgithub.com/catamorphism/test_pkg_version-0.3"));
debug!("dir = {}", dir.display());
assert!(dir.is_dir());
assert!(dir.join("version-0.3-file.txt").exists());
#[test]
fn rustpkg_library_target() {
- let foo_repo = init_git_repo(&Path::new("foo"));
+ let foo_repo = init_git_repo(&Path::init("foo"));
let foo_repo = foo_repo.path();
let package_dir = foo_repo.join("foo");
add_git_tag(&package_dir, ~"1.0");
command_line_test([~"install", ~"foo"], foo_repo);
- assert_lib_exists(&foo_repo.join(".rust"), &Path::new("foo"), ExactRevision(~"1.0"));
+ assert_lib_exists(&foo_repo.join(".rust"), &Path::init("foo"), ExactRevision(~"1.0"));
}
#[test]
}
#[test]
+#[ignore(reason="busted")]
fn package_script_with_default_build() {
let dir = create_local_package(&PkgId::new("fancy-lib"));
let dir = dir.path();
debug!("dir = {}", dir.display());
let mut source = test_sysroot().dir_path();
source.pop(); source.pop();
- let source = Path::new(file!()).dir_path().join_many(
+ let source = Path::init(file!()).dir_path().join_many(
[~"testsuite", ~"pass", ~"src", ~"fancy-lib", ~"pkg.rs"]);
debug!("package_script_with_default_build: {}", source.display());
fs::copy(&source, &dir.join_many(["src", "fancy-lib-0.1", "pkg.rs"]));
command_line_test([~"install", ~"fancy-lib"], dir);
- assert_lib_exists(dir, &Path::new("fancy-lib"), NoVersion);
+ assert_lib_exists(dir, &Path::init("fancy-lib"), NoVersion);
assert!(target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]).exists());
let generated_path = target_build_dir(dir).join_many([~"fancy-lib", ~"generated.rs"]);
debug!("generated path = {}", generated_path.display());
"fn main() { let _x = (); }");
debug!("install_no_arg: dir = {}", package_dir.display());
command_line_test([~"install"], &package_dir);
- assert_lib_exists(&tmp, &Path::new("foo"), NoVersion);
+ assert_lib_exists(&tmp, &Path::init("foo"), NoVersion);
}
#[test]
#[test]
fn rust_path_test() {
let dir_for_path = TempDir::new("more_rust").expect("rust_path_test failed");
- let dir = mk_workspace(dir_for_path.path(), &Path::new("foo"), &NoVersion);
+ let dir = mk_workspace(dir_for_path.path(), &Path::init("foo"), &NoVersion);
debug!("dir = {}", dir.display());
writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }");
fn rust_path_parse() {
os::setenv("RUST_PATH", "/a/b/c:/d/e/f:/g/h/i");
let paths = rust_path();
- assert!(paths.contains(&Path::new("/g/h/i")));
- assert!(paths.contains(&Path::new("/d/e/f")));
- assert!(paths.contains(&Path::new("/a/b/c")));
+ assert!(paths.contains(&Path::init("/g/h/i")));
+ assert!(paths.contains(&Path::init("/d/e/f")));
+ assert!(paths.contains(&Path::init("/a/b/c")));
os::unsetenv("RUST_PATH");
}
// Copy the exact same package into directory B and install it
// Set the RUST_PATH to A:B
// Make a third package that uses foo, make sure we can build/install it
- let (a_loc, _pkg_dir) = mk_temp_workspace(&Path::new("foo"), &NoVersion);
- let (b_loc, _pkg_dir) = mk_temp_workspace(&Path::new("foo"), &NoVersion);
+ let (a_loc, _pkg_dir) = mk_temp_workspace(&Path::init("foo"), &NoVersion);
+ let (b_loc, _pkg_dir) = mk_temp_workspace(&Path::init("foo"), &NoVersion);
let (a_loc, b_loc) = (a_loc.path(), b_loc.path());
debug!("Trying to install foo in {}", a_loc.display());
command_line_test([~"install", ~"foo"], a_loc);
let p_id = PkgId::new("foo");
let workspace = create_local_package(&p_id);
let workspace = workspace.path();
- let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+ let dest_workspace = mk_empty_workspace(&Path::init("bar"), &NoVersion, "dest_workspace");
let dest_workspace = dest_workspace.path();
let foo_path = workspace.join_many(["src", "foo-0.1"]);
let rust_path = Some(~[(~"RUST_PATH",
foo_path.as_str().unwrap()))]);
command_line_test_with_env(~[~"install"] + if hack_flag { ~[~"--rust-path-hack"] } else { ~[] } +
~[~"foo"], dest_workspace, rust_path);
- assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion);
+ assert_lib_exists(dest_workspace, &Path::init("foo"), NoVersion);
assert_executable_exists(dest_workspace, "foo");
assert_built_library_exists(dest_workspace, "foo");
assert_built_executable_exists(dest_workspace, "foo");
- assert!(!lib_exists(workspace, &Path::new("foo"), NoVersion));
+ assert!(!lib_exists(workspace, &Path::init("foo"), NoVersion));
assert!(!executable_exists(workspace, "foo"));
assert!(!built_library_exists(workspace, "foo"));
assert!(!built_executable_exists(workspace, "foo"));
fs::mkdir_recursive(&cwd, io::UserRWX);
writeFile(&cwd.join("lib.rs"), "pub fn f() { }");
- let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+ let dest_workspace = mk_empty_workspace(&Path::init("bar"), &NoVersion, "dest_workspace");
let dest_workspace = dest_workspace.path();
// FIXME (#9639): This needs to handle non-utf8 paths
let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]);
command_line_test_with_env([~"install", ~"--rust-path-hack", ~"foo"], &cwd, rust_path);
debug!("Checking that foo exists in {}", dest_workspace.display());
- assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion);
+ assert_lib_exists(dest_workspace, &Path::init("foo"), NoVersion);
assert_built_library_exists(dest_workspace, "foo");
- assert!(!lib_exists(&cwd, &Path::new("foo"), NoVersion));
+ assert!(!lib_exists(&cwd, &Path::init("foo"), NoVersion));
assert!(!built_library_exists(&cwd, "foo"));
}
writeFile(&subdir.join("lib.rs"), "pub fn f() { }");
let name = ~"foo/bar/quux";
- let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+ let dest_workspace = mk_empty_workspace(&Path::init("bar"), &NoVersion, "dest_workspace");
let dest_workspace = dest_workspace.path();
// FIXME (#9639): This needs to handle non-utf8 paths
let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]);
command_line_test_with_env([~"install", ~"--rust-path-hack", name.clone()], &subdir, rust_path);
debug!("Checking that {} exists in {}", name, dest_workspace.display());
- assert_lib_exists(dest_workspace, &Path::new("quux"), NoVersion);
+ assert_lib_exists(dest_workspace, &Path::init("quux"), NoVersion);
assert_built_library_exists(dest_workspace, name);
- assert!(!lib_exists(&subdir, &Path::new("quux"), NoVersion));
+ assert!(!lib_exists(&subdir, &Path::init("quux"), NoVersion));
assert!(!built_library_exists(&subdir, name));
}
assert!(make_dir_rwx(&source_dir));
writeFile(&source_dir.join("lib.rs"), "pub fn f() { }");
- let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+ let dest_workspace = mk_empty_workspace(&Path::init("bar"), &NoVersion, "dest_workspace");
let dest_workspace = dest_workspace.path();
// FIXME (#9639): This needs to handle non-utf8 paths
let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]);
command_line_test_with_env([~"install", ~"--rust-path-hack"], &source_dir, rust_path);
debug!("Checking that foo exists in {}", dest_workspace.display());
- assert_lib_exists(dest_workspace, &Path::new("foo"), NoVersion);
+ assert_lib_exists(dest_workspace, &Path::init("foo"), NoVersion);
assert_built_library_exists(dest_workspace, "foo");
- assert!(!lib_exists(&source_dir, &Path::new("foo"), NoVersion));
+ assert!(!lib_exists(&source_dir, &Path::init("foo"), NoVersion));
assert!(!built_library_exists(cwd, "foo"));
}
assert!(make_dir_rwx(&source_dir));
writeFile(&source_dir.join("lib.rs"), "pub fn f() { }");
- let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+ let dest_workspace = mk_empty_workspace(&Path::init("bar"), &NoVersion, "dest_workspace");
let dest_workspace = dest_workspace.path();
// FIXME (#9639): This needs to handle non-utf8 paths
let rust_path = Some(~[(~"RUST_PATH", dest_workspace.as_str().unwrap().to_owned())]);
fn rust_path_install_target() {
let dir_for_path = TempDir::new(
"source_workspace").expect("rust_path_install_target failed");
- let mut dir = mk_workspace(dir_for_path.path(), &Path::new("foo"), &NoVersion);
+ let mut dir = mk_workspace(dir_for_path.path(), &Path::init("foo"), &NoVersion);
debug!("dir = {}", dir.display());
writeFile(&dir.join("main.rs"), "fn main() { let _x = (); }");
let dir_to_install_to = TempDir::new(
workspace, None, BAD_FLAG_CODE);
assert!(!built_executable_exists(workspace, "foo"));
assert!(!object_file_exists(workspace, "foo"));
- assert!(!lib_exists(workspace, &Path::new("foo"), NoVersion));
+ assert!(!lib_exists(workspace, &Path::init("foo"), NoVersion));
}
}
command_line_test_with_env([~"install", ~"a"],
a_workspace,
environment);
- assert_lib_exists(a_workspace, &Path::new("a"), NoVersion);
- assert_lib_exists(b_workspace, &Path::new("b"), NoVersion);
- assert_lib_exists(b_workspace, &Path::new("c"), NoVersion);
+ assert_lib_exists(a_workspace, &Path::init("a"), NoVersion);
+ assert_lib_exists(b_workspace, &Path::init("b"), NoVersion);
+ assert_lib_exists(b_workspace, &Path::init("c"), NoVersion);
}
#[test]
let p_id = PkgId::new("foo");
let second_workspace = create_local_package(&p_id);
let second_workspace = second_workspace.path();
- let first_workspace = mk_empty_workspace(&Path::new("p"), &NoVersion, "dest");
+ let first_workspace = mk_empty_workspace(&Path::init("p"), &NoVersion, "dest");
let first_workspace = first_workspace.path();
// FIXME (#9639): This needs to handle non-utf8 paths
let rust_path = Some(~[(~"RUST_PATH",
~"foo"],
workspace);
assert!(workspace.join_many([~"lib", host_triple()]).is_dir());
- assert_lib_exists(workspace, &Path::new("foo"), NoVersion);
+ assert_lib_exists(workspace, &Path::init("foo"), NoVersion);
assert!(fs::readdir(&workspace.join("lib")).len() == 1);
assert!(workspace.join("bin").is_dir());
assert_executable_exists(workspace, "foo");
let bar_id = PkgId::new("bar");
let foo_workspace = create_local_package(&foo_id);
let foo_workspace = foo_workspace.path();
- let dest_workspace = mk_empty_workspace(&Path::new("bar"), &NoVersion, "dest_workspace");
+ let dest_workspace = mk_empty_workspace(&Path::init("bar"), &NoVersion, "dest_workspace");
let dest_workspace = dest_workspace.path();
writeFile(&dest_workspace.join_many(["src", "bar-0.1", "main.rs"]),
}
#[test]
+#[ignore(reason="busted")]
fn test_c_dependency_ok() {
// Pkg has a custom build script that adds a single C file as a dependency, and
// registers a hook to build it if it's not fresh
writeFile(&dir.join_many(["src", "cdep-0.1", "foo.c"]), "void f() {}");
debug!("dir = {}", dir.display());
- let source = Path::new(file!()).dir_path().join_many(
+ let source = Path::init(file!()).dir_path().join_many(
[~"testsuite", ~"pass", ~"src", ~"c-dependencies", ~"pkg.rs"]);
fs::copy(&source, &dir.join_many([~"src", ~"cdep-0.1", ~"pkg.rs"]));
command_line_test([~"build", ~"cdep"], dir);
}
#[test]
+#[ignore(reason="busted")]
fn test_c_dependency_no_rebuilding() {
let dir = create_local_package(&PkgId::new("cdep"));
let dir = dir.path();
writeFile(&dir.join_many(["src", "cdep-0.1", "foo.c"]), "void f() {}");
debug!("dir = {}", dir.display());
- let source = Path::new(file!()).dir_path().join_many(
+ let source = Path::init(file!()).dir_path().join_many(
[~"testsuite", ~"pass", ~"src", ~"c-dependencies", ~"pkg.rs"]);
fs::copy(&source, &dir.join_many([~"src", ~"cdep-0.1", ~"pkg.rs"]));
command_line_test([~"build", ~"cdep"], dir);
}
#[test]
+#[ignore(reason="busted")]
fn test_c_dependency_yes_rebuilding() {
let dir = create_local_package(&PkgId::new("cdep"));
let dir = dir.path();
let c_file_name = dir.join_many(["src", "cdep-0.1", "foo.c"]);
writeFile(&c_file_name, "void f() {}");
- let source = Path::new(file!()).dir_path().join_many(
+ let source = Path::init(file!()).dir_path().join_many(
[~"testsuite", ~"pass", ~"src", ~"c-dependencies", ~"pkg.rs"]);
let target = dir.join_many([~"src", ~"cdep-0.1", ~"pkg.rs"]);
debug!("Copying {} -> {}", source.display(), target.display());
self.context.install(
pkg_src,
&WhatToBuild::new(Inferred,
- JustOne(Path::new(lib_crate_filename))));
+ JustOne(Path::init(lib_crate_filename))));
debug!("Installed {}, returned {:?} dependencies and \
{:?} transitive dependencies",
lib_name, outputs_disc.len(), inputs_disc.len());
self.exec.discover_input(*what,
*dep,
digest_file_with_date(
- &Path::new(dep.as_slice())));
+ &Path::init(dep.as_slice())));
} else if *what == ~"binary" {
add_dep(self.deps,
self.parent_crate.as_str().unwrap().to_owned(),
self.exec.discover_input(*what,
*dep,
digest_only_date(
- &Path::new(dep.as_slice())));
+ &Path::init(dep.as_slice())));
} else {
fail!("Bad kind: {}", *what);
}
}).map(|req| unsafe {
let mut paths = ~[];
let path = CString::new(path.with_ref(|p| p), false);
- let parent = Path::new(path);
+ let parent = Path::init(path);
c_str::from_c_multistring(req.get_ptr() as *libc::c_char,
Some(req.get_result() as uint),
|rel| {
uvll::uv_fs_readlink(loop_.handle, req,
path.with_ref(|p| p), cb)
}).map(|req| {
- Path::new(unsafe {
+ Path::init(unsafe {
CString::new(req.get_ptr() as *libc::c_char, false)
})
})
pub fn mkstat(&self) -> FileStat {
let path = unsafe { uvll::get_path_from_fs_req(self.req) };
- let path = unsafe { Path::new(CString::new(path, false)) };
+ let path = unsafe { Path::init(CString::new(path, false)) };
let stat = self.get_stat();
fn to_msec(stat: uvll::uv_timespec_t) -> u64 {
// Be sure to cast to u64 first to prevent overflowing if the tv_sec
use std::io::{File, fs};
- let path = Path::new("foo.txt");
+ let path = Path::init("foo.txt");
// create the file, whether it exists or not
let mut file = File::create(&path);
file.read_to_end();
println!("{}", path.stat().size);
- fs::symlink(&path, &Path::new("bar.txt"));
+ fs::symlink(&path, &Path::init("bar.txt"));
fs::unlink(&path);
*/
///
/// use std::io::{File, io_error, Open, ReadWrite};
///
- /// let p = Path::new("/some/file/path.txt");
+ /// let p = Path::init("/some/file/path.txt");
///
/// io_error::cond.trap(|_| {
/// // hoo-boy...
///
/// use std::io::File;
///
- /// let contents = File::open(&Path::new("foo.txt")).read_to_end();
+ /// let contents = File::open(&Path::init("foo.txt")).read_to_end();
pub fn open(path: &Path) -> Option<File> {
File::open_mode(path, Open, Read)
}
///
/// use std::io::File;
///
- /// let mut f = File::create(&Path::new("foo.txt"));
+ /// let mut f = File::create(&Path::init("foo.txt"));
/// f.write(bytes!("This is a sample file"));
pub fn create(path: &Path) -> Option<File> {
File::open_mode(path, Truncate, Write)
///
/// use std::io::fs;
///
-/// let p = Path::new("/some/file/path.txt");
+/// let p = Path::init("/some/file/path.txt");
/// fs::unlink(&p);
/// // if we made it here without failing, then the
/// // unlink operation was successful
/// use std::io;
/// use std::io::fs;
///
-/// let p = Path::new("/some/file/path.txt");
+/// let p = Path::init("/some/file/path.txt");
/// match io::result(|| fs::stat(&p)) {
/// Ok(stat) => { /* ... */ }
/// Err(e) => { /* handle error */ }
fn dummystat() -> FileStat {
FileStat {
- path: Path::new(""),
+ path: Path::init(""),
size: 0,
kind: io::TypeFile,
perm: 0,
///
/// use std::io::fs;
///
-/// fs::rename(&Path::new("foo"), &Path::new("bar"));
+/// fs::rename(&Path::init("foo"), &Path::init("bar"));
/// // Oh boy, nothing was raised!
///
/// # Errors
///
/// use std::io::fs;
///
-/// fs::copy(&Path::new("foo.txt"), &Path::new("bar.txt"));
+/// fs::copy(&Path::init("foo.txt"), &Path::init("bar.txt"));
/// // Oh boy, nothing was raised!
///
/// # Errors
/// use std::io;
/// use std::io::fs;
///
-/// fs::chmod(&Path::new("file.txt"), io::UserFile);
-/// fs::chmod(&Path::new("file.txt"), io::UserRead | io::UserWrite);
-/// fs::chmod(&Path::new("dir"), io::UserDir);
-/// fs::chmod(&Path::new("file.exe"), io::UserExec);
+/// fs::chmod(&Path::init("file.txt"), io::UserFile);
+/// fs::chmod(&Path::init("file.txt"), io::UserRead | io::UserWrite);
+/// fs::chmod(&Path::init("dir"), io::UserDir);
+/// fs::chmod(&Path::init("file.exe"), io::UserExec);
///
/// # Errors
///
/// use std::libc::S_IRWXU;
/// use std::io::fs;
///
-/// let p = Path::new("/some/dir");
+/// let p = Path::init("/some/dir");
/// fs::mkdir(&p, S_IRWXU as int);
/// // If we got here, our directory exists! Horray!
///
///
/// use std::io::fs;
///
-/// let p = Path::new("/some/dir");
+/// let p = Path::init("/some/dir");
/// fs::rmdir(&p);
/// // good riddance, you mean ol' directory
///
})
test!(fn recursive_mkdir_slash() {
- mkdir_recursive(&Path::new("/"), io::UserRWX);
+ mkdir_recursive(&Path::init("/"), io::UserRWX);
})
test!(fn unicode_path_is_dir() {
- assert!(Path::new(".").is_dir());
- assert!(!Path::new("test/stdtest/fs.rs").is_dir());
+ assert!(Path::init(".").is_dir());
+ assert!(!Path::init("test/stdtest/fs.rs").is_dir());
let tmpdir = tmpdir();
})
test!(fn unicode_path_exists() {
- assert!(Path::new(".").exists());
- assert!(!Path::new("test/nonexistent-bogus-path").exists());
+ assert!(Path::init(".").exists());
+ assert!(!Path::init("test/nonexistent-bogus-path").exists());
let tmpdir = tmpdir();
let unicode = tmpdir.clone();
let unicode = unicode.join(format!("test-각丁ー再见"));
mkdir(&unicode, io::UserRWX);
assert!(unicode.exists());
- assert!(!Path::new("test/unicode-bogus-path-각丁ー再见").exists());
+ assert!(!Path::init("test/unicode-bogus-path-각丁ー再见").exists());
})
test!(fn copy_file_does_not_exist() {
- let from = Path::new("test/nonexistent-bogus-path");
- let to = Path::new("test/other-bogus-path");
+ let from = Path::init("test/nonexistent-bogus-path");
+ let to = Path::init("test/other-bogus-path");
match io::result(|| copy(&from, &to)) {
Ok(..) => fail!(),
Err(..) => {
///
/// # Example
///
- /// let reader = File::open(&Path::new("foo.txt"))
+ /// let reader = File::open(&Path::init("foo.txt"))
/// while !reader.eof() {
/// println(reader.read_line());
/// }
self.seek(orig_pos as i64, io::SeekSet);
return ret;
}
+
#[cfg(unix)]
fn truncate(&mut self, offset: i64) -> Result<(), IoError> {
super::mkerr_libc(unsafe {
pub fn readdir(p: &CString) -> IoResult<~[Path]> {
fn prune(root: &CString, dirs: ~[Path]) -> ~[Path] {
let root = unsafe { CString::new(root.with_ref(|p| p), false) };
- let root = Path::new(root);
+ let root = Path::init(root);
dirs.move_iter().filter(|path| {
path.as_vec() != bytes!(".") && path.as_vec() != bytes!("..")
let mut entry_ptr = readdir(dir_ptr);
while (entry_ptr as uint != 0) {
let cstr = CString::new(rust_list_dir_val(entry_ptr), false);
- paths.push(Path::new(cstr));
+ paths.push(Path::init(cstr));
entry_ptr = readdir(dir_ptr);
}
closedir(dir_ptr);
fn rust_list_dir_wfd_fp_buf(wfd: *libc::c_void) -> *u16;
}
let p = CString::new(p.with_ref(|p| p), false);
- let p = Path::new(p);
+ let p = Path::init(p);
let star = p.join("*");
as_utf16_p(star.as_str().unwrap(), |path_ptr| {
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
let fp_vec = vec::from_buf(
fp_buf, wcslen(fp_buf) as uint);
let fp_str = str::from_utf16(fp_vec);
- paths.push(Path::new(fp_str));
+ paths.push(Path::init(fp_str));
}
more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);
}
}
});
let ret = match ret {
- Some(s) => Ok(Path::new(s)),
+ Some(s) => Ok(Path::init(s)),
None => Err(super::last_error()),
};
unsafe { libc::CloseHandle(handle) };
n => {
assert!(n > 0);
unsafe { vec::raw::set_len(&mut buf, n as uint); }
- Ok(Path::new(buf))
+ Ok(Path::init(buf))
}
}
}
};
io::FileStat {
- path: Path::new(path),
+ path: Path::init(path),
size: stat.st_size as u64,
kind: kind,
perm: (stat.st_mode) as io::FilePermission & io::AllPermissions,
fn gen(_stat: &libc::stat) -> u64 { 0 }
io::FileStat {
- path: Path::new(path),
+ path: Path::init(path),
size: stat.st_size as u64,
kind: kind,
perm: (stat.st_mode) as io::FilePermission & io::AllPermissions,
let (err_pipe, err_fd) = get_io(config.io, &mut ret_io, 2);
let env = config.env.map(|a| a.to_owned());
- let cwd = config.cwd.map(|a| Path::new(a));
+ let cwd = config.cwd.map(|a| Path::init(a));
let res = spawn_process_os(config.program, config.args, env,
cwd.as_ref(), in_fd, out_fd, err_fd);
fail!()
}
- Path::new(CString::new(buf as *c_char, false))
+ Path::init(CString::new(buf as *c_char, false))
}
})
}
}
}
});
- Path::new(str::from_utf16(buf))
+ Path::init(str::from_utf16(buf))
}
#[cfg(windows)]
fn load_self() -> Option<~[u8]> {
use std::io;
- match io::result(|| io::fs::readlink(&Path::new("/proc/self/exe"))) {
+ match io::result(|| io::fs::readlink(&Path::init("/proc/self/exe"))) {
Ok(Some(path)) => Some(path.as_vec().to_owned()),
Ok(None) | Err(..) => None
}
}
}
- load_self().and_then(|path| Path::new_opt(path).map(|mut p| { p.pop(); p }))
+ load_self().and_then(|path| Path::init_opt(path).map(|mut p| { p.pop(); p }))
}
/**
pub fn homedir() -> Option<Path> {
// FIXME (#7188): getenv needs a ~[u8] variant
return match getenv("HOME") {
- Some(ref p) if !p.is_empty() => Path::new_opt(p.as_slice()),
+ Some(ref p) if !p.is_empty() => Path::init_opt(p.as_slice()),
_ => secondary()
};
fn secondary() -> Option<Path> {
getenv("USERPROFILE").and_then(|p| {
if !p.is_empty() {
- Path::new_opt(p)
+ Path::init_opt(p)
} else {
None
}
if x.is_empty() {
None
} else {
- Path::new_opt(x)
+ Path::init_opt(x)
},
_ => None
}
#[cfg(unix)]
fn lookup() -> Path {
if cfg!(target_os = "android") {
- Path::new("/data/tmp")
+ Path::init("/data/tmp")
} else {
- getenv_nonempty("TMPDIR").unwrap_or(Path::new("/tmp"))
+ getenv_nonempty("TMPDIR").unwrap_or(Path::init("/tmp"))
}
}
getenv_nonempty("TMP").or(
getenv_nonempty("TEMP").or(
getenv_nonempty("USERPROFILE").or(
- getenv_nonempty("WINDIR")))).unwrap_or(Path::new("C:\\Windows"))
+ getenv_nonempty("WINDIR")))).unwrap_or(Path::init("C:\\Windows"))
}
}
#[test]
fn test() {
- assert!((!Path::new("test-path").is_absolute()));
+ assert!((!Path::init("test-path").is_absolute()));
let cwd = getcwd();
debug!("Current working directory: {}", cwd.display());
- debug!("{:?}", make_absolute(&Path::new("test-path")));
- debug!("{:?}", make_absolute(&Path::new("/usr/bin")));
+ debug!("{:?}", make_absolute(&Path::init("test-path")));
+ debug!("{:?}", make_absolute(&Path::init("/usr/bin")));
}
#[test]
let oldhome = getenv("HOME");
setenv("HOME", "/home/MountainView");
- assert_eq!(os::homedir(), Some(Path::new("/home/MountainView")));
+ assert_eq!(os::homedir(), Some(Path::init("/home/MountainView")));
setenv("HOME", "");
assert!(os::homedir().is_none());
assert!(os::homedir().is_none());
setenv("HOME", "/home/MountainView");
- assert_eq!(os::homedir(), Some(Path::new("/home/MountainView")));
+ assert_eq!(os::homedir(), Some(Path::init("/home/MountainView")));
setenv("HOME", "");
setenv("USERPROFILE", "/home/MountainView");
- assert_eq!(os::homedir(), Some(Path::new("/home/MountainView")));
+ assert_eq!(os::homedir(), Some(Path::init("/home/MountainView")));
setenv("HOME", "/home/MountainView");
setenv("USERPROFILE", "/home/PaloAlto");
- assert_eq!(os::homedir(), Some(Path::new("/home/MountainView")));
+ assert_eq!(os::homedir(), Some(Path::init("/home/MountainView")));
for s in oldhome.iter() { setenv("HOME", *s) }
for s in olduserprofile.iter() { setenv("USERPROFILE", *s) }
Usage of this module is fairly straightforward. Unless writing platform-specific
code, `Path` should be used to refer to the platform-native path.
-Creation of a path is typically done with either `Path::new(some_str)` or
-`Path::new(some_vec)`. This path can be modified with `.push()` and
+Creation of a path is typically done with either `Path::init(some_str)` or
+`Path::init(some_vec)`. This path can be modified with `.push()` and
`.pop()` (and other setters). The resulting Path can either be passed to another
API that expects a path, or can be turned into a &[u8] with `.as_vec()` or a
Option<&str> with `.as_str()`. Similarly, attributes of the path can be queried
path instead of modifying the receiver, such as `.join()` or `.dir_path()`.
Paths are always kept in normalized form. This means that creating the path
-`Path::new("a/b/../c")` will return the path `a/c`. Similarly any attempt
+`Path::init("a/b/../c")` will return the path `a/c`. Similarly any attempt
to mutate the path will always leave it in normalized form.
When rendering a path to some form of output, there is a method `.display()`
## Example
```rust
-let mut path = Path::new("/tmp/path");
+let mut path = Path::from_str("/tmp/path");
debug!("path: {}", path.display());
path.set_filename("foo");
path.push("bar");
///
/// See individual Path impls for additional restrictions.
#[inline]
- fn new<T: BytesContainer>(path: T) -> Self {
+ fn init<T: BytesContainer>(path: T) -> Self {
if contains_nul(path.container_as_bytes()) {
let path = self::null_byte::cond.raise(path.container_into_owned_bytes());
assert!(!contains_nul(path));
- unsafe { GenericPathUnsafe::new_unchecked(path) }
+ unsafe { GenericPathUnsafe::init_unchecked(path) }
} else {
- unsafe { GenericPathUnsafe::new_unchecked(path) }
+ unsafe { GenericPathUnsafe::init_unchecked(path) }
}
}
/// Creates a new Path from a byte vector or string, if possible.
/// The resulting Path will always be normalized.
#[inline]
- fn new_opt<T: BytesContainer>(path: T) -> Option<Self> {
+ fn init_opt<T: BytesContainer>(path: T) -> Option<Self> {
if contains_nul(path.container_as_bytes()) {
None
} else {
- Some(unsafe { GenericPathUnsafe::new_unchecked(path) })
+ Some(unsafe { GenericPathUnsafe::init_unchecked(path) })
}
}
/// If `self` represents the root of the filesystem hierarchy, returns `self`.
fn dir_path(&self) -> Self {
// self.dirname() returns a NUL-free vector
- unsafe { GenericPathUnsafe::new_unchecked(self.dirname()) }
+ unsafe { GenericPathUnsafe::init_unchecked(self.dirname()) }
}
/// Returns a Path that represents the filesystem root that `self` is rooted in.
pub trait GenericPathUnsafe {
/// Creates a new Path without checking for null bytes.
/// The resulting Path will always be normalized.
- unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Self;
+ unsafe fn init_unchecked<T: BytesContainer>(path: T) -> Self;
/// Replaces the filename portion of the path without checking for null
/// bytes.
#[test]
fn test_cstring() {
let input = "/foo/bar/baz";
- let path: PosixPath = PosixPath::new(input.to_c_str());
+ let path: PosixPath = PosixPath::init(input.to_c_str());
assert_eq!(path.as_vec(), input.as_bytes());
let input = r"\foo\bar\baz";
- let path: WindowsPath = WindowsPath::new(input.to_c_str());
+ let path: WindowsPath = WindowsPath::init(input.to_c_str());
assert_eq!(path.as_str().unwrap(), input.as_slice());
}
}
impl FromStr for Path {
fn from_str(s: &str) -> Option<Path> {
- Path::new_opt(s)
+ Path::init_opt(s)
}
}
}
impl GenericPathUnsafe for Path {
- unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path {
+ unsafe fn init_unchecked<T: BytesContainer>(path: T) -> Path {
let path = Path::normalize(path.container_as_bytes());
assert!(!path.is_empty());
let idx = path.rposition_elem(&sep_byte);
fn root_path(&self) -> Option<Path> {
if self.is_absolute() {
- Some(Path::new("/"))
+ Some(Path::init("/"))
} else {
None
}
}
}
}
- Some(Path::new(comps.connect_vec(&sep_byte)))
+ Some(Path::init(comps.connect_vec(&sep_byte)))
}
}
///
/// Raises the `null_byte` condition if the vector contains a NUL.
#[inline]
- pub fn new<T: BytesContainer>(path: T) -> Path {
- GenericPath::new(path)
+ pub fn init<T: BytesContainer>(path: T) -> Path {
+ GenericPath::init(path)
}
/// Returns a new Path from a byte vector or string, if possible
#[inline]
- pub fn new_opt<T: BytesContainer>(path: T) -> Option<Path> {
- GenericPath::new_opt(path)
+ pub fn init_opt<T: BytesContainer>(path: T) -> Option<Path> {
+ GenericPath::init_opt(path)
}
/// Returns a normalized byte vector representation of a path, by removing all empty
#[test]
fn test_paths() {
let empty: &[u8] = [];
- t!(v: Path::new(empty), b!("."));
- t!(v: Path::new(b!("/")), b!("/"));
- t!(v: Path::new(b!("a/b/c")), b!("a/b/c"));
- t!(v: Path::new(b!("a/b/c", 0xff)), b!("a/b/c", 0xff));
- t!(v: Path::new(b!(0xff, "/../foo", 0x80)), b!("foo", 0x80));
- let p = Path::new(b!("a/b/c", 0xff));
+ t!(v: Path::init(empty), b!("."));
+ t!(v: Path::init(b!("/")), b!("/"));
+ t!(v: Path::init(b!("a/b/c")), b!("a/b/c"));
+ t!(v: Path::init(b!("a/b/c", 0xff)), b!("a/b/c", 0xff));
+ t!(v: Path::init(b!(0xff, "/../foo", 0x80)), b!("foo", 0x80));
+ let p = Path::init(b!("a/b/c", 0xff));
assert_eq!(p.as_str(), None);
- t!(s: Path::new(""), ".");
- t!(s: Path::new("/"), "/");
- t!(s: Path::new("hi"), "hi");
- t!(s: Path::new("hi/"), "hi");
- t!(s: Path::new("/lib"), "/lib");
- t!(s: Path::new("/lib/"), "/lib");
- t!(s: Path::new("hi/there"), "hi/there");
- t!(s: Path::new("hi/there.txt"), "hi/there.txt");
-
- t!(s: Path::new("hi/there/"), "hi/there");
- t!(s: Path::new("hi/../there"), "there");
- t!(s: Path::new("../hi/there"), "../hi/there");
- t!(s: Path::new("/../hi/there"), "/hi/there");
- t!(s: Path::new("foo/.."), ".");
- t!(s: Path::new("/foo/.."), "/");
- t!(s: Path::new("/foo/../.."), "/");
- t!(s: Path::new("/foo/../../bar"), "/bar");
- t!(s: Path::new("/./hi/./there/."), "/hi/there");
- t!(s: Path::new("/./hi/./there/./.."), "/hi");
- t!(s: Path::new("foo/../.."), "..");
- t!(s: Path::new("foo/../../.."), "../..");
- t!(s: Path::new("foo/../../bar"), "../bar");
-
- assert_eq!(Path::new(b!("foo/bar")).into_vec(), b!("foo/bar").to_owned());
- assert_eq!(Path::new(b!("/foo/../../bar")).into_vec(),
+ t!(s: Path::init(""), ".");
+ t!(s: Path::init("/"), "/");
+ t!(s: Path::init("hi"), "hi");
+ t!(s: Path::init("hi/"), "hi");
+ t!(s: Path::init("/lib"), "/lib");
+ t!(s: Path::init("/lib/"), "/lib");
+ t!(s: Path::init("hi/there"), "hi/there");
+ t!(s: Path::init("hi/there.txt"), "hi/there.txt");
+
+ t!(s: Path::init("hi/there/"), "hi/there");
+ t!(s: Path::init("hi/../there"), "there");
+ t!(s: Path::init("../hi/there"), "../hi/there");
+ t!(s: Path::init("/../hi/there"), "/hi/there");
+ t!(s: Path::init("foo/.."), ".");
+ t!(s: Path::init("/foo/.."), "/");
+ t!(s: Path::init("/foo/../.."), "/");
+ t!(s: Path::init("/foo/../../bar"), "/bar");
+ t!(s: Path::init("/./hi/./there/."), "/hi/there");
+ t!(s: Path::init("/./hi/./there/./.."), "/hi");
+ t!(s: Path::init("foo/../.."), "..");
+ t!(s: Path::init("foo/../../.."), "../..");
+ t!(s: Path::init("foo/../../bar"), "../bar");
+
+ assert_eq!(Path::init(b!("foo/bar")).into_vec(), b!("foo/bar").to_owned());
+ assert_eq!(Path::init(b!("/foo/../../bar")).into_vec(),
b!("/bar").to_owned());
- let p = Path::new(b!("foo/bar", 0x80));
+ let p = Path::init(b!("foo/bar", 0x80));
assert_eq!(p.as_str(), None);
}
#[test]
fn test_opt_paths() {
- assert_eq!(Path::new_opt(b!("foo/bar", 0)), None);
- t!(v: Path::new_opt(b!("foo/bar")).unwrap(), b!("foo/bar"));
- assert_eq!(Path::new_opt("foo/bar\0"), None);
- t!(s: Path::new_opt("foo/bar").unwrap(), "foo/bar");
+ assert_eq!(Path::init_opt(b!("foo/bar", 0)), None);
+ t!(v: Path::init_opt(b!("foo/bar")).unwrap(), b!("foo/bar"));
+ assert_eq!(Path::init_opt("foo/bar\0"), None);
+ t!(s: Path::init_opt("foo/bar").unwrap(), "foo/bar");
}
#[test]
assert_eq!(v.as_slice(), b!("foo/bar", 0));
(b!("/bar").to_owned())
}).inside(|| {
- Path::new(b!("foo/bar", 0))
+ Path::init(b!("foo/bar", 0))
});
assert!(handled);
assert_eq!(p.as_vec(), b!("/bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
- Path::new(b!("foo/bar", 0))
+ Path::init(b!("foo/bar", 0))
});
})
t!(~"set_filename w/nul" => {
- let mut p = Path::new(b!("foo/bar"));
+ let mut p = Path::init(b!("foo/bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
})
t!(~"push w/nul" => {
- let mut p = Path::new(b!("foo/bar"));
+ let mut p = Path::init(b!("foo/bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
macro_rules! t(
($path:expr, $disp:ident, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
assert_eq!(path.$disp().to_str(), ~$exp);
}
)
($path:expr, $exp:expr) => (
{
let mut called = false;
- let path = Path::new($path);
+ let path = Path::init($path);
path.display().with_str(|s| {
assert_eq!(s, $exp);
called = true;
($path:expr, $exp:expr, filename) => (
{
let mut called = false;
- let path = Path::new($path);
+ let path = Path::init($path);
path.filename_display().with_str(|s| {
assert_eq!(s, $exp);
called = true;
macro_rules! t(
($path:expr, $exp:expr, $expf:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let f = format!("{}", path.display());
assert_eq!(f.as_slice(), $exp);
let f = format!("{}", path.filename_display());
macro_rules! t(
(s: $path:expr, $op:ident, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
assert_eq!(path.$op(), ($exp).as_bytes());
}
);
(s: $path:expr, $op:ident, $exp:expr, opt) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let left = path.$op().map(|x| str::from_utf8_slice(x));
assert_eq!(left, $exp);
}
);
(v: $path:expr, $op:ident, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
assert_eq!(path.$op(), $exp);
}
);
{
let path = ($path);
let join = ($join);
- let mut p1 = Path::new(path);
+ let mut p1 = Path::init(path);
let p2 = p1.clone();
p1.push(join);
assert_eq!(p1, p2.join(join));
macro_rules! t(
(s: $path:expr, $push:expr, $exp:expr) => (
{
- let mut p = Path::new($path);
- let push = Path::new($push);
+ let mut p = Path::init($path);
+ let push = Path::init($push);
p.push(&push);
assert_eq!(p.as_str(), Some($exp));
}
macro_rules! t(
(s: $path:expr, $push:expr, $exp:expr) => (
{
- let mut p = Path::new($path);
+ let mut p = Path::init($path);
p.push_many($push);
assert_eq!(p.as_str(), Some($exp));
}
);
(v: $path:expr, $push:expr, $exp:expr) => (
{
- let mut p = Path::new($path);
+ let mut p = Path::init($path);
p.push_many($push);
assert_eq!(p.as_vec(), $exp);
}
macro_rules! t(
(s: $path:expr, $left:expr, $right:expr) => (
{
- let mut p = Path::new($path);
+ let mut p = Path::init($path);
let result = p.pop();
assert_eq!(p.as_str(), Some($left));
assert_eq!(result, $right);
);
(v: [$($path:expr),+], [$($left:expr),+], $right:expr) => (
{
- let mut p = Path::new(b!($($path),+));
+ let mut p = Path::init(b!($($path),+));
let result = p.pop();
assert_eq!(p.as_vec(), b!($($left),+));
assert_eq!(result, $right);
#[test]
fn test_root_path() {
- assert_eq!(Path::new(b!("a/b/c")).root_path(), None);
- assert_eq!(Path::new(b!("/a/b/c")).root_path(), Some(Path::new("/")));
+ assert_eq!(Path::init(b!("a/b/c")).root_path(), None);
+ assert_eq!(Path::init(b!("/a/b/c")).root_path(), Some(Path::init("/")));
}
#[test]
fn test_join() {
- t!(v: Path::new(b!("a/b/c")).join(b!("..")), b!("a/b"));
- t!(v: Path::new(b!("/a/b/c")).join(b!("d")), b!("/a/b/c/d"));
- t!(v: Path::new(b!("a/", 0x80, "/c")).join(b!(0xff)), b!("a/", 0x80, "/c/", 0xff));
- t!(s: Path::new("a/b/c").join(".."), "a/b");
- t!(s: Path::new("/a/b/c").join("d"), "/a/b/c/d");
- t!(s: Path::new("a/b").join("c/d"), "a/b/c/d");
- t!(s: Path::new("a/b").join("/c/d"), "/c/d");
- t!(s: Path::new(".").join("a/b"), "a/b");
- t!(s: Path::new("/").join("a/b"), "/a/b");
+ t!(v: Path::init(b!("a/b/c")).join(b!("..")), b!("a/b"));
+ t!(v: Path::init(b!("/a/b/c")).join(b!("d")), b!("/a/b/c/d"));
+ t!(v: Path::init(b!("a/", 0x80, "/c")).join(b!(0xff)), b!("a/", 0x80, "/c/", 0xff));
+ t!(s: Path::init("a/b/c").join(".."), "a/b");
+ t!(s: Path::init("/a/b/c").join("d"), "/a/b/c/d");
+ t!(s: Path::init("a/b").join("c/d"), "a/b/c/d");
+ t!(s: Path::init("a/b").join("/c/d"), "/c/d");
+ t!(s: Path::init(".").join("a/b"), "a/b");
+ t!(s: Path::init("/").join("a/b"), "/a/b");
}
#[test]
macro_rules! t(
(s: $path:expr, $join:expr, $exp:expr) => (
{
- let path = Path::new($path);
- let join = Path::new($join);
+ let path = Path::init($path);
+ let join = Path::init($join);
let res = path.join(&join);
assert_eq!(res.as_str(), Some($exp));
}
macro_rules! t(
(s: $path:expr, $join:expr, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let res = path.join_many($join);
assert_eq!(res.as_str(), Some($exp));
}
);
(v: $path:expr, $join:expr, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let res = path.join_many($join);
assert_eq!(res.as_vec(), $exp);
}
fn test_with_helpers() {
let empty: &[u8] = [];
- t!(v: Path::new(b!("a/b/c")).with_filename(b!("d")), b!("a/b/d"));
- t!(v: Path::new(b!("a/b/c", 0xff)).with_filename(b!(0x80)), b!("a/b/", 0x80));
- t!(v: Path::new(b!("/", 0xff, "/foo")).with_filename(b!(0xcd)),
+ t!(v: Path::init(b!("a/b/c")).with_filename(b!("d")), b!("a/b/d"));
+ t!(v: Path::init(b!("a/b/c", 0xff)).with_filename(b!(0x80)), b!("a/b/", 0x80));
+ t!(v: Path::init(b!("/", 0xff, "/foo")).with_filename(b!(0xcd)),
b!("/", 0xff, "/", 0xcd));
- t!(s: Path::new("a/b/c").with_filename("d"), "a/b/d");
- t!(s: Path::new(".").with_filename("foo"), "foo");
- t!(s: Path::new("/a/b/c").with_filename("d"), "/a/b/d");
- t!(s: Path::new("/").with_filename("foo"), "/foo");
- t!(s: Path::new("/a").with_filename("foo"), "/foo");
- t!(s: Path::new("foo").with_filename("bar"), "bar");
- t!(s: Path::new("/").with_filename("foo/"), "/foo");
- t!(s: Path::new("/a").with_filename("foo/"), "/foo");
- t!(s: Path::new("a/b/c").with_filename(""), "a/b");
- t!(s: Path::new("a/b/c").with_filename("."), "a/b");
- t!(s: Path::new("a/b/c").with_filename(".."), "a");
- t!(s: Path::new("/a").with_filename(""), "/");
- t!(s: Path::new("foo").with_filename(""), ".");
- t!(s: Path::new("a/b/c").with_filename("d/e"), "a/b/d/e");
- t!(s: Path::new("a/b/c").with_filename("/d"), "a/b/d");
- t!(s: Path::new("..").with_filename("foo"), "../foo");
- t!(s: Path::new("../..").with_filename("foo"), "../../foo");
- t!(s: Path::new("..").with_filename(""), "..");
- t!(s: Path::new("../..").with_filename(""), "../..");
-
- t!(v: Path::new(b!("hi/there", 0x80, ".txt")).with_extension(b!("exe")),
+ t!(s: Path::init("a/b/c").with_filename("d"), "a/b/d");
+ t!(s: Path::init(".").with_filename("foo"), "foo");
+ t!(s: Path::init("/a/b/c").with_filename("d"), "/a/b/d");
+ t!(s: Path::init("/").with_filename("foo"), "/foo");
+ t!(s: Path::init("/a").with_filename("foo"), "/foo");
+ t!(s: Path::init("foo").with_filename("bar"), "bar");
+ t!(s: Path::init("/").with_filename("foo/"), "/foo");
+ t!(s: Path::init("/a").with_filename("foo/"), "/foo");
+ t!(s: Path::init("a/b/c").with_filename(""), "a/b");
+ t!(s: Path::init("a/b/c").with_filename("."), "a/b");
+ t!(s: Path::init("a/b/c").with_filename(".."), "a");
+ t!(s: Path::init("/a").with_filename(""), "/");
+ t!(s: Path::init("foo").with_filename(""), ".");
+ t!(s: Path::init("a/b/c").with_filename("d/e"), "a/b/d/e");
+ t!(s: Path::init("a/b/c").with_filename("/d"), "a/b/d");
+ t!(s: Path::init("..").with_filename("foo"), "../foo");
+ t!(s: Path::init("../..").with_filename("foo"), "../../foo");
+ t!(s: Path::init("..").with_filename(""), "..");
+ t!(s: Path::init("../..").with_filename(""), "../..");
+
+ t!(v: Path::init(b!("hi/there", 0x80, ".txt")).with_extension(b!("exe")),
b!("hi/there", 0x80, ".exe"));
- t!(v: Path::new(b!("hi/there.txt", 0x80)).with_extension(b!(0xff)),
+ t!(v: Path::init(b!("hi/there.txt", 0x80)).with_extension(b!(0xff)),
b!("hi/there.", 0xff));
- t!(v: Path::new(b!("hi/there", 0x80)).with_extension(b!(0xff)),
+ t!(v: Path::init(b!("hi/there", 0x80)).with_extension(b!(0xff)),
b!("hi/there", 0x80, ".", 0xff));
- t!(v: Path::new(b!("hi/there.", 0xff)).with_extension(empty), b!("hi/there"));
- t!(s: Path::new("hi/there.txt").with_extension("exe"), "hi/there.exe");
- t!(s: Path::new("hi/there.txt").with_extension(""), "hi/there");
- t!(s: Path::new("hi/there.txt").with_extension("."), "hi/there..");
- t!(s: Path::new("hi/there.txt").with_extension(".."), "hi/there...");
- t!(s: Path::new("hi/there").with_extension("txt"), "hi/there.txt");
- t!(s: Path::new("hi/there").with_extension("."), "hi/there..");
- t!(s: Path::new("hi/there").with_extension(".."), "hi/there...");
- t!(s: Path::new("hi/there.").with_extension("txt"), "hi/there.txt");
- t!(s: Path::new("hi/.foo").with_extension("txt"), "hi/.foo.txt");
- t!(s: Path::new("hi/there.txt").with_extension(".foo"), "hi/there..foo");
- t!(s: Path::new("/").with_extension("txt"), "/");
- t!(s: Path::new("/").with_extension("."), "/");
- t!(s: Path::new("/").with_extension(".."), "/");
- t!(s: Path::new(".").with_extension("txt"), ".");
+ t!(v: Path::init(b!("hi/there.", 0xff)).with_extension(empty), b!("hi/there"));
+ t!(s: Path::init("hi/there.txt").with_extension("exe"), "hi/there.exe");
+ t!(s: Path::init("hi/there.txt").with_extension(""), "hi/there");
+ t!(s: Path::init("hi/there.txt").with_extension("."), "hi/there..");
+ t!(s: Path::init("hi/there.txt").with_extension(".."), "hi/there...");
+ t!(s: Path::init("hi/there").with_extension("txt"), "hi/there.txt");
+ t!(s: Path::init("hi/there").with_extension("."), "hi/there..");
+ t!(s: Path::init("hi/there").with_extension(".."), "hi/there...");
+ t!(s: Path::init("hi/there.").with_extension("txt"), "hi/there.txt");
+ t!(s: Path::init("hi/.foo").with_extension("txt"), "hi/.foo.txt");
+ t!(s: Path::init("hi/there.txt").with_extension(".foo"), "hi/there..foo");
+ t!(s: Path::init("/").with_extension("txt"), "/");
+ t!(s: Path::init("/").with_extension("."), "/");
+ t!(s: Path::init("/").with_extension(".."), "/");
+ t!(s: Path::init(".").with_extension("txt"), ".");
}
#[test]
{
let path = $path;
let arg = $arg;
- let mut p1 = Path::new(path);
+ let mut p1 = Path::init(path);
p1.$set(arg);
- let p2 = Path::new(path);
+ let p2 = Path::init(path);
assert_eq!(p1, p2.$with(arg));
}
);
{
let path = $path;
let arg = $arg;
- let mut p1 = Path::new(path);
+ let mut p1 = Path::init(path);
p1.$set(arg);
- let p2 = Path::new(path);
+ let p2 = Path::init(path);
assert_eq!(p1, p2.$with(arg));
}
)
)
)
- t!(v: Path::new(b!("a/b/c")), Some(b!("c")), b!("a/b"), Some(b!("c")), None);
- t!(v: Path::new(b!("a/b/", 0xff)), Some(b!(0xff)), b!("a/b"), Some(b!(0xff)), None);
- t!(v: Path::new(b!("hi/there.", 0xff)), Some(b!("there.", 0xff)), b!("hi"),
+ t!(v: Path::init(b!("a/b/c")), Some(b!("c")), b!("a/b"), Some(b!("c")), None);
+ t!(v: Path::init(b!("a/b/", 0xff)), Some(b!(0xff)), b!("a/b"), Some(b!(0xff)), None);
+ t!(v: Path::init(b!("hi/there.", 0xff)), Some(b!("there.", 0xff)), b!("hi"),
Some(b!("there")), Some(b!(0xff)));
- t!(s: Path::new("a/b/c"), Some("c"), Some("a/b"), Some("c"), None);
- t!(s: Path::new("."), None, Some("."), None, None);
- t!(s: Path::new("/"), None, Some("/"), None, None);
- t!(s: Path::new(".."), None, Some(".."), None, None);
- t!(s: Path::new("../.."), None, Some("../.."), None, None);
- t!(s: Path::new("hi/there.txt"), Some("there.txt"), Some("hi"),
+ t!(s: Path::init("a/b/c"), Some("c"), Some("a/b"), Some("c"), None);
+ t!(s: Path::init("."), None, Some("."), None, None);
+ t!(s: Path::init("/"), None, Some("/"), None, None);
+ t!(s: Path::init(".."), None, Some(".."), None, None);
+ t!(s: Path::init("../.."), None, Some("../.."), None, None);
+ t!(s: Path::init("hi/there.txt"), Some("there.txt"), Some("hi"),
Some("there"), Some("txt"));
- t!(s: Path::new("hi/there"), Some("there"), Some("hi"), Some("there"), None);
- t!(s: Path::new("hi/there."), Some("there."), Some("hi"),
+ t!(s: Path::init("hi/there"), Some("there"), Some("hi"), Some("there"), None);
+ t!(s: Path::init("hi/there."), Some("there."), Some("hi"),
Some("there"), Some(""));
- t!(s: Path::new("hi/.there"), Some(".there"), Some("hi"), Some(".there"), None);
- t!(s: Path::new("hi/..there"), Some("..there"), Some("hi"),
+ t!(s: Path::init("hi/.there"), Some(".there"), Some("hi"), Some(".there"), None);
+ t!(s: Path::init("hi/..there"), Some("..there"), Some("hi"),
Some("."), Some("there"));
- t!(s: Path::new(b!("a/b/", 0xff)), None, Some("a/b"), None, None);
- t!(s: Path::new(b!("a/b/", 0xff, ".txt")), None, Some("a/b"), None, Some("txt"));
- t!(s: Path::new(b!("a/b/c.", 0x80)), None, Some("a/b"), Some("c"), None);
- t!(s: Path::new(b!(0xff, "/b")), Some("b"), None, Some("b"), None);
+ t!(s: Path::init(b!("a/b/", 0xff)), None, Some("a/b"), None, None);
+ t!(s: Path::init(b!("a/b/", 0xff, ".txt")), None, Some("a/b"), None, Some("txt"));
+ t!(s: Path::init(b!("a/b/c.", 0x80)), None, Some("a/b"), Some("c"), None);
+ t!(s: Path::init(b!(0xff, "/b")), Some("b"), None, Some("b"), None);
}
#[test]
fn test_dir_path() {
- t!(v: Path::new(b!("hi/there", 0x80)).dir_path(), b!("hi"));
- t!(v: Path::new(b!("hi", 0xff, "/there")).dir_path(), b!("hi", 0xff));
- t!(s: Path::new("hi/there").dir_path(), "hi");
- t!(s: Path::new("hi").dir_path(), ".");
- t!(s: Path::new("/hi").dir_path(), "/");
- t!(s: Path::new("/").dir_path(), "/");
- t!(s: Path::new("..").dir_path(), "..");
- t!(s: Path::new("../..").dir_path(), "../..");
+ t!(v: Path::init(b!("hi/there", 0x80)).dir_path(), b!("hi"));
+ t!(v: Path::init(b!("hi", 0xff, "/there")).dir_path(), b!("hi", 0xff));
+ t!(s: Path::init("hi/there").dir_path(), "hi");
+ t!(s: Path::init("hi").dir_path(), ".");
+ t!(s: Path::init("/hi").dir_path(), "/");
+ t!(s: Path::init("/").dir_path(), "/");
+ t!(s: Path::init("..").dir_path(), "..");
+ t!(s: Path::init("../..").dir_path(), "../..");
}
#[test]
macro_rules! t(
(s: $path:expr, $abs:expr, $rel:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
assert_eq!(path.is_absolute(), $abs);
assert_eq!(path.is_relative(), $rel);
}
macro_rules! t(
(s: $path:expr, $dest:expr, $exp:expr) => (
{
- let path = Path::new($path);
- let dest = Path::new($dest);
+ let path = Path::init($path);
+ let dest = Path::init($dest);
assert_eq!(path.is_ancestor_of(&dest), $exp);
}
)
macro_rules! t(
(s: $path:expr, $child:expr, $exp:expr) => (
{
- let path = Path::new($path);
- let child = Path::new($child);
+ let path = Path::init($path);
+ let child = Path::init($child);
assert_eq!(path.ends_with_path(&child), $exp);
}
);
(v: $path:expr, $child:expr, $exp:expr) => (
{
- let path = Path::new($path);
- let child = Path::new($child);
+ let path = Path::init($path);
+ let child = Path::init($child);
assert_eq!(path.ends_with_path(&child), $exp);
}
)
macro_rules! t(
(s: $path:expr, $other:expr, $exp:expr) => (
{
- let path = Path::new($path);
- let other = Path::new($other);
+ let path = Path::init($path);
+ let other = Path::init($other);
let res = path.path_relative_from(&other);
assert_eq!(res.as_ref().and_then(|x| x.as_str()), $exp);
}
macro_rules! t(
(s: $path:expr, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let comps = path.components().to_owned_vec();
let exp: &[&str] = $exp;
let exps = exp.iter().map(|x| x.as_bytes()).to_owned_vec();
);
(v: [$($arg:expr),+], [$([$($exp:expr),*]),*]) => (
{
- let path = Path::new(b!($($arg),+));
+ let path = Path::init(b!($($arg),+));
let comps = path.components().to_owned_vec();
let exp: &[&[u8]] = [$(b!($($exp),*)),*];
assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}",
macro_rules! t(
(v: [$($arg:expr),+], $exp:expr) => (
{
- let path = Path::new(b!($($arg),+));
+ let path = Path::init(b!($($arg),+));
let comps = path.str_components().to_owned_vec();
let exp: &[Option<&str>] = $exp;
assert!(comps.as_slice() == exp,
#[bench]
fn join_home_dir(bh: &mut BenchHarness) {
- let posix_path = Path::new("/");
+ let posix_path = Path::init("/");
bh.iter(|| {
posix_path.join("home");
});
#[bench]
fn join_abs_path_home_dir(bh: &mut BenchHarness) {
- let posix_path = Path::new("/");
+ let posix_path = Path::init("/");
bh.iter(|| {
posix_path.join("/home");
});
#[bench]
fn join_many_home_dir(bh: &mut BenchHarness) {
- let posix_path = Path::new("/");
+ let posix_path = Path::init("/");
bh.iter(|| {
posix_path.join_many(&["home"]);
});
#[bench]
fn join_many_abs_path_home_dir(bh: &mut BenchHarness) {
- let posix_path = Path::new("/");
+ let posix_path = Path::init("/");
bh.iter(|| {
posix_path.join_many(&["/home"]);
});
#[bench]
fn push_home_dir(bh: &mut BenchHarness) {
- let mut posix_path = Path::new("/");
+ let mut posix_path = Path::init("/");
bh.iter(|| {
posix_path.push("home");
});
#[bench]
fn push_abs_path_home_dir(bh: &mut BenchHarness) {
- let mut posix_path = Path::new("/");
+ let mut posix_path = Path::init("/");
bh.iter(|| {
posix_path.push("/home");
});
#[bench]
fn push_many_home_dir(bh: &mut BenchHarness) {
- let mut posix_path = Path::new("/");
+ let mut posix_path = Path::init("/");
bh.iter(|| {
posix_path.push_many(&["home"]);
});
#[bench]
fn push_many_abs_path_home_dir(bh: &mut BenchHarness) {
- let mut posix_path = Path::new("/");
+ let mut posix_path = Path::init("/");
bh.iter(|| {
posix_path.push_many(&["/home"]);
});
#[bench]
fn ends_with_path_home_dir(bh: &mut BenchHarness) {
- let posix_home_path = Path::new("/home");
+ let posix_home_path = Path::init("/home");
bh.iter(|| {
- posix_home_path.ends_with_path(&Path::new("home"));
+ posix_home_path.ends_with_path(&Path::init("home"));
});
}
#[bench]
fn ends_with_path_missmatch_jome_home(bh: &mut BenchHarness) {
- let posix_home_path = Path::new("/home");
+ let posix_home_path = Path::init("/home");
bh.iter(|| {
- posix_home_path.ends_with_path(&Path::new("jome"));
+ posix_home_path.ends_with_path(&Path::init("jome"));
});
}
}
impl FromStr for Path {
fn from_str(s: &str) -> Option<Path> {
- Path::new_opt(s)
+ Path::init_opt(s)
}
}
///
/// Raises the `str::not_utf8` condition if not valid UTF-8.
#[inline]
- unsafe fn new_unchecked<T: BytesContainer>(path: T) -> Path {
+ unsafe fn init_unchecked<T: BytesContainer>(path: T) -> Path {
let (prefix, path) = Path::normalize_(path.container_as_str());
assert!(!path.is_empty());
let mut ret = Path{ repr: path, prefix: prefix, sepidx: None };
impl GenericPath for Path {
#[inline]
- fn new_opt<T: BytesContainer>(path: T) -> Option<Path> {
+ fn init_opt<T: BytesContainer>(path: T) -> Option<Path> {
let s = path.container_as_str_opt();
match s {
None => None,
if contains_nul(s.as_bytes()) {
None
} else {
- Some(unsafe { GenericPathUnsafe::new_unchecked(s) })
+ Some(unsafe { GenericPathUnsafe::init_unchecked(s) })
}
}
}
}
fn dir_path(&self) -> Path {
- unsafe { GenericPathUnsafe::new_unchecked(self.dirname_str().unwrap()) }
+ unsafe { GenericPathUnsafe::init_unchecked(self.dirname_str().unwrap()) }
}
#[inline]
fn root_path(&self) -> Option<Path> {
if self.is_absolute() {
- Some(Path::new(match self.prefix {
+ Some(Path::init(match self.prefix {
Some(VerbatimDiskPrefix)|Some(DiskPrefix) => {
self.repr.slice_to(self.prefix_len()+1)
}
_ => self.repr.slice_to(self.prefix_len())
}))
} else if is_vol_relative(self) {
- Some(Path::new(self.repr.slice_to(1)))
+ Some(Path::init(self.repr.slice_to(1)))
} else {
None
}
}
}
}
- Some(Path::new(comps.connect("\\")))
+ Some(Path::init(comps.connect("\\")))
}
}
/// Raises the `null_byte` condition if the vector contains a NUL.
/// Raises the `str::not_utf8` condition if invalid UTF-8.
#[inline]
- pub fn new<T: BytesContainer>(path: T) -> Path {
- GenericPath::new(path)
+ pub fn init<T: BytesContainer>(path: T) -> Path {
+ GenericPath::init(path)
}
/// Returns a new Path from a byte vector or string, if possible
#[inline]
- pub fn new_opt<T: BytesContainer>(path: T) -> Option<Path> {
- GenericPath::new_opt(path)
+ pub fn init_opt<T: BytesContainer>(path: T) -> Option<Path> {
+ GenericPath::init_opt(path)
}
/// Returns an iterator that yields each component of the path in turn as a Option<&str>.
#[test]
fn test_paths() {
let empty: &[u8] = [];
- t!(v: Path::new(empty), b!("."));
- t!(v: Path::new(b!("\\")), b!("\\"));
- t!(v: Path::new(b!("a\\b\\c")), b!("a\\b\\c"));
-
- t!(s: Path::new(""), ".");
- t!(s: Path::new("\\"), "\\");
- t!(s: Path::new("hi"), "hi");
- t!(s: Path::new("hi\\"), "hi");
- t!(s: Path::new("\\lib"), "\\lib");
- t!(s: Path::new("\\lib\\"), "\\lib");
- t!(s: Path::new("hi\\there"), "hi\\there");
- t!(s: Path::new("hi\\there.txt"), "hi\\there.txt");
- t!(s: Path::new("/"), "\\");
- t!(s: Path::new("hi/"), "hi");
- t!(s: Path::new("/lib"), "\\lib");
- t!(s: Path::new("/lib/"), "\\lib");
- t!(s: Path::new("hi/there"), "hi\\there");
-
- t!(s: Path::new("hi\\there\\"), "hi\\there");
- t!(s: Path::new("hi\\..\\there"), "there");
- t!(s: Path::new("hi/../there"), "there");
- t!(s: Path::new("..\\hi\\there"), "..\\hi\\there");
- t!(s: Path::new("\\..\\hi\\there"), "\\hi\\there");
- t!(s: Path::new("/../hi/there"), "\\hi\\there");
- t!(s: Path::new("foo\\.."), ".");
- t!(s: Path::new("\\foo\\.."), "\\");
- t!(s: Path::new("\\foo\\..\\.."), "\\");
- t!(s: Path::new("\\foo\\..\\..\\bar"), "\\bar");
- t!(s: Path::new("\\.\\hi\\.\\there\\."), "\\hi\\there");
- t!(s: Path::new("\\.\\hi\\.\\there\\.\\.."), "\\hi");
- t!(s: Path::new("foo\\..\\.."), "..");
- t!(s: Path::new("foo\\..\\..\\.."), "..\\..");
- t!(s: Path::new("foo\\..\\..\\bar"), "..\\bar");
-
- assert_eq!(Path::new(b!("foo\\bar")).into_vec(), b!("foo\\bar").to_owned());
- assert_eq!(Path::new(b!("\\foo\\..\\..\\bar")).into_vec(),
+ t!(v: Path::init(empty), b!("."));
+ t!(v: Path::init(b!("\\")), b!("\\"));
+ t!(v: Path::init(b!("a\\b\\c")), b!("a\\b\\c"));
+
+ t!(s: Path::init(""), ".");
+ t!(s: Path::init("\\"), "\\");
+ t!(s: Path::init("hi"), "hi");
+ t!(s: Path::init("hi\\"), "hi");
+ t!(s: Path::init("\\lib"), "\\lib");
+ t!(s: Path::init("\\lib\\"), "\\lib");
+ t!(s: Path::init("hi\\there"), "hi\\there");
+ t!(s: Path::init("hi\\there.txt"), "hi\\there.txt");
+ t!(s: Path::init("/"), "\\");
+ t!(s: Path::init("hi/"), "hi");
+ t!(s: Path::init("/lib"), "\\lib");
+ t!(s: Path::init("/lib/"), "\\lib");
+ t!(s: Path::init("hi/there"), "hi\\there");
+
+ t!(s: Path::init("hi\\there\\"), "hi\\there");
+ t!(s: Path::init("hi\\..\\there"), "there");
+ t!(s: Path::init("hi/../there"), "there");
+ t!(s: Path::init("..\\hi\\there"), "..\\hi\\there");
+ t!(s: Path::init("\\..\\hi\\there"), "\\hi\\there");
+ t!(s: Path::init("/../hi/there"), "\\hi\\there");
+ t!(s: Path::init("foo\\.."), ".");
+ t!(s: Path::init("\\foo\\.."), "\\");
+ t!(s: Path::init("\\foo\\..\\.."), "\\");
+ t!(s: Path::init("\\foo\\..\\..\\bar"), "\\bar");
+ t!(s: Path::init("\\.\\hi\\.\\there\\."), "\\hi\\there");
+ t!(s: Path::init("\\.\\hi\\.\\there\\.\\.."), "\\hi");
+ t!(s: Path::init("foo\\..\\.."), "..");
+ t!(s: Path::init("foo\\..\\..\\.."), "..\\..");
+ t!(s: Path::init("foo\\..\\..\\bar"), "..\\bar");
+
+ assert_eq!(Path::init(b!("foo\\bar")).into_vec(), b!("foo\\bar").to_owned());
+ assert_eq!(Path::init(b!("\\foo\\..\\..\\bar")).into_vec(),
b!("\\bar").to_owned());
- t!(s: Path::new("\\\\a"), "\\a");
- t!(s: Path::new("\\\\a\\"), "\\a");
- t!(s: Path::new("\\\\a\\b"), "\\\\a\\b");
- t!(s: Path::new("\\\\a\\b\\"), "\\\\a\\b");
- t!(s: Path::new("\\\\a\\b/"), "\\\\a\\b");
- t!(s: Path::new("\\\\\\b"), "\\b");
- t!(s: Path::new("\\\\a\\\\b"), "\\a\\b");
- t!(s: Path::new("\\\\a\\b\\c"), "\\\\a\\b\\c");
- t!(s: Path::new("\\\\server\\share/path"), "\\\\server\\share\\path");
- t!(s: Path::new("\\\\server/share/path"), "\\\\server\\share\\path");
- t!(s: Path::new("C:a\\b.txt"), "C:a\\b.txt");
- t!(s: Path::new("C:a/b.txt"), "C:a\\b.txt");
- t!(s: Path::new("z:\\a\\b.txt"), "Z:\\a\\b.txt");
- t!(s: Path::new("z:/a/b.txt"), "Z:\\a\\b.txt");
- t!(s: Path::new("ab:/a/b.txt"), "ab:\\a\\b.txt");
- t!(s: Path::new("C:\\"), "C:\\");
- t!(s: Path::new("C:"), "C:");
- t!(s: Path::new("q:"), "Q:");
- t!(s: Path::new("C:/"), "C:\\");
- t!(s: Path::new("C:\\foo\\.."), "C:\\");
- t!(s: Path::new("C:foo\\.."), "C:");
- t!(s: Path::new("C:\\a\\"), "C:\\a");
- t!(s: Path::new("C:\\a/"), "C:\\a");
- t!(s: Path::new("C:\\a\\b\\"), "C:\\a\\b");
- t!(s: Path::new("C:\\a\\b/"), "C:\\a\\b");
- t!(s: Path::new("C:a\\"), "C:a");
- t!(s: Path::new("C:a/"), "C:a");
- t!(s: Path::new("C:a\\b\\"), "C:a\\b");
- t!(s: Path::new("C:a\\b/"), "C:a\\b");
- t!(s: Path::new("\\\\?\\z:\\a\\b.txt"), "\\\\?\\z:\\a\\b.txt");
- t!(s: Path::new("\\\\?\\C:/a/b.txt"), "\\\\?\\C:/a/b.txt");
- t!(s: Path::new("\\\\?\\C:\\a/b.txt"), "\\\\?\\C:\\a/b.txt");
- t!(s: Path::new("\\\\?\\test\\a\\b.txt"), "\\\\?\\test\\a\\b.txt");
- t!(s: Path::new("\\\\?\\foo\\bar\\"), "\\\\?\\foo\\bar\\");
- t!(s: Path::new("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar");
- t!(s: Path::new("\\\\.\\"), "\\\\.\\");
- t!(s: Path::new("\\\\?\\UNC\\server\\share\\foo"), "\\\\?\\UNC\\server\\share\\foo");
- t!(s: Path::new("\\\\?\\UNC\\server/share"), "\\\\?\\UNC\\server/share\\");
- t!(s: Path::new("\\\\?\\UNC\\server"), "\\\\?\\UNC\\server\\");
- t!(s: Path::new("\\\\?\\UNC\\"), "\\\\?\\UNC\\\\");
- t!(s: Path::new("\\\\?\\UNC"), "\\\\?\\UNC");
+ t!(s: Path::init("\\\\a"), "\\a");
+ t!(s: Path::init("\\\\a\\"), "\\a");
+ t!(s: Path::init("\\\\a\\b"), "\\\\a\\b");
+ t!(s: Path::init("\\\\a\\b\\"), "\\\\a\\b");
+ t!(s: Path::init("\\\\a\\b/"), "\\\\a\\b");
+ t!(s: Path::init("\\\\\\b"), "\\b");
+ t!(s: Path::init("\\\\a\\\\b"), "\\a\\b");
+ t!(s: Path::init("\\\\a\\b\\c"), "\\\\a\\b\\c");
+ t!(s: Path::init("\\\\server\\share/path"), "\\\\server\\share\\path");
+ t!(s: Path::init("\\\\server/share/path"), "\\\\server\\share\\path");
+ t!(s: Path::init("C:a\\b.txt"), "C:a\\b.txt");
+ t!(s: Path::init("C:a/b.txt"), "C:a\\b.txt");
+ t!(s: Path::init("z:\\a\\b.txt"), "Z:\\a\\b.txt");
+ t!(s: Path::init("z:/a/b.txt"), "Z:\\a\\b.txt");
+ t!(s: Path::init("ab:/a/b.txt"), "ab:\\a\\b.txt");
+ t!(s: Path::init("C:\\"), "C:\\");
+ t!(s: Path::init("C:"), "C:");
+ t!(s: Path::init("q:"), "Q:");
+ t!(s: Path::init("C:/"), "C:\\");
+ t!(s: Path::init("C:\\foo\\.."), "C:\\");
+ t!(s: Path::init("C:foo\\.."), "C:");
+ t!(s: Path::init("C:\\a\\"), "C:\\a");
+ t!(s: Path::init("C:\\a/"), "C:\\a");
+ t!(s: Path::init("C:\\a\\b\\"), "C:\\a\\b");
+ t!(s: Path::init("C:\\a\\b/"), "C:\\a\\b");
+ t!(s: Path::init("C:a\\"), "C:a");
+ t!(s: Path::init("C:a/"), "C:a");
+ t!(s: Path::init("C:a\\b\\"), "C:a\\b");
+ t!(s: Path::init("C:a\\b/"), "C:a\\b");
+ t!(s: Path::init("\\\\?\\z:\\a\\b.txt"), "\\\\?\\z:\\a\\b.txt");
+ t!(s: Path::init("\\\\?\\C:/a/b.txt"), "\\\\?\\C:/a/b.txt");
+ t!(s: Path::init("\\\\?\\C:\\a/b.txt"), "\\\\?\\C:\\a/b.txt");
+ t!(s: Path::init("\\\\?\\test\\a\\b.txt"), "\\\\?\\test\\a\\b.txt");
+ t!(s: Path::init("\\\\?\\foo\\bar\\"), "\\\\?\\foo\\bar\\");
+ t!(s: Path::init("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar");
+ t!(s: Path::init("\\\\.\\"), "\\\\.\\");
+ t!(s: Path::init("\\\\?\\UNC\\server\\share\\foo"), "\\\\?\\UNC\\server\\share\\foo");
+ t!(s: Path::init("\\\\?\\UNC\\server/share"), "\\\\?\\UNC\\server/share\\");
+ t!(s: Path::init("\\\\?\\UNC\\server"), "\\\\?\\UNC\\server\\");
+ t!(s: Path::init("\\\\?\\UNC\\"), "\\\\?\\UNC\\\\");
+ t!(s: Path::init("\\\\?\\UNC"), "\\\\?\\UNC");
// I'm not sure whether \\.\foo/bar should normalize to \\.\foo\bar
// as information is sparse and this isn't really googleable.
// I'm going to err on the side of not normalizing it, as this skips the filesystem
- t!(s: Path::new("\\\\.\\foo/bar"), "\\\\.\\foo/bar");
- t!(s: Path::new("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar");
+ t!(s: Path::init("\\\\.\\foo/bar"), "\\\\.\\foo/bar");
+ t!(s: Path::init("\\\\.\\foo\\bar"), "\\\\.\\foo\\bar");
}
#[test]
fn test_opt_paths() {
- assert_eq!(Path::new_opt(b!("foo\\bar", 0)), None);
- assert_eq!(Path::new_opt(b!("foo\\bar", 0x80)), None);
- t!(v: Path::new_opt(b!("foo\\bar")).unwrap(), b!("foo\\bar"));
- assert_eq!(Path::new_opt("foo\\bar\0"), None);
- t!(s: Path::new_opt("foo\\bar").unwrap(), "foo\\bar");
+ assert_eq!(Path::init_opt(b!("foo\\bar", 0)), None);
+ assert_eq!(Path::init_opt(b!("foo\\bar", 0x80)), None);
+ t!(v: Path::init_opt(b!("foo\\bar")).unwrap(), b!("foo\\bar"));
+ assert_eq!(Path::init_opt("foo\\bar\0"), None);
+ t!(s: Path::init_opt("foo\\bar").unwrap(), "foo\\bar");
}
#[test]
assert_eq!(v.as_slice(), b!("foo\\bar", 0));
(b!("\\bar").to_owned())
}).inside(|| {
- Path::new(b!("foo\\bar", 0))
+ Path::init(b!("foo\\bar", 0))
});
assert!(handled);
assert_eq!(p.as_vec(), b!("\\bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
- Path::new(b!("foo\\bar", 0))
+ Path::init(b!("foo\\bar", 0))
});
})
t!(~"set_filename w\\nul" => {
- let mut p = Path::new(b!("foo\\bar"));
+ let mut p = Path::init(b!("foo\\bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
})
t!(~"push w\\nul" => {
- let mut p = Path::new(b!("foo\\bar"));
+ let mut p = Path::init(b!("foo\\bar"));
cond.trap(|_| {
(b!("null", 0).to_owned())
}).inside(|| {
#[test]
#[should_fail]
fn test_not_utf8_fail() {
- Path::new(b!("hello", 0x80, ".txt"));
+ Path::init(b!("hello", 0x80, ".txt"));
}
#[test]
fn test_display_str() {
- let path = Path::new("foo");
+ let path = Path::init("foo");
assert_eq!(path.display().to_str(), ~"foo");
- let path = Path::new(b!("\\"));
+ let path = Path::init(b!("\\"));
assert_eq!(path.filename_display().to_str(), ~"");
let mut called = false;
- let path = Path::new("foo");
+ let path = Path::init("foo");
path.display().with_str(|s| {
assert_eq!(s, "foo");
called = true;
});
assert!(called);
called = false;
- let path = Path::new(b!("\\"));
+ let path = Path::init(b!("\\"));
path.filename_display().with_str(|s| {
assert_eq!(s, "");
called = true;
macro_rules! t(
($path:expr, $exp:expr, $expf:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let f = format!("{}", path.display());
assert_eq!(f.as_slice(), $exp);
let f = format!("{}", path.filename_display());
macro_rules! t(
(s: $path:expr, $op:ident, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
assert_eq!(path.$op(), Some($exp));
}
);
(s: $path:expr, $op:ident, $exp:expr, opt) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let left = path.$op();
assert_eq!(left, $exp);
}
);
(v: $path:expr, $op:ident, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
assert_eq!(path.$op(), $exp);
}
)
{
let path = ($path);
let join = ($join);
- let mut p1 = Path::new(path);
+ let mut p1 = Path::init(path);
let p2 = p1.clone();
p1.push(join);
assert_eq!(p1, p2.join(join));
// so there's no need for the full set of prefix tests
// we do want to check one odd case though to ensure the prefix is re-parsed
- let mut p = Path::new("\\\\?\\C:");
+ let mut p = Path::init("\\\\?\\C:");
assert_eq!(prefix(&p), Some(VerbatimPrefix(2)));
p.push("foo");
assert_eq!(prefix(&p), Some(VerbatimDiskPrefix));
assert_eq!(p.as_str(), Some("\\\\?\\C:\\foo"));
// and another with verbatim non-normalized paths
- let mut p = Path::new("\\\\?\\C:\\a\\");
+ let mut p = Path::init("\\\\?\\C:\\a\\");
p.push("foo");
assert_eq!(p.as_str(), Some("\\\\?\\C:\\a\\foo"));
}
macro_rules! t(
(s: $path:expr, $push:expr, $exp:expr) => (
{
- let mut p = Path::new($path);
- let push = Path::new($push);
+ let mut p = Path::init($path);
+ let push = Path::init($push);
p.push(&push);
assert_eq!(p.as_str(), Some($exp));
}
macro_rules! t(
(s: $path:expr, $push:expr, $exp:expr) => (
{
- let mut p = Path::new($path);
+ let mut p = Path::init($path);
p.push_many($push);
assert_eq!(p.as_str(), Some($exp));
}
);
(v: $path:expr, $push:expr, $exp:expr) => (
{
- let mut p = Path::new($path);
+ let mut p = Path::init($path);
p.push_many($push);
assert_eq!(p.as_vec(), $exp);
}
(s: $path:expr, $left:expr, $right:expr) => (
{
let pstr = $path;
- let mut p = Path::new(pstr);
+ let mut p = Path::init(pstr);
let result = p.pop();
let left = $left;
assert!(p.as_str() == Some(left),
);
(v: [$($path:expr),+], [$($left:expr),+], $right:expr) => (
{
- let mut p = Path::new(b!($($path),+));
+ let mut p = Path::init(b!($($path),+));
let result = p.pop();
assert_eq!(p.as_vec(), b!($($left),+));
assert_eq!(result, $right);
#[test]
fn test_root_path() {
- assert_eq!(Path::new("a\\b\\c").root_path(), None);
- assert_eq!(Path::new("\\a\\b\\c").root_path(), Some(Path::new("\\")));
- assert_eq!(Path::new("C:a").root_path(), None);
- assert_eq!(Path::new("C:\\a").root_path(), Some(Path::new("C:\\")));
- assert_eq!(Path::new("\\\\a\\b\\c").root_path(), Some(Path::new("\\\\a\\b")));
- assert_eq!(Path::new("\\\\?\\a\\b").root_path(), Some(Path::new("\\\\?\\a")));
- assert_eq!(Path::new("\\\\?\\C:\\a").root_path(), Some(Path::new("\\\\?\\C:\\")));
- assert_eq!(Path::new("\\\\?\\UNC\\a\\b\\c").root_path(),
- Some(Path::new("\\\\?\\UNC\\a\\b")));
- assert_eq!(Path::new("\\\\.\\a\\b").root_path(), Some(Path::new("\\\\.\\a")));
+ assert_eq!(Path::init("a\\b\\c").root_path(), None);
+ assert_eq!(Path::init("\\a\\b\\c").root_path(), Some(Path::init("\\")));
+ assert_eq!(Path::init("C:a").root_path(), None);
+ assert_eq!(Path::init("C:\\a").root_path(), Some(Path::init("C:\\")));
+ assert_eq!(Path::init("\\\\a\\b\\c").root_path(), Some(Path::init("\\\\a\\b")));
+ assert_eq!(Path::init("\\\\?\\a\\b").root_path(), Some(Path::init("\\\\?\\a")));
+ assert_eq!(Path::init("\\\\?\\C:\\a").root_path(), Some(Path::init("\\\\?\\C:\\")));
+ assert_eq!(Path::init("\\\\?\\UNC\\a\\b\\c").root_path(),
+ Some(Path::init("\\\\?\\UNC\\a\\b")));
+ assert_eq!(Path::init("\\\\.\\a\\b").root_path(), Some(Path::init("\\\\.\\a")));
}
#[test]
fn test_join() {
- t!(s: Path::new("a\\b\\c").join(".."), "a\\b");
- t!(s: Path::new("\\a\\b\\c").join("d"), "\\a\\b\\c\\d");
- t!(s: Path::new("a\\b").join("c\\d"), "a\\b\\c\\d");
- t!(s: Path::new("a\\b").join("\\c\\d"), "\\c\\d");
- t!(s: Path::new(".").join("a\\b"), "a\\b");
- t!(s: Path::new("\\").join("a\\b"), "\\a\\b");
- t!(v: Path::new(b!("a\\b\\c")).join(b!("..")), b!("a\\b"));
- t!(v: Path::new(b!("\\a\\b\\c")).join(b!("d")), b!("\\a\\b\\c\\d"));
+ t!(s: Path::init("a\\b\\c").join(".."), "a\\b");
+ t!(s: Path::init("\\a\\b\\c").join("d"), "\\a\\b\\c\\d");
+ t!(s: Path::init("a\\b").join("c\\d"), "a\\b\\c\\d");
+ t!(s: Path::init("a\\b").join("\\c\\d"), "\\c\\d");
+ t!(s: Path::init(".").join("a\\b"), "a\\b");
+ t!(s: Path::init("\\").join("a\\b"), "\\a\\b");
+ t!(v: Path::init(b!("a\\b\\c")).join(b!("..")), b!("a\\b"));
+ t!(v: Path::init(b!("\\a\\b\\c")).join(b!("d")), b!("\\a\\b\\c\\d"));
// full join testing is covered under test_push_path, so no need for
// the full set of prefix tests
}
macro_rules! t(
(s: $path:expr, $join:expr, $exp:expr) => (
{
- let path = Path::new($path);
- let join = Path::new($join);
+ let path = Path::init($path);
+ let join = Path::init($join);
let res = path.join(&join);
assert_eq!(res.as_str(), Some($exp));
}
macro_rules! t(
(s: $path:expr, $join:expr, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let res = path.join_many($join);
assert_eq!(res.as_str(), Some($exp));
}
);
(v: $path:expr, $join:expr, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let res = path.join_many($join);
assert_eq!(res.as_vec(), $exp);
}
(s: $path:expr, $op:ident, $arg:expr, $res:expr) => (
{
let pstr = $path;
- let path = Path::new(pstr);
+ let path = Path::init(pstr);
let arg = $arg;
let res = path.$op(arg);
let exp = $res;
{
let path = $path;
let arg = $arg;
- let mut p1 = Path::new(path);
+ let mut p1 = Path::init(path);
p1.$set(arg);
- let p2 = Path::new(path);
+ let p2 = Path::init(path);
assert_eq!(p1, p2.$with(arg));
}
);
{
let path = $path;
let arg = $arg;
- let mut p1 = Path::new(path);
+ let mut p1 = Path::init(path);
p1.$set(arg);
- let p2 = Path::new(path);
+ let p2 = Path::init(path);
assert_eq!(p1, p2.$with(arg));
}
)
)
)
- t!(v: Path::new(b!("a\\b\\c")), Some(b!("c")), b!("a\\b"), Some(b!("c")), None);
- t!(s: Path::new("a\\b\\c"), Some("c"), Some("a\\b"), Some("c"), None);
- t!(s: Path::new("."), None, Some("."), None, None);
- t!(s: Path::new("\\"), None, Some("\\"), None, None);
- t!(s: Path::new(".."), None, Some(".."), None, None);
- t!(s: Path::new("..\\.."), None, Some("..\\.."), None, None);
- t!(s: Path::new("hi\\there.txt"), Some("there.txt"), Some("hi"),
+ t!(v: Path::init(b!("a\\b\\c")), Some(b!("c")), b!("a\\b"), Some(b!("c")), None);
+ t!(s: Path::init("a\\b\\c"), Some("c"), Some("a\\b"), Some("c"), None);
+ t!(s: Path::init("."), None, Some("."), None, None);
+ t!(s: Path::init("\\"), None, Some("\\"), None, None);
+ t!(s: Path::init(".."), None, Some(".."), None, None);
+ t!(s: Path::init("..\\.."), None, Some("..\\.."), None, None);
+ t!(s: Path::init("hi\\there.txt"), Some("there.txt"), Some("hi"),
Some("there"), Some("txt"));
- t!(s: Path::new("hi\\there"), Some("there"), Some("hi"), Some("there"), None);
- t!(s: Path::new("hi\\there."), Some("there."), Some("hi"),
+ t!(s: Path::init("hi\\there"), Some("there"), Some("hi"), Some("there"), None);
+ t!(s: Path::init("hi\\there."), Some("there."), Some("hi"),
Some("there"), Some(""));
- t!(s: Path::new("hi\\.there"), Some(".there"), Some("hi"), Some(".there"), None);
- t!(s: Path::new("hi\\..there"), Some("..there"), Some("hi"),
+ t!(s: Path::init("hi\\.there"), Some(".there"), Some("hi"), Some(".there"), None);
+ t!(s: Path::init("hi\\..there"), Some("..there"), Some("hi"),
Some("."), Some("there"));
// these are already tested in test_components, so no need for extended tests
#[test]
fn test_dir_path() {
- t!(s: Path::new("hi\\there").dir_path(), "hi");
- t!(s: Path::new("hi").dir_path(), ".");
- t!(s: Path::new("\\hi").dir_path(), "\\");
- t!(s: Path::new("\\").dir_path(), "\\");
- t!(s: Path::new("..").dir_path(), "..");
- t!(s: Path::new("..\\..").dir_path(), "..\\..");
+ t!(s: Path::init("hi\\there").dir_path(), "hi");
+ t!(s: Path::init("hi").dir_path(), ".");
+ t!(s: Path::init("\\hi").dir_path(), "\\");
+ t!(s: Path::init("\\").dir_path(), "\\");
+ t!(s: Path::init("..").dir_path(), "..");
+ t!(s: Path::init("..\\..").dir_path(), "..\\..");
// dir_path is just dirname interpreted as a path.
// No need for extended tests
macro_rules! t(
($path:expr, $abs:expr, $vol:expr, $cwd:expr, $rel:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let (abs, vol, cwd, rel) = ($abs, $vol, $cwd, $rel);
let b = path.is_absolute();
assert!(b == abs, "Path '{}'.is_absolute(): expected {:?}, found {:?}",
macro_rules! t(
(s: $path:expr, $dest:expr, $exp:expr) => (
{
- let path = Path::new($path);
- let dest = Path::new($dest);
+ let path = Path::init($path);
+ let dest = Path::init($dest);
let exp = $exp;
let res = path.is_ancestor_of(&dest);
assert!(res == exp,
macro_rules! t(
(s: $path:expr, $child:expr, $exp:expr) => (
{
- let path = Path::new($path);
- let child = Path::new($child);
+ let path = Path::init($path);
+ let child = Path::init($child);
assert_eq!(path.ends_with_path(&child), $exp);
}
);
macro_rules! t(
(s: $path:expr, $other:expr, $exp:expr) => (
{
- let path = Path::new($path);
- let other = Path::new($other);
+ let path = Path::init($path);
+ let other = Path::init($other);
let res = path.path_relative_from(&other);
let exp = $exp;
assert!(res.as_ref().and_then(|x| x.as_str()) == exp,
macro_rules! t(
(s: $path:expr, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let comps = path.str_components().map(|x|x.unwrap()).to_owned_vec();
let exp: &[&str] = $exp;
assert!(comps.as_slice() == exp,
);
(v: [$($arg:expr),+], $exp:expr) => (
{
- let path = Path::new(b!($($arg),+));
+ let path = Path::init(b!($($arg),+));
let comps = path.str_components().map(|x|x.unwrap()).to_owned_vec();
let exp: &[&str] = $exp;
assert!(comps.as_slice() == exp,
macro_rules! t(
(s: $path:expr, $exp:expr) => (
{
- let path = Path::new($path);
+ let path = Path::init($path);
let comps = path.components().to_owned_vec();
let exp: &[&[u8]] = $exp;
assert!(comps.as_slice() == exp, "components: Expected {:?}, found {:?}",
#[cfg(unix)]
pub fn new() -> OSRng {
use path::Path;
- let reader = File::open(&Path::new("/dev/urandom"));
+ let reader = File::open(&Path::init("/dev/urandom"));
let reader = reader.expect("Error opening /dev/urandom");
let reader_rng = ReaderRng::new(reader);
if cfg!(unix) {
os::tmpdir().join(rand::task_rng().gen_ascii_str(20))
} else {
- Path::new(r"\\.\pipe\" + rand::task_rng().gen_ascii_str(20))
+ Path::init(r"\\.\pipe\" + rand::task_rng().gen_ascii_str(20))
}
}
let output = str::from_utf8(prog.finish_with_output().output);
let parent_dir = os::getcwd();
- let child_dir = Path::new(output.trim());
+ let child_dir = Path::init(output.trim());
let parent_stat = parent_dir.stat();
let child_stat = child_dir.stat();
let mut prog = run_pwd(Some(&parent_dir));
let output = str::from_utf8(prog.finish_with_output().output);
- let child_dir = Path::new(output.trim());
+ let child_dir = Path::init(output.trim());
let parent_stat = parent_dir.stat();
let child_stat = child_dir.stat();
fn test_errors_do_not_crash() {
// Open /dev/null as a library to get an error, and make sure
// that only causes an error, and not a crash.
- let path = GenericPath::new("/dev/null");
+ let path = GenericPath::init("/dev/null");
match DynamicLibrary::open(Some(&path)) {
Err(_) => {}
Ok(_) => fail!("Successfully opened the empty library.")
let file = get_single_str_from_tts(cx, sp, tts, "include!");
let p = parse::new_sub_parser_from_file(
cx.parse_sess(), cx.cfg(),
- &res_rel_file(cx, sp, &Path::new(file)), sp);
+ &res_rel_file(cx, sp, &Path::init(file)), sp);
base::MRExpr(p.parse_expr())
}
pub fn expand_include_str(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
-> base::MacResult {
let file = get_single_str_from_tts(cx, sp, tts, "include_str!");
- let file = res_rel_file(cx, sp, &Path::new(file));
+ let file = res_rel_file(cx, sp, &Path::init(file));
let bytes = match io::result(|| File::open(&file).read_to_end()) {
Err(e) => {
cx.span_fatal(sp, format!("couldn't read {}: {}",
use std::at_vec;
let file = get_single_str_from_tts(cx, sp, tts, "include_bin!");
- let file = res_rel_file(cx, sp, &Path::new(file));
+ let file = res_rel_file(cx, sp, &Path::init(file));
match io::result(|| File::open(&file).read_to_end()) {
Err(e) => {
cx.span_fatal(sp, format!("couldn't read {}: {}",
fn res_rel_file(cx: @ExtCtxt, sp: codemap::Span, arg: &Path) -> Path {
// NB: relative paths are resolved relative to the compilation unit
if !arg.is_absolute() {
- let mut cu = Path::new(cx.codemap().span_to_filename(sp));
+ let mut cu = Path::init(cx.codemap().span_to_filename(sp));
cu.pop();
cu.push(arg);
cu
outer_attrs: &[ast::Attribute],
id_sp: Span)
-> (ast::item_, ~[ast::Attribute]) {
- let mut prefix = Path::new(self.sess.cm.span_to_filename(*self.span));
+ let mut prefix = Path::init(self.sess.cm.span_to_filename(*self.span));
prefix.pop();
let mod_path_stack = &*self.mod_path_stack;
- let mod_path = Path::new(".").join_many(*mod_path_stack);
+ let mod_path = Path::init(".").join_many(*mod_path_stack);
let dir_path = prefix.join(&mod_path);
let file_path = match ::attr::first_attr_value_str_by_name(
outer_attrs, "path") {
fn read_line() {
use std::io::buffered::BufferedReader;
- let mut path = Path::new(env!("CFG_SRC_DIR"));
+ let mut path = Path::init(env!("CFG_SRC_DIR"));
path.push("src/test/bench/shootout-k-nucleotide.data");
for _ in range(0, 3) {
};
let writer = if os::getenv("RUST_BENCH").is_some() {
- let file = File::create(&Path::new("./shootout-fasta.data"));
+ let file = File::create(&Path::init("./shootout-fasta.data"));
@mut file as @mut io::Writer
} else {
@mut io::stdout() as @mut io::Writer
pub fn main() {
fn mk_file(path: &str, directory: bool) {
if directory {
- io::fs::mkdir(&Path::new(path), io::UserRWX);
+ io::fs::mkdir(&Path::init(path), io::UserRWX);
} else {
- io::File::create(&Path::new(path));
+ io::File::create(&Path::init(path));
}
}
fn abs_path(path: &str) -> Path {
- os::getcwd().join(&Path::new(path))
+ os::getcwd().join(&Path::init(path))
}
fn glob_vec(pattern: &str) -> ~[Path] {
{
let loader: rsrc_loader = proc(_path) {result::Ok(~"more blah")};
- let path = path::Path::new("blah");
+ let path = path::Path::init("blah");
assert!(loader(&path).is_ok());
}
use std::io::File;
pub fn main() {
- let dir = tempfile::TempDir::new_in(&Path::new("."), "").unwrap();
+ let dir = tempfile::TempDir::new_in(&Path::init("."), "").unwrap();
let path = dir.path().join("file");
{
fn test_tempdir() {
let path = {
- let p = TempDir::new_in(&Path::new("."), "foobar").unwrap();
+ let p = TempDir::new_in(&Path::init("."), "foobar").unwrap();
let p = p.path();
assert!(p.as_vec().ends_with(bytes!("foobar")));
p.clone()
// Ideally these would be in std::os but then core would need
// to depend on std
fn recursive_mkdir_rel() {
- let path = Path::new("frob");
+ let path = Path::init("frob");
let cwd = os::getcwd();
debug!("recursive_mkdir_rel: Making: {} in cwd {} [{:?}]", path.display(),
cwd.display(), path.exists());
}
fn recursive_mkdir_dot() {
- let dot = Path::new(".");
+ let dot = Path::init(".");
fs::mkdir_recursive(&dot, io::UserRWX);
- let dotdot = Path::new("..");
+ let dotdot = Path::init("..");
fs::mkdir_recursive(&dotdot, io::UserRWX);
}
fn recursive_mkdir_rel_2() {
- let path = Path::new("./frob/baz");
+ let path = Path::init("./frob/baz");
let cwd = os::getcwd();
debug!("recursive_mkdir_rel_2: Making: {} in cwd {} [{:?}]", path.display(),
cwd.display(), path.exists());
fs::mkdir_recursive(&path, io::UserRWX);
assert!(path.is_dir());
assert!(path.dir_path().is_dir());
- let path2 = Path::new("quux/blat");
+ let path2 = Path::init("quux/blat");
debug!("recursive_mkdir_rel_2: Making: {} in cwd {}", path2.display(),
cwd.display());
fs::mkdir_recursive(&path2, io::UserRWX);