]> git.proxmox.com Git - cargo.git/commitdiff
Remove Location, use Url everywhere
authorAlex Crichton <alex@alexcrichton.com>
Wed, 6 Aug 2014 16:21:10 +0000 (09:21 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 7 Aug 2014 00:09:24 +0000 (17:09 -0700)
Now that rust-url supports windows paths in URLs, this commit jettisons the
janky Location enum in favor of just using Url everywhere.

27 files changed:
Cargo.lock
src/bin/cargo-git-checkout.rs
src/bin/cargo-read-manifest.rs
src/cargo/core/package_id.rs
src/cargo/core/resolver.rs
src/cargo/core/source.rs
src/cargo/ops/cargo_clean.rs
src/cargo/ops/cargo_compile.rs
src/cargo/ops/cargo_doc.rs
src/cargo/ops/cargo_generate_lockfile.rs
src/cargo/ops/cargo_run.rs
src/cargo/sources/git/source.rs
src/cargo/sources/git/utils.rs
src/cargo/sources/path.rs
src/cargo/util/errors.rs
src/cargo/util/to_url.rs
src/cargo/util/toml.rs
tests/support/mod.rs
tests/test_cargo_compile.rs
tests/test_cargo_compile_git_deps.rs
tests/test_cargo_compile_path_deps.rs
tests/test_cargo_cross_compile.rs
tests/test_cargo_doc.rs
tests/test_cargo_freshness.rs
tests/test_cargo_run.rs
tests/test_cargo_test.rs
tests/tests.rs

index b21911995feccd8356bd08266947d5b827e1b752..cf681f64b2f2501f68284d6f23101283d215f8dc 100644 (file)
@@ -6,8 +6,8 @@ dependencies = [
  "docopt_macros 0.6.0 (git+https://github.com/burntsushi/docopt.rs#fd2377d1c36b2671136cd36566aad5d54c2fb17e)",
  "hamcrest 0.1.0 (git+https://github.com/carllerche/hamcrest-rust.git#c23b8769f20f306c59a96b22532bb09b33faa764)",
  "semver 0.0.1 (git+https://github.com/rust-lang/semver#e17191f51d543529a6f07e6731802b77977fcef8)",
- "toml 0.1.0 (git+https://github.com/alexcrichton/toml-rs#7e1c1e127d952066bda5fbc94e3cbdb40e912119)",
- "url 0.1.0 (git+https://github.com/servo/rust-url#3d54552e06062835edf8b8e3a8664272e2fdab61)",
+ "toml 0.1.0 (git+https://github.com/alexcrichton/toml-rs#934e093047ae15432fcc772d4e01fdf5fd56d2fb)",
+ "url 0.1.0 (git+https://github.com/servo/rust-url#ad61773abc56d812f8abe4bc78833f422a5f6a94)",
 ]
 
 [[package]]
@@ -26,7 +26,7 @@ dependencies = [
 [[package]]
 name = "encoding"
 version = "0.1.0"
-source = "git+https://github.com/lifthrasiir/rust-encoding#12b6610adff6eddc060691888c36017cd3ad57f7"
+source = "git+https://github.com/lifthrasiir/rust-encoding#eae7c261f50cfbdc699e9b234d2b13d4d255fd42"
 
 [[package]]
 name = "hamcrest"
@@ -41,13 +41,13 @@ source = "git+https://github.com/rust-lang/semver#e17191f51d543529a6f07e6731802b
 [[package]]
 name = "toml"
 version = "0.1.0"
-source = "git+https://github.com/alexcrichton/toml-rs#7e1c1e127d952066bda5fbc94e3cbdb40e912119"
+source = "git+https://github.com/alexcrichton/toml-rs#934e093047ae15432fcc772d4e01fdf5fd56d2fb"
 
 [[package]]
 name = "url"
 version = "0.1.0"
-source = "git+https://github.com/servo/rust-url#3d54552e06062835edf8b8e3a8664272e2fdab61"
+source = "git+https://github.com/servo/rust-url#ad61773abc56d812f8abe4bc78833f422a5f6a94"
 dependencies = [
- "encoding 0.1.0 (git+https://github.com/lifthrasiir/rust-encoding#12b6610adff6eddc060691888c36017cd3ad57f7)",
+ "encoding 0.1.0 (git+https://github.com/lifthrasiir/rust-encoding#eae7c261f50cfbdc699e9b234d2b13d4d255fd42)",
 ]
 
index 4087b8b0d173bd21fce7318cc024fb1143646ad8..8994e840b1d29196ff6dab1b61bbfbf989b3681a 100644 (file)
@@ -12,8 +12,7 @@ use cargo::{execute_main_without_stdin};
 use cargo::core::MultiShell;
 use cargo::core::source::{Source, SourceId};
 use cargo::sources::git::{GitSource};
-use cargo::util::{Config, CliResult, CliError, human};
-use url::Url;
+use cargo::util::{Config, CliResult, CliError, human, ToUrl};
 
 docopt!(Options, "
 Usage:
@@ -31,11 +30,11 @@ fn main() {
 fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
     let Options { flag_url: url, flag_reference: reference, .. } = options;
 
-    let url: Url = try!(Url::parse(url.as_slice()).map_err(|e| {
-                            human(format!("The URL `{}` you passed was \
-                                           not a valid URL: {}", url, e))
-                        })
-                        .map_err(|e| CliError::from_boxed(e, 1)));
+    let url = try!(url.as_slice().to_url().map_err(|e| {
+                       human(format!("The URL `{}` you passed was \
+                                      not a valid URL: {}", url, e))
+                   })
+                   .map_err(|e| CliError::from_boxed(e, 1)));
 
     let source_id = SourceId::for_git(&url, reference.as_slice(), None);
 
index 7cb001652dff591c4a012af493b87f4178a80766..2300912e83826da197627a6cde39643ed994129f 100644 (file)
@@ -25,7 +25,9 @@ fn main() {
 
 fn execute(options: Options, _: &mut MultiShell) -> CliResult<Option<Package>> {
     let path = Path::new(options.flag_manifest_path.as_slice());
-    let mut source = PathSource::for_path(&path);
+    let mut source = try!(PathSource::for_path(&path).map_err(|e| {
+        CliError::new(e.description(), 1)
+    }));
 
     try!(source.update().map_err(|err| CliError::new(err.description(), 1)));
 
index 783e6e22f12853c891c6d2c364a0a92d1b7fc8bb..8f7f9933a061a3f93fe3d33be1b7fb0ac8b8bdb2 100644 (file)
@@ -151,31 +151,15 @@ impl Show for PackageId {
     }
 }
 
-//impl<D: Decoder<Box<CargoError + Send>>>
-    //Decodable<D,Box<CargoError + Send>>
-    //for PackageId
-//{
-    //fn decode(d: &mut D) -> CargoResult<PackageId> {
-        //let (name, version, source_id): (String, String, SourceId) = try!(Decodable::decode(d));
-
-        //PackageId::new(name.as_slice(), version.as_slice(), &source_id)
-    //}
-//}
-
-//impl<E, S: Encoder<E>> Encodable<S,E> for PackageId {
-    //fn encode(&self, e: &mut S) -> Result<(), E> {
-        //(self.name.clone(), self.version.to_string(), self.source_id.clone()).encode(e)
-    //}
-//}
-
 #[cfg(test)]
 mod tests {
     use super::{PackageId, central_repo};
-    use core::source::{Location, RegistryKind, SourceId};
+    use core::source::{RegistryKind, SourceId};
+    use util::ToUrl;
 
     #[test]
     fn invalid_version_handled_nicely() {
-        let loc = Location::parse(central_repo).unwrap();
+        let loc = central_repo.to_url().unwrap();
         let repo = SourceId::new(RegistryKind, loc);
 
         assert!(PackageId::new("foo", "1.0", &repo).is_err());
index b7e1a6b9ebe6daf0090a0140b0d444d4f65d356a..43cb2e3b4a0edebee876c22a390d7460b79974b0 100644 (file)
@@ -312,7 +312,7 @@ fn resolve_deps<'a, R: Registry>(parent: &PackageId,
 mod test {
     use hamcrest::{assert_that, equal_to, contains};
 
-    use core::source::{SourceId, RegistryKind, GitKind, Location, Remote};
+    use core::source::{SourceId, RegistryKind, GitKind};
     use core::{Dependency, PackageId, Summary, Registry};
     use util::{CargoResult, ToUrl};
 
@@ -329,7 +329,7 @@ mod test {
     impl ToDep for &'static str {
         fn to_dep(self) -> Dependency {
             let url = "http://example.com".to_url().unwrap();
-            let source_id = SourceId::new(RegistryKind, Remote(url));
+            let source_id = SourceId::new(RegistryKind, url);
             Dependency::parse(self, Some("1.0.0"), &source_id).unwrap()
         }
     }
@@ -355,7 +355,7 @@ mod test {
     )
 
     fn registry_loc() -> SourceId {
-        let remote = Location::parse("http://example.com").unwrap();
+        let remote = "http://example.com".to_url().unwrap();
         SourceId::new(RegistryKind, remote)
     }
 
@@ -368,7 +368,7 @@ mod test {
     }
 
     fn pkg_id_loc(name: &str, loc: &str) -> PackageId {
-        let remote = Location::parse(loc);
+        let remote = loc.to_url();
         let source_id = SourceId::new(GitKind("master".to_string()),
                                       remote.unwrap());
 
@@ -381,13 +381,13 @@ mod test {
 
     fn dep(name: &str) -> Dependency {
         let url = "http://example.com".to_url().unwrap();
-        let source_id = SourceId::new(RegistryKind, Remote(url));
+        let source_id = SourceId::new(RegistryKind, url);
         Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
     }
 
     fn dep_loc(name: &str, location: &str) -> Dependency {
         let url = location.to_url().unwrap();
-        let source_id = SourceId::new(GitKind("master".to_string()), Remote(url));
+        let source_id = SourceId::new(GitKind("master".to_string()), url);
         Dependency::parse(name, Some("1.0.0"), &source_id).unwrap()
     }
 
index a3a28e61abc7986f8c854f66520650dba87f6f6f..dfa80d06ded4b8476a8bbd3207c6f546b1061a98 100644 (file)
@@ -1,4 +1,3 @@
-use std::c_str::CString;
 use std::cmp::Ordering;
 use std::collections::HashMap;
 use std::collections::hashmap::{Values, MutEntries};
@@ -56,44 +55,16 @@ pub enum SourceKind {
     RegistryKind
 }
 
-#[deriving(Clone, PartialEq, Eq, Hash)]
-pub enum Location {
-    Local(Path),
-    Remote(Url),
-}
-
 type Error = Box<CargoError + Send>;
 
-impl<E, D: Decoder<E>> Decodable<D, E> for Location {
-    fn decode(d: &mut D) -> Result<Location, E> {
-        let url: String  = raw_try!(Decodable::decode(d));
-        Ok(Location::parse(url.as_slice()).unwrap())
-    }
-}
-
-impl<E, S: Encoder<E>> Encodable<S, E> for Location {
-    fn encode(&self, e: &mut S) -> Result<(), E> {
-        self.to_string().encode(e)
-    }
-}
-
 #[deriving(Clone, Eq)]
 pub struct SourceId {
-    pub location: Location,
+    pub url: Url,
     pub kind: SourceKind,
     // e.g. the exact git revision of the specified branch for a Git Source
     pub precise: Option<String>
 }
 
-impl Show for Location {
-    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        match *self {
-            Local(ref p) => write!(f, "file:{}", p.display()),
-            Remote(ref u) => write!(f, "{}", u),
-        }
-    }
-}
-
 impl PartialOrd for SourceId {
     fn partial_cmp(&self, other: &SourceId) -> Option<Ordering> {
         self.to_string().partial_cmp(&other.to_string())
@@ -106,29 +77,6 @@ impl Ord for SourceId {
     }
 }
 
-impl Location {
-    pub fn parse(s: &str) -> CargoResult<Location> {
-        if s.starts_with("file:") {
-            Ok(Local(Path::new(s.slice_from(5))))
-        } else {
-            s.to_url().map(Remote).map_err(|e| {
-                human(format!("invalid url `{}`: `{}", s, e))
-            })
-        }
-    }
-}
-
-impl<'a> ToCStr for &'a Location {
-    fn to_c_str(&self) -> CString {
-        match **self {
-            Local(ref p) => p.to_c_str(),
-            Remote(ref u) => u.to_string().to_c_str(),
-        }
-    }
-
-    unsafe fn to_c_str_unchecked(&self) -> CString { self.to_c_str() }
-}
-
 impl<E, S: Encoder<E>> Encodable<S, E> for SourceId {
     fn encode(&self, s: &mut S) -> Result<(), E> {
         if self.is_path() {
@@ -149,11 +97,9 @@ impl<E, D: Decoder<E>> Decodable<D, E> for SourceId {
 impl Show for SourceId {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
         match *self {
-            SourceId { kind: PathKind, ref location, .. } => {
-                try!(write!(f, "{}", location))
-            },
-            SourceId { kind: GitKind(ref reference), ref location, ref precise, .. } => {
-                try!(write!(f, "{}", location));
+            SourceId { kind: PathKind, ref url, .. } => url.fmt(f),
+            SourceId { kind: GitKind(ref reference), ref url, ref precise, .. } => {
+                try!(write!(f, "{}", url));
                 if reference.as_slice() != "master" {
                     try!(write!(f, "?ref={}", reference));
                 }
@@ -164,14 +110,13 @@ impl Show for SourceId {
                     }
                     None => {}
                 }
+                Ok(())
             },
             SourceId { kind: RegistryKind, .. } => {
                 // TODO: Central registry vs. alternates
-                try!(write!(f, "the package registry"));
+                write!(f, "the package registry")
             }
         }
-
-        Ok(())
     }
 }
 
@@ -181,14 +126,12 @@ impl Show for SourceId {
 impl PartialEq for SourceId {
     fn eq(&self, other: &SourceId) -> bool {
         if self.kind != other.kind { return false }
-        if self.location == other.location { return true }
+        if self.url == other.url { return true }
 
-        match (&self.kind, &other.kind, &self.location, &other.location) {
-            (&GitKind(ref ref1), &GitKind(ref ref2),
-             &Remote(ref u1), &Remote(ref u2)) => {
+        match (&self.kind, &other.kind, &self.url, &other.url) {
+            (&GitKind(ref ref1), &GitKind(ref ref2), u1, u2) => {
                 ref1 == ref2 &&
-                git::canonicalize_url(u1.to_string().as_slice()) ==
-                    git::canonicalize_url(u2.to_string().as_slice())
+                git::canonicalize_url(u1) == git::canonicalize_url(u2)
             }
             _ => false,
         }
@@ -197,26 +140,19 @@ impl PartialEq for SourceId {
 
 impl<S: hash::Writer> hash::Hash<S> for SourceId {
     fn hash(&self, into: &mut S) {
+        self.kind.hash(into);
         match *self {
-            SourceId {
-                kind: ref kind @ GitKind(..),
-                location: Remote(ref url),
-                precise: _,
-            } => {
-                kind.hash(into);
-                git::canonicalize_url(url.to_string().as_slice()).hash(into);
-            }
-            _ => {
-                self.kind.hash(into);
-                self.location.hash(into);
+            SourceId { kind: GitKind(..), ref url, .. } => {
+                git::canonicalize_url(url).hash(into)
             }
+            _ => self.url.hash(into),
         }
     }
 }
 
 impl SourceId {
-    pub fn new(kind: SourceKind, location: Location) -> SourceId {
-        SourceId { kind: kind, location: location, precise: None }
+    pub fn new(kind: SourceKind, url: Url) -> SourceId {
+        SourceId { kind: kind, url: url, precise: None }
     }
 
     pub fn from_url(string: String) -> SourceId {
@@ -225,28 +161,6 @@ impl SourceId {
         let url = parts.next().unwrap();
 
         match kind {
-            "git" if url.starts_with("file:") => {
-                let url = url.slice_from(5);
-                let (url, precise) = match url.rfind('#') {
-                    Some(pos) => {
-                        (url.slice_to(pos), Some(url.slice_from(pos + 1)))
-                    }
-                    None => (url, None)
-                };
-                let (url, reference) = match url.find_str("?ref=") {
-                    Some(pos) => {
-                        (url.slice_to(pos), Some(url.slice_from(pos + 5)))
-                    }
-                    None => (url, None)
-                };
-                let reference = reference.unwrap_or("master");
-                let id = SourceId::new(GitKind(reference.to_string()),
-                                       Local(Path::new(url)));
-                match precise {
-                    Some(p) => id.with_precise(p.to_string()),
-                    None => id,
-                }
-            }
             "git" => {
                 let mut url = url.to_url().unwrap();
                 let mut reference = "master".to_string();
@@ -261,7 +175,7 @@ impl SourceId {
                 SourceId::for_git(&url, reference.as_slice(), precise)
             },
             "registry" => SourceId::for_central(),
-            "path" => SourceId::for_path(&Path::new(url.slice_from(5))),
+            "path" => SourceId::for_path(&Path::new(url.slice_from(5))).unwrap(),
             _ => fail!("Unsupported serialized SourceId")
         }
     }
@@ -273,7 +187,7 @@ impl SourceId {
                        so this is unimplemented")
             },
             SourceId {
-                kind: GitKind(ref reference), ref location, ref precise, ..
+                kind: GitKind(ref reference), ref url, ref precise, ..
             } => {
                 let ref_str = if reference.as_slice() != "master" {
                     format!("?ref={}", reference)
@@ -287,7 +201,7 @@ impl SourceId {
                     "".to_string()
                 };
 
-                format!("git+{}{}{}", location, ref_str, precise_str)
+                format!("git+{}{}{}", url, ref_str, precise_str)
             },
             SourceId { kind: RegistryKind, .. } => {
                 // TODO: Central registry vs. alternates
@@ -297,12 +211,15 @@ impl SourceId {
     }
 
     // Pass absolute path
-    pub fn for_path(path: &Path) -> SourceId {
-        SourceId::new(PathKind, Local(path.clone()))
+    pub fn for_path(path: &Path) -> CargoResult<SourceId> {
+        let url = try!(Url::from_file_path(path).map_err(|()| {
+            human(format!("not a valid path for a URL: {}", path.display()))
+        }));
+        Ok(SourceId::new(PathKind, url))
     }
 
     pub fn for_git(url: &Url, reference: &str, precise: Option<String>) -> SourceId {
-        let mut id = SourceId::new(GitKind(reference.to_string()), Remote(url.clone()));
+        let mut id = SourceId::new(GitKind(reference.to_string()), url.clone());
         if precise.is_some() {
             id = id.with_precise(precise.unwrap());
         }
@@ -312,11 +229,11 @@ impl SourceId {
 
     pub fn for_central() -> SourceId {
         SourceId::new(RegistryKind,
-                      Remote("https://example.com".to_url().unwrap()))
+                      "https://example.com".to_url().unwrap())
     }
 
-    pub fn get_location(&self) -> &Location {
-        &self.location
+    pub fn get_url(&self) -> &Url {
+        &self.url
     }
 
     pub fn is_path(&self) -> bool {
@@ -335,11 +252,11 @@ impl SourceId {
         match self.kind {
             GitKind(..) => box GitSource::new(self, config) as Box<Source>,
             PathKind => {
-                let path = match self.location {
-                    Local(ref p) => p,
-                    Remote(..) => fail!("path sources cannot be remote"),
+                let path = match self.url.to_file_path() {
+                    Ok(p) => p,
+                    Err(()) => fail!("path sources cannot be remote"),
                 };
-                box PathSource::new(path, self) as Box<Source>
+                box PathSource::new(&path, self) as Box<Source>
             },
             RegistryKind => box DummyRegistrySource::new(self) as Box<Source>,
         }
@@ -470,15 +387,15 @@ impl Source for SourceSet {
 
 #[cfg(test)]
 mod tests {
-    use super::{SourceId, Remote, GitKind};
+    use super::{SourceId, GitKind};
     use util::ToUrl;
 
     #[test]
     fn github_sources_equal() {
-        let loc = Remote("https://github.com/foo/bar".to_url().unwrap());
+        let loc = "https://github.com/foo/bar".to_url().unwrap();
         let s1 = SourceId::new(GitKind("master".to_string()), loc);
 
-        let loc = Remote("git://github.com/foo/bar".to_url().unwrap());
+        let loc = "git://github.com/foo/bar".to_url().unwrap();
         let mut s2 = SourceId::new(GitKind("master".to_string()), loc);
 
         assert_eq!(s1, s2);
index 434bb65e26b74aa45248db739496d2573a91c78a..44c64ff846bb55e87ddbb748098c97c762d1a433 100644 (file)
@@ -7,7 +7,7 @@ use util::{CargoResult, human, ChainError};
 /// Cleans the project from build artifacts.
 
 pub fn clean(manifest_path: &Path) -> CargoResult<()> {
-    let mut src = PathSource::for_path(&manifest_path.dir_path());
+    let mut src = try!(PathSource::for_path(&manifest_path.dir_path()));
     try!(src.update());
     let root = try!(src.get_root_package());
     let manifest = root.get_manifest();
index 3b605e1a99e1edbb000984632df6494ad112bbc2..c0effe7d215da8a9209f030dc60efd5814b5c807 100644 (file)
@@ -24,6 +24,7 @@
 
 use std::os;
 use std::collections::{HashMap, HashSet};
+use std::result;
 
 use core::registry::PackageRegistry;
 use core::{MultiShell, Source, SourceId, PackageSet, Target, PackageId};
@@ -56,8 +57,7 @@ pub fn compile(manifest_path: &Path,
                           `cargo update` command instead"));
     }
 
-    let mut source = PathSource::for_path(&manifest_path.dir_path());
-
+    let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
     try!(source.update());
 
     // TODO: Move this into PathSource
@@ -144,11 +144,9 @@ fn source_ids_from_config(configs: &HashMap<String, config::ConfigValue>,
 
     // Make sure we don't override the local package, even if it's in the list
     // of override paths
-    Ok(paths.iter().filter(|p| {
+    result::collect(paths.iter().filter(|p| {
         cur_path != os::make_absolute(&Path::new(p.as_slice()))
-    }).map(|p| {
-        SourceId::for_path(&Path::new(p.as_slice()))
-    }).collect())
+    }).map(|p| SourceId::for_path(&Path::new(p.as_slice()))))
 }
 
 fn scrape_target_config(config: &mut Config,
index 1b3264e66dbd9c3ae31443d4996907c054e9fbfa..486b5e46f55656270628c0e04a8a8d85a8ae4fb4 100644 (file)
@@ -12,7 +12,7 @@ pub struct DocOptions<'a> {
 
 pub fn doc(manifest_path: &Path,
            options: &mut DocOptions) -> CargoResult<()> {
-    let mut source = PathSource::for_path(&manifest_path.dir_path());
+    let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
     try!(source.update());
     let package = try!(source.get_root_package());
 
index ec35b61892ffcf54587337428b79b86f30934e79..2851da52f0255b67315662663e767a635d3b7fff 100644 (file)
@@ -21,7 +21,7 @@ pub fn generate_lockfile(manifest_path: &Path,
 
     log!(4, "compile; manifest-path={}", manifest_path.display());
 
-    let mut source = PathSource::for_path(&manifest_path.dir_path());
+    let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
     try!(source.update());
 
     // TODO: Move this into PathSource
@@ -47,7 +47,7 @@ pub fn generate_lockfile(manifest_path: &Path,
 pub fn update_lockfile(manifest_path: &Path,
                        shell: &mut MultiShell,
                        to_update: Option<String>) -> CargoResult<()> {
-    let mut source = PathSource::for_path(&manifest_path.dir_path());
+    let mut source = try!(PathSource::for_path(&manifest_path.dir_path()));
     try!(source.update());
     let package = try!(source.get_root_package());
 
index dcf2e1ab707173721a638c75c82c735612d68994..91879706a3dda2fa9cb78bb70c720f73d7ad123f 100644 (file)
@@ -12,7 +12,7 @@ pub fn run(manifest_path: &Path,
         return Err(human("`src/main.rs` must be present for `cargo run`"))
     }
 
-    let mut src = PathSource::for_path(&manifest_path.dir_path());
+    let mut src = try!(PathSource::for_path(&manifest_path.dir_path()));
     try!(src.update());
     let root = try!(src.get_root_package());
 
index 032b36cd8181151a8023711fc0f9060e3891d998..743a2c3918fd577a122b47c7213b6b9d2f306d90 100644 (file)
@@ -2,9 +2,10 @@ use std::fmt::{Show,Formatter};
 use std::fmt;
 use std::hash::Hasher;
 use std::hash::sip::SipHasher;
-use std::str;
+use std::mem;
+use url::{mod, Url};
 
-use core::source::{Source, SourceId, GitKind, Location, Remote, Local};
+use core::source::{Source, SourceId, GitKind};
 use core::{Package, PackageId, Summary, Registry, Dependency};
 use util::{CargoResult, Config, to_hex};
 use sources::PathSource;
@@ -33,8 +34,8 @@ impl<'a, 'b> GitSource<'a, 'b> {
             _ => fail!("Not a git source; id={}", source_id)
         };
 
-        let remote = GitRemote::new(source_id.get_location());
-        let ident = ident(source_id.get_location());
+        let remote = GitRemote::new(source_id.get_url());
+        let ident = ident(source_id.get_url());
 
         let db_path = config.git_db_path()
             .join(ident.as_slice());
@@ -59,28 +60,20 @@ impl<'a, 'b> GitSource<'a, 'b> {
         }
     }
 
-    pub fn get_location(&self) -> &Location {
-        self.remote.get_location()
+    pub fn get_url(&self) -> &Url {
+        self.remote.get_url()
     }
 }
 
-fn ident(location: &Location) -> String {
+fn ident(url: &Url) -> String {
     let hasher = SipHasher::new_with_keys(0,0);
 
     // FIXME: this really should be able to not use to_str() everywhere, but the
     //        compiler seems to currently ask for static lifetimes spuriously.
     //        Perhaps related to rust-lang/rust#15144
-    let ident = match *location {
-        Local(ref path) => {
-            let last = path.components().last().unwrap();
-            str::from_utf8(last).unwrap().to_string()
-        }
-        Remote(ref url) => {
-            let path = url.path().unwrap().connect("/");
-            let path = canonicalize_url(path.as_slice());
-            path.as_slice().split('/').last().unwrap().to_string()
-        }
-    };
+    let url = canonicalize_url(url);
+    let ident = url.path().unwrap_or(&[])
+                   .last().map(|a| a.clone()).unwrap_or(String::new());
 
     let ident = if ident.as_slice() == "" {
         "_empty".to_string()
@@ -88,57 +81,64 @@ fn ident(location: &Location) -> String {
         ident
     };
 
-    let location = canonicalize_url(location.to_string().as_slice());
-
-    format!("{}-{}", ident, to_hex(hasher.hash(&location.as_slice())))
-}
-
-fn strip_trailing_slash(path: &str) -> &str {
-    // Remove the trailing '/' so that 'split' doesn't give us
-    // an empty string, making '../foo/' and '../foo' both
-    // result in the name 'foo' (#84)
-    if path.as_bytes().last() != Some(&('/' as u8)) {
-        path.clone()
-    } else {
-        path.slice(0, path.len() - 1)
-    }
+    format!("{}-{}", ident, to_hex(hasher.hash(&url)))
 }
 
 // Some hacks and heuristics for making equivalent URLs hash the same
-pub fn canonicalize_url(url: &str) -> String {
-    let url = strip_trailing_slash(url);
+pub fn canonicalize_url(url: &Url) -> Url {
+    let mut url = url.clone();
+
+    // Strip a trailing slash
+    match url.scheme_data {
+        url::RelativeSchemeData(ref mut rel) => {
+            if rel.path.last().map(|s| s.is_empty()).unwrap_or(false) {
+                rel.path.pop();
+            }
+        }
+        _ => {}
+    }
 
     // HACKHACK: For github URL's specifically just lowercase
-    // everything.  GitHub traits both the same, but they hash
+    // everything.  GitHub treats both the same, but they hash
     // differently, and we're gonna be hashing them. This wants a more
     // general solution, and also we're almost certainly not using the
     // same case conversion rules that GitHub does. (#84)
-
-    let lower_url = url.chars().map(|c|c.to_lowercase()).collect::<String>();
-    let url = if lower_url.as_slice().contains("github.com") {
-        if lower_url.as_slice().starts_with("https") {
-            lower_url
-        } else {
-            let pos = lower_url.as_slice().find_str("://").unwrap_or(0);
-            "https".to_string() + lower_url.as_slice().slice_from(pos)
+    if url.domain() == Some("github.com") {
+        url.scheme = "https".to_string();
+        match url.scheme_data {
+            url::RelativeSchemeData(ref mut rel) => {
+                rel.port = "443".to_string();
+                let path = mem::replace(&mut rel.path, Vec::new());
+                rel.path = path.move_iter().map(|s| {
+                    s.as_slice().chars().map(|c| c.to_lowercase()).collect()
+                }).collect();
+            }
+            _ => {}
         }
-    } else {
-        url.to_string()
-    };
+    }
 
     // Repos generally can be accessed with or w/o '.git'
-    let url = if !url.as_slice().ends_with(".git") {
-        url
-    } else {
-        url.as_slice().slice(0, url.len() - 4).to_string()
-    };
+    match url.scheme_data {
+        url::RelativeSchemeData(ref mut rel) => {
+            let needs_chopping = {
+                let last = rel.path.last().map(|s| s.as_slice()).unwrap_or("");
+                last.ends_with(".git")
+            };
+            if needs_chopping {
+                let last = rel.path.pop().unwrap();
+                let last = last.as_slice();
+                rel.path.push(last.slice_to(last.len() - 4).to_string())
+            }
+        }
+        _ => {}
+    }
 
     return url;
 }
 
 impl<'a, 'b> Show for GitSource<'a, 'b> {
     fn fmt(&self, f: &mut Formatter) -> fmt::Result {
-        try!(write!(f, "git repo at {}", self.remote.get_location()));
+        try!(write!(f, "git repo at {}", self.remote.get_url()));
 
         match self.reference {
             Master => Ok(()),
@@ -163,7 +163,7 @@ impl<'a, 'b> Source for GitSource<'a, 'b> {
 
         let (repo, actual_rev) = if should_update {
             try!(self.config.shell().status("Updating",
-                format!("git repository `{}`", self.remote.get_location())));
+                format!("git repository `{}`", self.remote.get_url())));
 
             log!(5, "updating git source `{}`", self.remote);
             let repo = try!(self.remote.checkout(&self.db_path));
@@ -201,47 +201,46 @@ impl<'a, 'b> Source for GitSource<'a, 'b> {
 #[cfg(test)]
 mod test {
     use url::Url;
-    use core::source::Remote;
     use super::ident;
     use util::ToUrl;
 
     #[test]
     pub fn test_url_to_path_ident_with_path() {
-        let ident = ident(&Remote(url("https://github.com/carlhuda/cargo")));
-        assert_eq!(ident.as_slice(), "cargo-0eed735c8ffd7c88");
+        let ident = ident(&url("https://github.com/carlhuda/cargo"));
+        assert_eq!(ident.as_slice(), "cargo-51d6ede913e3e1d5");
     }
 
     #[test]
     pub fn test_url_to_path_ident_without_path() {
-        let ident = ident(&Remote(url("https://github.com")));
-        assert_eq!(ident.as_slice(), "_empty-fc065c9b6b16fc00");
+        let ident = ident(&url("https://github.com"));
+        assert_eq!(ident.as_slice(), "_empty-eba8a1ec0f6907fb");
     }
 
     #[test]
     fn test_canonicalize_idents_by_stripping_trailing_url_slash() {
-        let ident1 = ident(&Remote(url("https://github.com/PistonDevelopers/piston/")));
-        let ident2 = ident(&Remote(url("https://github.com/PistonDevelopers/piston")));
+        let ident1 = ident(&url("https://github.com/PistonDevelopers/piston/"));
+        let ident2 = ident(&url("https://github.com/PistonDevelopers/piston"));
         assert_eq!(ident1, ident2);
     }
 
     #[test]
     fn test_canonicalize_idents_by_lowercasing_github_urls() {
-        let ident1 = ident(&Remote(url("https://github.com/PistonDevelopers/piston")));
-        let ident2 = ident(&Remote(url("https://github.com/pistondevelopers/piston")));
+        let ident1 = ident(&url("https://github.com/PistonDevelopers/piston"));
+        let ident2 = ident(&url("https://github.com/pistondevelopers/piston"));
         assert_eq!(ident1, ident2);
     }
 
     #[test]
     fn test_canonicalize_idents_by_stripping_dot_git() {
-        let ident1 = ident(&Remote(url("https://github.com/PistonDevelopers/piston")));
-        let ident2 = ident(&Remote(url("https://github.com/PistonDevelopers/piston.git")));
+        let ident1 = ident(&url("https://github.com/PistonDevelopers/piston"));
+        let ident2 = ident(&url("https://github.com/PistonDevelopers/piston.git"));
         assert_eq!(ident1, ident2);
     }
 
     #[test]
     fn test_canonicalize_idents_different_protocls() {
-        let ident1 = ident(&Remote(url("https://github.com/PistonDevelopers/piston")));
-        let ident2 = ident(&Remote(url("git://github.com/PistonDevelopers/piston")));
+        let ident1 = ident(&url("https://github.com/PistonDevelopers/piston"));
+        let ident2 = ident(&url("git://github.com/PistonDevelopers/piston"));
         assert_eq!(ident1, ident2);
     }
 
index 8e4cdadd4497b46147ec3aa5de23b58172c2541d..8ef1c9a3e6f0b549d89001c6365adff8fd8907f0 100644 (file)
@@ -3,8 +3,8 @@ use std::fmt::{Show,Formatter};
 use std::io::{UserDir};
 use std::io::fs::{mkdir_recursive,rmdir_recursive};
 use serialize::{Encodable,Encoder};
+use url::Url;
 
-use core::source::Location;
 use util::{CargoResult, ChainError, ProcessBuilder, process, human};
 
 #[deriving(PartialEq,Clone,Encodable)]
@@ -74,18 +74,18 @@ macro_rules! errln(
 /// GitDatabase.
 #[deriving(PartialEq,Clone,Show)]
 pub struct GitRemote {
-    location: Location,
+    url: Url,
 }
 
 #[deriving(PartialEq,Clone,Encodable)]
 struct EncodableGitRemote {
-    location: String,
+    url: String,
 }
 
 impl<E, S: Encoder<E>> Encodable<S, E> for GitRemote {
     fn encode(&self, s: &mut S) -> Result<(), E> {
         EncodableGitRemote {
-            location: self.location.to_string()
+            url: self.url.to_string()
         }.encode(s)
     }
 }
@@ -142,12 +142,12 @@ impl<E, S: Encoder<E>> Encodable<S, E> for GitCheckout {
 // Implementations
 
 impl GitRemote {
-    pub fn new(location: &Location) -> GitRemote {
-        GitRemote { location: location.clone() }
+    pub fn new(url: &Url) -> GitRemote {
+        GitRemote { url: url.clone() }
     }
 
-    pub fn get_location(&self) -> &Location {
-        &self.location
+    pub fn get_url(&self) -> &Url {
+        &self.url
     }
 
     pub fn rev_for<S: Str>(&self, path: &Path, reference: S)
@@ -171,7 +171,7 @@ impl GitRemote {
 
     fn fetch_into(&self, path: &Path) -> CargoResult<()> {
         Ok(git!(*path, "fetch", "--force", "--quiet", "--tags",
-                &self.location, "refs/heads/*:refs/heads/*"))
+                self.url.to_string(), "refs/heads/*:refs/heads/*"))
     }
 
     fn clone_into(&self, path: &Path) -> CargoResult<()> {
@@ -179,7 +179,7 @@ impl GitRemote {
 
         try!(mkdir_recursive(path, UserDir));
 
-        Ok(git!(dirname, "clone", &self.location, path, "--bare",
+        Ok(git!(dirname, "clone", self.url.to_string(), path, "--bare",
                 "--no-hardlinks", "--quiet"))
     }
 }
index 9227b9eab1eecb0bb77d40c3f1b2763b261c1043..8a6622d62081de4376373b4228359381ad186bbb 100644 (file)
@@ -18,9 +18,9 @@ pub struct PathSource {
 // mut and packages are discovered in update
 impl PathSource {
 
-    pub fn for_path(path: &Path) -> PathSource {
+    pub fn for_path(path: &Path) -> CargoResult<PathSource> {
         log!(5, "PathSource::for_path; path={}", path.display());
-        PathSource::new(path, &SourceId::for_path(path))
+        Ok(PathSource::new(path, &try!(SourceId::for_path(path))))
     }
 
     /// Invoked with an absolute path to a directory that contains a Cargo.toml.
index 93559888d73471dc0d7a28349254718ec7b0c69c..cdafb631e2a73b66b59c980f0322d10917d6233e 100644 (file)
@@ -6,6 +6,7 @@ use std::str;
 
 use docopt;
 use TomlError = toml::Error;
+use url;
 
 pub trait CargoError: Send {
     fn description(&self) -> String;
@@ -287,6 +288,12 @@ impl CargoError for docopt::Error {
 
 from_error!(docopt::Error)
 
+impl CargoError for url::ParseError {
+    fn description(&self) -> String { self.to_string() }
+}
+
+from_error!(url::ParseError)
+
 impl CliError {
     pub fn new<S: Str>(error: S, code: uint) -> CliError {
         let error = human(error.as_slice().to_string());
index b4baf9e5d0581c9c1a88d2d665b32a16e21ebe44..d130daa72937f83d42909ecc9c67a45130111bc8 100644 (file)
@@ -20,7 +20,7 @@ impl<'a> ToUrl for &'a Url {
 impl<'a> ToUrl for &'a str {
     fn to_url(self) -> Result<Url, String> {
         UrlParser::new().scheme_type_mapper(mapper).parse(self).map_err(|s| {
-            s.to_string()
+            format!("invalid url `{}`: {}", self, s)
         })
     }
 }
index fa5bf0b0b3cd6032cd6ad19b7445acdfe829da70..a7a959f993a65845029179cdebfb0fcb05a4d752 100644 (file)
@@ -9,8 +9,7 @@ use core::{SourceId, GitKind};
 use core::manifest::{LibKind, Lib, Dylib, Profile};
 use core::{Summary, Manifest, Target, Dependency, PackageId};
 use core::package_id::Metadata;
-use core::source::Location;
-use util::{CargoResult, Require, human};
+use util::{CargoResult, Require, human, ToUrl};
 
 /// Representation of the projects file layout.
 ///
@@ -425,7 +424,9 @@ fn process_dependencies<'a>(cx: &mut Context<'a>, dev: bool,
                 let new_source_id = match details.git {
                     Some(ref git) => {
                         let kind = GitKind(reference.clone());
-                        let loc = try!(Location::parse(git.as_slice()));
+                        let loc = try!(git.as_slice().to_url().map_err(|e| {
+                            human(e)
+                        }));
                         let source_id = SourceId::new(kind, loc);
                         // TODO: Don't do this for path
                         cx.source_ids.push(source_id.clone());
index 080e4349ed36073e0a4b932494d2edfed08bdaed..534a1406a9203242e660a30990d13c128556e0d6 100644 (file)
@@ -6,6 +6,7 @@ use std::path::{Path,BytesContainer};
 use std::str;
 use std::vec::Vec;
 use std::fmt::Show;
+use url::Url;
 use ham = hamcrest;
 use cargo::util::{process,ProcessBuilder};
 use cargo::util::ProcessError;
@@ -95,6 +96,8 @@ impl ProjectBuilder {
         self.root.clone()
     }
 
+    pub fn url(&self) -> Url { path2url(self.root()) }
+
     pub fn bin(&self, b: &str) -> Path {
         self.build_dir().join(format!("{}{}", b, os::consts::EXE_SUFFIX))
     }
@@ -495,6 +498,10 @@ pub fn basic_lib_manifest(name: &str) -> String {
     "#, name, name)
 }
 
+pub fn path2url(p: Path) -> Url {
+    Url::from_file_path(&p).unwrap()
+}
+
 pub static RUNNING:   &'static str = "     Running";
 pub static COMPILING: &'static str = "   Compiling";
 pub static FRESH:     &'static str = "       Fresh";
index 78c2ab94da927145699d36cbc6576ba156dba6b5..b9a3adfb9dccc0ff3c749f2fbbb6f2bdbcc20e08 100644 (file)
@@ -3,7 +3,7 @@ use std::os;
 use std::path;
 
 use support::{ResultTest, project, execs, main_file, basic_bin_manifest};
-use support::{COMPILING, RUNNING, cargo_dir, ProjectBuilder};
+use support::{COMPILING, RUNNING, cargo_dir, ProjectBuilder, path2url};
 use hamcrest::{assert_that, existing_file};
 use cargo;
 use cargo::util::{process, realpath};
@@ -197,10 +197,10 @@ test!(cargo_compile_with_warnings_in_a_dep_package {
 
     assert_that(p.cargo_process("cargo-build"),
         execs()
-        .with_stdout(format!("{} bar v0.5.0 (file:{})\n\
-                              {} foo v0.5.0 (file:{})\n",
-                             COMPILING, bar.display(),
-                             COMPILING, main.display()))
+        .with_stdout(format!("{} bar v0.5.0 ({})\n\
+                              {} foo v0.5.0 ({})\n",
+                             COMPILING, path2url(bar),
+                             COMPILING, path2url(main)))
         .with_stderr(""));
 
     assert_that(&p.bin("foo"), existing_file());
@@ -522,9 +522,9 @@ test!(cargo_compile_with_dep_name_mismatch {
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(101).with_stderr(format!(
 r#"No package named `notquitebar` found (required by `foo`).
-Location searched: file:{proj_dir}
+Location searched: {proj_dir}
 Version required: *
-"#, proj_dir = p.root().display())));
+"#, proj_dir = p.url())));
 })
 
 // test!(compiling_project_with_invalid_manifest)
@@ -565,8 +565,8 @@ test!(custom_build {
         "#);
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(0)
-                       .with_stdout(format!("   Compiling foo v0.5.0 (file:{})\n",
-                                            p.root().display()))
+                       .with_stdout(format!("   Compiling foo v0.5.0 ({})\n",
+                                            p.url()))
                        .with_stderr(""));
 })
 
@@ -629,8 +629,8 @@ test!(custom_multiple_build {
         "#);
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(0)
-                       .with_stdout(format!("   Compiling foo v0.5.0 (file:{})\n",
-                                            p.root().display()))
+                       .with_stdout(format!("   Compiling foo v0.5.0 ({})\n",
+                                            p.url()))
                        .with_stderr(""));
 })
 
@@ -1111,9 +1111,10 @@ test!(verbose_build {
         --dep-info [..] \
         -L {dir}{sep}target \
         -L {dir}{sep}target{sep}deps`
-{compiling} test v0.0.0 (file:{dir})\n",
+{compiling} test v0.0.0 ({url})\n",
 running = RUNNING, compiling = COMPILING, sep = path::SEP,
-dir = p.root().display()
+dir = p.root().display(),
+url = p.url(),
 )));
 })
 
@@ -1139,9 +1140,10 @@ test!(verbose_release_build {
         --dep-info [..] \
         -L {dir}{sep}target{sep}release \
         -L {dir}{sep}target{sep}release{sep}deps`
-{compiling} test v0.0.0 (file:{dir})\n",
+{compiling} test v0.0.0 ({url})\n",
 running = RUNNING, compiling = COMPILING, sep = path::SEP,
-dir = p.root().display()
+dir = p.root().display(),
+url = p.url(),
 )));
 })
 
@@ -1195,11 +1197,12 @@ test!(verbose_release_build_deps {
         --extern foo={dir}{sep}target{sep}release{sep}deps/\
                      {prefix}foo-[..]{suffix} \
         --extern foo={dir}{sep}target{sep}release{sep}deps/libfoo-[..].rlib`
-{compiling} foo v0.0.0 (file:{dir})
-{compiling} test v0.0.0 (file:{dir})\n",
+{compiling} foo v0.0.0 ({url})
+{compiling} test v0.0.0 ({url})\n",
                     running = RUNNING,
                     compiling = COMPILING,
                     dir = p.root().display(),
+                    url = p.url(),
                     sep = path::SEP,
                     prefix = os::consts::DLL_PREFIX,
                     suffix = os::consts::DLL_SUFFIX).as_slice()));
@@ -1391,10 +1394,10 @@ test!(lib_with_standard_name {
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{compiling} syntax v0.0.1 (file:{dir})
+{compiling} syntax v0.0.1 ({dir})
 ",
                        compiling = COMPILING,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
 })
 
 test!(simple_staticlib {
index 26c419bbe3a2fcdea6798a97bd012ece8bbdaab6..88c9ca6c25df96d078fb2a3bab5f6cb24016794a 100644 (file)
@@ -1,7 +1,7 @@
 use std::io::File;
 
 use support::{ProjectBuilder, ResultTest, project, execs, main_file, paths};
-use support::{cargo_dir};
+use support::{cargo_dir, path2url};
 use support::{COMPILING, FRESH, UPDATING};
 use support::paths::PathExt;
 use hamcrest::{assert_that,existing_file};
@@ -72,12 +72,12 @@ test!(cargo_compile_simple_git_dep {
 
             [dependencies.dep1]
 
-            git = 'file:{}'
+            git = '{}'
 
             [[bin]]
 
             name = "foo"
-        "#, git_project.root().display()))
+        "#, git_project.url()))
         .file("src/foo.rs", main_file(r#""{}", dep1::hello()"#, ["dep1"]));
 
     let root = project.root();
@@ -85,12 +85,12 @@ test!(cargo_compile_simple_git_dep {
 
     assert_that(project.cargo_process("cargo-build"),
         execs()
-        .with_stdout(format!("{} git repository `file:{}`\n\
-                              {} dep1 v0.5.0 (file:{}#[..])\n\
-                              {} foo v0.5.0 (file:{})\n",
-                             UPDATING, git_root.display(),
-                             COMPILING, git_root.display(),
-                             COMPILING, root.display()))
+        .with_stdout(format!("{} git repository `{}`\n\
+                              {} dep1 v0.5.0 ({}#[..])\n\
+                              {} foo v0.5.0 ({})\n",
+                             UPDATING, path2url(git_root.clone()),
+                             COMPILING, path2url(git_root),
+                             COMPILING, path2url(root)))
         .with_stderr(""));
 
     assert_that(&project.bin("foo"), existing_file());
@@ -135,13 +135,13 @@ test!(cargo_compile_git_dep_branch {
 
             [dependencies.dep1]
 
-            git = 'file:{}'
+            git = '{}'
             branch = "branchy"
 
             [[bin]]
 
             name = "foo"
-        "#, git_project.root().display()))
+        "#, git_project.url()))
         .file("src/foo.rs", main_file(r#""{}", dep1::hello()"#, ["dep1"]));
 
     let root = project.root();
@@ -149,12 +149,12 @@ test!(cargo_compile_git_dep_branch {
 
     assert_that(project.cargo_process("cargo-build"),
         execs()
-        .with_stdout(format!("{} git repository `file:{}`\n\
-                              {} dep1 v0.5.0 (file:{}?ref=branchy#[..])\n\
-                              {} foo v0.5.0 (file:{})\n",
-                             UPDATING, git_root.display(),
-                             COMPILING, git_root.display(),
-                             COMPILING, root.display()))
+        .with_stdout(format!("{} git repository `{}`\n\
+                              {} dep1 v0.5.0 ({}?ref=branchy#[..])\n\
+                              {} foo v0.5.0 ({})\n",
+                             UPDATING, path2url(git_root.clone()),
+                             COMPILING, path2url(git_root),
+                             COMPILING, path2url(root)))
         .with_stderr(""));
 
     assert_that(&project.bin("foo"), existing_file());
@@ -200,13 +200,13 @@ test!(cargo_compile_git_dep_tag {
 
             [dependencies.dep1]
 
-            git = 'file:{}'
+            git = '{}'
             tag = "v0.1.0"
 
             [[bin]]
 
             name = "foo"
-        "#, git_project.root().display()))
+        "#, git_project.url()))
         .file("src/foo.rs", main_file(r#""{}", dep1::hello()"#, ["dep1"]));
 
     let root = project.root();
@@ -214,12 +214,12 @@ test!(cargo_compile_git_dep_tag {
 
     assert_that(project.cargo_process("cargo-build"),
         execs()
-        .with_stdout(format!("{} git repository `file:{}`\n\
-                              {} dep1 v0.5.0 (file:{}?ref=v0.1.0#[..])\n\
-                              {} foo v0.5.0 (file:{})\n",
-                             UPDATING, git_root.display(),
-                             COMPILING, git_root.display(),
-                             COMPILING, root.display()))
+        .with_stdout(format!("{} git repository `{}`\n\
+                              {} dep1 v0.5.0 ({}?ref=v0.1.0#[..])\n\
+                              {} foo v0.5.0 ({})\n",
+                             UPDATING, path2url(git_root.clone()),
+                             COMPILING, path2url(git_root),
+                             COMPILING, path2url(root)))
         .with_stderr(""));
 
     assert_that(&project.bin("foo"), existing_file());
@@ -284,12 +284,12 @@ test!(cargo_compile_with_nested_paths {
             [dependencies.dep1]
 
             version = "0.5.0"
-            git = 'file:{}'
+            git = '{}'
 
             [[bin]]
 
             name = "parent"
-        "#, git_project.root().display()))
+        "#, git_project.url()))
         .file("src/parent.rs",
               main_file(r#""{}", dep1::hello()"#, ["dep1"]).as_slice());
 
@@ -352,17 +352,17 @@ test!(cargo_compile_with_meta_package {
             [dependencies.dep1]
 
             version = "0.5.0"
-            git = 'file:{}'
+            git = '{}'
 
             [dependencies.dep2]
 
             version = "0.5.0"
-            git = 'file:{}'
+            git = '{}'
 
             [[bin]]
 
             name = "parent"
-        "#, git_project.root().display(), git_project.root().display()))
+        "#, git_project.url(), git_project.url()))
         .file("src/parent.rs",
               main_file(r#""{} {}", dep1::hello(), dep2::hello()"#, ["dep1", "dep2"]).as_slice());
 
@@ -402,7 +402,7 @@ test!(cargo_compile_with_short_ssh_git {
         execs()
         .with_stdout("")
         .with_stderr(format!("Cargo.toml is not a valid manifest\n\n\
-                              invalid url `{}`: `Relative URL without a base\n", url)));
+                              invalid url `{}`: Relative URL without a base\n", url)));
 })
 
 test!(two_revs_same_deps {
@@ -439,12 +439,12 @@ test!(two_revs_same_deps {
             authors = []
 
             [dependencies.bar]
-            git = 'file:{}'
+            git = '{}'
             rev = "{}"
 
             [dependencies.baz]
             path = "../baz"
-        "#, bar.root().display(), rev1.as_slice().trim()).as_slice())
+        "#, bar.url(), rev1.as_slice().trim()).as_slice())
         .file("src/main.rs", r#"
             extern crate bar;
             extern crate baz;
@@ -463,9 +463,9 @@ test!(two_revs_same_deps {
             authors = []
 
             [dependencies.bar]
-            git = 'file:{}'
+            git = '{}'
             rev = "{}"
-        "#, bar.root().display(), rev2.as_slice().trim()).as_slice())
+        "#, bar.url(), rev2.as_slice().trim()).as_slice())
         .file("src/lib.rs", r#"
             extern crate bar;
             pub fn baz() -> int { bar::bar() }
@@ -509,30 +509,30 @@ test!(recompilation {
             [dependencies.bar]
 
             version = "0.5.0"
-            git = 'file:{}'
+            git = '{}'
 
             [[bin]]
 
             name = "foo"
-        "#, git_project.root().display()))
+        "#, git_project.url()))
         .file("src/foo.rs",
               main_file(r#""{}", bar::bar()"#, ["bar"]).as_slice());
 
     // First time around we should compile both foo and bar
     assert_that(p.cargo_process("cargo-build"),
-                execs().with_stdout(format!("{} git repository `file:{}`\n\
-                                             {} bar v0.5.0 (file:{}#[..])\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            UPDATING, git_project.root().display(),
-                                            COMPILING, git_project.root().display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} git repository `{}`\n\
+                                             {} bar v0.5.0 ({}#[..])\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            UPDATING, git_project.url(),
+                                            COMPILING, git_project.url(),
+                                            COMPILING, p.url())));
 
     // Don't recompile the second time
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            FRESH, git_project.root().display(),
-                                            FRESH, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            FRESH, git_project.url(),
+                                            FRESH, p.url())));
 
     // Modify a file manually, shouldn't trigger a recompile
     File::create(&git_project.root().join("src/bar.rs")).write_str(r#"
@@ -540,21 +540,21 @@ test!(recompilation {
     "#).assert();
 
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            FRESH, git_project.root().display(),
-                                            FRESH, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            FRESH, git_project.url(),
+                                            FRESH, p.url())));
 
     assert_that(p.process(cargo_dir().join("cargo-update")),
-                execs().with_stdout(format!("{} git repository `file:{}`",
+                execs().with_stdout(format!("{} git repository `{}`",
                                             UPDATING,
-                                            git_project.root().display())));
+                                            git_project.url())));
 
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            FRESH, git_project.root().display(),
-                                            FRESH, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            FRESH, git_project.url(),
+                                            FRESH, p.url())));
 
     // Commit the changes and make sure we don't trigger a recompile because the
     // lockfile says not to change
@@ -564,23 +564,23 @@ test!(recompilation {
 
     println!("compile after commit");
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            FRESH, git_project.root().display(),
-                                            FRESH, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            FRESH, git_project.url(),
+                                            FRESH, p.url())));
     p.root().move_into_the_past().assert();
 
     // Update the dependency and carry on!
     assert_that(p.process(cargo_dir().join("cargo-update")),
-                execs().with_stdout(format!("{} git repository `file:{}`",
+                execs().with_stdout(format!("{} git repository `{}`",
                                             UPDATING,
-                                            git_project.root().display())));
+                                            git_project.url())));
     println!("going for the last compile");
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{}#[..])\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            COMPILING, git_project.root().display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({}#[..])\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            COMPILING, git_project.url(),
+                                            COMPILING, p.url())));
 })
 
 test!(update_with_shared_deps {
@@ -626,8 +626,8 @@ test!(update_with_shared_deps {
 
             [dependencies.bar]
             version = "0.5.0"
-            git = 'file:{}'
-        "#, git_project.root().display()))
+            git = '{}'
+        "#, git_project.url()))
         .file("dep1/src/lib.rs", "")
         .file("dep2/Cargo.toml", format!(r#"
             [package]
@@ -637,20 +637,20 @@ test!(update_with_shared_deps {
 
             [dependencies.bar]
             version = "0.5.0"
-            git = 'file:{}'
-        "#, git_project.root().display()))
+            git = '{}'
+        "#, git_project.url()))
         .file("dep2/src/lib.rs", "");
 
     // First time around we should compile both foo and bar
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_stdout(format!("\
-{updating} git repository `file:{git}`
-{compiling} bar v0.5.0 (file:{git}#[..])
-{compiling} [..] v0.5.0 (file:{dir})
-{compiling} [..] v0.5.0 (file:{dir})
-{compiling} foo v0.5.0 (file:{dir})\n",
-                    updating = UPDATING, git = git_project.root().display(),
-                    compiling = COMPILING, dir = p.root().display())));
+{updating} git repository `{git}`
+{compiling} bar v0.5.0 ({git}#[..])
+{compiling} [..] v0.5.0 ({dir})
+{compiling} [..] v0.5.0 ({dir})
+{compiling} foo v0.5.0 ({dir})\n",
+                    updating = UPDATING, git = git_project.url(),
+                    compiling = COMPILING, dir = p.url())));
 
     // Modify a file manually, and commit it
     File::create(&git_project.root().join("src/bar.rs")).write_str(r#"
@@ -660,19 +660,19 @@ test!(update_with_shared_deps {
     git_project.process("git").args(["commit", "-m", "test"]).exec_with_output()
                .assert();
     assert_that(p.process(cargo_dir().join("cargo-update")).arg("dep1"),
-                execs().with_stdout(format!("{} git repository `file:{}`",
+                execs().with_stdout(format!("{} git repository `{}`",
                                             UPDATING,
-                                            git_project.root().display())));
+                                            git_project.url())));
 
     // Make sure we still only compile one version of the git repo
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_stdout(format!("\
-{compiling} bar v0.5.0 (file:{git}#[..])
-{compiling} [..] v0.5.0 (file:{dir})
-{compiling} [..] v0.5.0 (file:{dir})
-{compiling} foo v0.5.0 (file:{dir})\n",
-                    git = git_project.root().display(),
-                    compiling = COMPILING, dir = p.root().display())));
+{compiling} bar v0.5.0 ({git}#[..])
+{compiling} [..] v0.5.0 ({dir})
+{compiling} [..] v0.5.0 ({dir})
+{compiling} foo v0.5.0 ({dir})\n",
+                    git = git_project.url(),
+                    compiling = COMPILING, dir = p.url())));
 })
 
 test!(dep_with_submodule {
@@ -707,23 +707,23 @@ test!(dep_with_submodule {
 
             [dependencies.dep1]
 
-            git = 'file:{}'
-        "#, git_project.root().display()))
+            git = '{}'
+        "#, git_project.url()))
         .file("src/lib.rs", "
             extern crate dep1;
             pub fn foo() { dep1::dep() }
         ");
 
-    let root = project.root();
-    let git_root = git_project.root();
+    let root = project.url();
+    let git_root = git_project.url();
 
     assert_that(project.cargo_process("cargo-build"),
         execs()
-        .with_stdout(format!("{} git repository `file:{}`\n\
-                              {} dep1 v0.5.0 (file:{}#[..])\n\
-                              {} foo v0.5.0 (file:{})\n",
-                             UPDATING, git_root.display(),
-                             COMPILING, git_root.display(),
-                             COMPILING, root.display()))
+        .with_stdout(format!("{} git repository `{}`\n\
+                              {} dep1 v0.5.0 ({}#[..])\n\
+                              {} foo v0.5.0 ({})\n",
+                             UPDATING, git_root,
+                             COMPILING, git_root,
+                             COMPILING, root))
         .with_stderr(""));
 })
index be7ee8c8384442a0eec27fd6bb562b7339ce3532..39cf9cdbba6e554b136c2544636cb8e9991e4c5d 100644 (file)
@@ -1,6 +1,6 @@
 use std::io::File;
 
-use support::{ResultTest, project, execs, main_file, cargo_dir};
+use support::{ResultTest, project, execs, main_file, cargo_dir, path2url};
 use support::{COMPILING, FRESH};
 use support::paths::PathExt;
 use hamcrest::{assert_that, existing_file};
@@ -71,12 +71,12 @@ test!(cargo_compile_with_nested_deps_shorthand {
         "#);
 
     assert_that(p.cargo_process("cargo-build"),
-        execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
-                                     {} bar v0.5.0 (file:{})\n\
-                                     {} foo v0.5.0 (file:{})\n",
-                                    COMPILING, p.root().display(),
-                                    COMPILING, p.root().display(),
-                                    COMPILING, p.root().display())));
+        execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+                                     {} bar v0.5.0 ({})\n\
+                                     {} foo v0.5.0 ({})\n",
+                                    COMPILING, p.url(),
+                                    COMPILING, p.url(),
+                                    COMPILING, p.url())));
 
     assert_that(&p.bin("foo"), existing_file());
 
@@ -120,10 +120,10 @@ test!(cargo_compile_with_root_dev_deps {
 
     p2.build();
     assert_that(p.cargo_process("cargo-build"),
-        execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
-                                     {} foo v0.5.0 (file:{})\n",
-                                    COMPILING, p.root().display(),
-                                    COMPILING, p.root().display())));
+        execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+                                     {} foo v0.5.0 ({})\n",
+                                    COMPILING, p.url(),
+                                    COMPILING, p.url())));
 
     assert_that(&p.bin("foo"), existing_file());
 
@@ -174,10 +174,10 @@ test!(cargo_compile_with_transitive_dev_deps {
         "#);
 
     assert_that(p.cargo_process("cargo-build"),
-        execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
-                                     {} foo v0.5.0 (file:{})\n",
-                                    COMPILING, p.root().display(),
-                                    COMPILING, p.root().display())));
+        execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+                                     {} foo v0.5.0 ({})\n",
+                                    COMPILING, p.url(),
+                                    COMPILING, p.url())));
 
     assert_that(&p.bin("foo"), existing_file());
 
@@ -219,26 +219,27 @@ test!(no_rebuild_dependency {
         .file("bar/src/bar.rs", r#"
             pub fn bar() {}
         "#);
+    let bar = path2url(bar);
     // First time around we should compile both foo and bar
     assert_that(p.cargo_process("cargo-build"),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            COMPILING, bar.display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            COMPILING, bar,
+                                            COMPILING, p.url())));
     // This time we shouldn't compile bar
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            FRESH, bar.display(),
-                                            FRESH, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            FRESH, bar,
+                                            FRESH, p.url())));
     p.root().move_into_the_past().assert();
 
     p.build(); // rebuild the files (rewriting them in the process)
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            COMPILING, bar.display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            COMPILING, bar,
+                                            COMPILING, p.url())));
 })
 
 test!(deep_dependencies_trigger_rebuild {
@@ -294,20 +295,22 @@ test!(deep_dependencies_trigger_rebuild {
         .file("baz/src/baz.rs", r#"
             pub fn baz() {}
         "#);
+    let baz = path2url(baz);
+    let bar = path2url(bar);
     assert_that(p.cargo_process("cargo-build"),
-                execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
-                                             {} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            COMPILING, baz.display(),
-                                            COMPILING, bar.display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+                                             {} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            COMPILING, baz,
+                                            COMPILING, bar,
+                                            COMPILING, p.url())));
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
-                                             {} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            FRESH, baz.display(),
-                                            FRESH, bar.display(),
-                                            FRESH, p.root().display())));
+                execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+                                             {} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            FRESH, baz,
+                                            FRESH, bar,
+                                            FRESH, p.url())));
 
     // Make sure an update to baz triggers a rebuild of bar
     //
@@ -318,12 +321,12 @@ test!(deep_dependencies_trigger_rebuild {
         pub fn baz() { println!("hello!"); }
     "#).assert();
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
-                                             {} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            COMPILING, baz.display(),
-                                            COMPILING, bar.display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+                                             {} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            COMPILING, baz,
+                                            COMPILING, bar,
+                                            COMPILING, p.url())));
 
     // Make sure an update to bar doesn't trigger baz
     p.root().move_into_the_past().assert();
@@ -332,12 +335,12 @@ test!(deep_dependencies_trigger_rebuild {
         pub fn bar() { println!("hello!"); baz::baz(); }
     "#).assert();
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
-                                             {} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            FRESH, baz.display(),
-                                            COMPILING, bar.display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+                                             {} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            FRESH, baz,
+                                            COMPILING, bar,
+                                            COMPILING, p.url())));
 })
 
 test!(no_rebuild_two_deps {
@@ -393,21 +396,23 @@ test!(no_rebuild_two_deps {
         .file("baz/src/baz.rs", r#"
             pub fn baz() {}
         "#);
+    let baz = path2url(baz);
+    let bar = path2url(bar);
     assert_that(p.cargo_process("cargo-build"),
-                execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
-                                             {} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            COMPILING, baz.display(),
-                                            COMPILING, bar.display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+                                             {} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            COMPILING, baz,
+                                            COMPILING, bar,
+                                            COMPILING, p.url())));
     assert_that(&p.bin("foo"), existing_file());
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} baz v0.5.0 (file:{})\n\
-                                             {} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            FRESH, baz.display(),
-                                            FRESH, bar.display(),
-                                            FRESH, p.root().display())));
+                execs().with_stdout(format!("{} baz v0.5.0 ({})\n\
+                                             {} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            FRESH, baz,
+                                            FRESH, bar,
+                                            FRESH, p.url())));
     assert_that(&p.bin("foo"), existing_file());
 })
 
@@ -443,13 +448,13 @@ test!(nested_deps_recompile {
             name = "bar"
         "#)
         .file("src/bar/src/bar.rs", "pub fn gimme() {}");
-    let bar = p.root();
+    let bar = p.url();
 
     assert_that(p.cargo_process("cargo-build"),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            COMPILING, bar.display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            COMPILING, bar,
+                                            COMPILING, p.url())));
     p.root().move_into_the_past().assert();
 
     File::create(&p.root().join("src/foo.rs")).write_str(r#"
@@ -458,10 +463,10 @@ test!(nested_deps_recompile {
 
     // This shouldn't recompile `bar`
     assert_that(p.process(cargo_dir().join("cargo-build")),
-                execs().with_stdout(format!("{} bar v0.5.0 (file:{})\n\
-                                             {} foo v0.5.0 (file:{})\n",
-                                            FRESH, bar.display(),
-                                            COMPILING, p.root().display())));
+                execs().with_stdout(format!("{} bar v0.5.0 ({})\n\
+                                             {} foo v0.5.0 ({})\n",
+                                            FRESH, bar,
+                                            COMPILING, p.url())));
 })
 
 test!(error_message_for_missing_manifest {
index eeb14b445512098dbe205f3948506ca737405cc0..08c4d6837c541aef7d7d5859f820111f9e1276a1 100644 (file)
@@ -263,11 +263,12 @@ test!(linker_and_ar {
     -C ar=my-ar-tool -C linker=my-linker-tool \
     -L {dir}{sep}target{sep}{target} \
     -L {dir}{sep}target{sep}{target}{sep}deps`
-{compiling} foo v0.5.0 (file:{dir})
+{compiling} foo v0.5.0 ({url})
 ",
                             running = RUNNING,
                             compiling = COMPILING,
                             dir = p.root().display(),
+                            url = p.url(),
                             target = target,
                             sep = path::SEP,
                             ).as_slice()));
index 5442887e9834f4f48c2530f59417e25afe67858f..065511e94acb52a702d17a631451e811cda8184e 100644 (file)
@@ -1,4 +1,4 @@
-use support::{project, execs, cargo_dir};
+use support::{project, execs, cargo_dir, path2url};
 use support::{COMPILING, FRESH};
 use hamcrest::{assert_that, existing_file, existing_dir, is_not};
 
@@ -19,10 +19,10 @@ test!(simple {
 
     assert_that(p.cargo_process("cargo-doc"),
                 execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
 ",
         compiling = COMPILING,
-        dir = p.root().display()).as_slice()));
+        dir = path2url(p.root())).as_slice()));
     assert_that(&p.root().join("target/doc"), existing_dir());
     assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
 })
@@ -61,17 +61,17 @@ test!(doc_twice {
 
     assert_that(p.cargo_process("cargo-doc"),
                 execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
 ",
         compiling = COMPILING,
-        dir = p.root().display()).as_slice()));
+        dir = path2url(p.root())).as_slice()));
 
     assert_that(p.process(cargo_dir().join("cargo-doc")),
                 execs().with_status(0).with_stdout(format!("\
-{fresh} foo v0.0.1 (file:{dir})
+{fresh} foo v0.0.1 ({dir})
 ",
         fresh = FRESH,
-        dir = p.root().display()).as_slice()));
+        dir = path2url(p.root())).as_slice()));
 })
 
 test!(doc_deps {
@@ -101,11 +101,11 @@ test!(doc_deps {
 
     assert_that(p.cargo_process("cargo-doc"),
                 execs().with_status(0).with_stdout(format!("\
-{compiling} bar v0.0.1 (file:{dir})
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} bar v0.0.1 ({dir})
+{compiling} foo v0.0.1 ({dir})
 ",
         compiling = COMPILING,
-        dir = p.root().display()).as_slice()));
+        dir = path2url(p.root())).as_slice()));
 
     assert_that(&p.root().join("target/doc"), existing_dir());
     assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
@@ -114,11 +114,11 @@ test!(doc_deps {
     assert_that(p.process(cargo_dir().join("cargo-doc"))
                  .env("RUST_LOG", Some("cargo::ops::cargo_rustc::fingerprint")),
                 execs().with_status(0).with_stdout(format!("\
-{fresh} bar v0.0.1 (file:{dir})
-{fresh} foo v0.0.1 (file:{dir})
+{fresh} bar v0.0.1 ({dir})
+{fresh} foo v0.0.1 ({dir})
 ",
         fresh = FRESH,
-        dir = p.root().display()).as_slice()));
+        dir = path2url(p.root())).as_slice()));
 
     assert_that(&p.root().join("target/doc"), existing_dir());
     assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
@@ -152,11 +152,11 @@ test!(doc_no_deps {
 
     assert_that(p.cargo_process("cargo-doc").arg("--no-deps"),
                 execs().with_status(0).with_stdout(format!("\
-{compiling} bar v0.0.1 (file:{dir})
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} bar v0.0.1 ({dir})
+{compiling} foo v0.0.1 ({dir})
 ",
         compiling = COMPILING,
-        dir = p.root().display()).as_slice()));
+        dir = path2url(p.root())).as_slice()));
 
     assert_that(&p.root().join("target/doc"), existing_dir());
     assert_that(&p.root().join("target/doc/foo/index.html"), existing_file());
index 3b4a84e8a9dd8344f0b7ff8ddceae6561f9a4ce8..6f9ac3c140a83a25a4a41014d77669c9b2c46663 100644 (file)
@@ -1,6 +1,6 @@
 use std::io::{fs, File};
 
-use support::{project, execs};
+use support::{project, execs, path2url};
 use support::{COMPILING, cargo_dir, ResultTest, FRESH};
 use support::paths::PathExt;
 use hamcrest::{assert_that, existing_file};
@@ -22,20 +22,20 @@ test!(modifying_and_moving {
 
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-", compiling = COMPILING, dir = p.root().display())));
+{compiling} foo v0.0.1 ({dir})
+", compiling = COMPILING, dir = path2url(p.root()))));
 
     assert_that(p.process(cargo_dir().join("cargo-build")),
                 execs().with_status(0).with_stdout(format!("\
-{fresh} foo v0.0.1 (file:{dir})
-", fresh = FRESH, dir = p.root().display())));
+{fresh} foo v0.0.1 ({dir})
+", fresh = FRESH, dir = path2url(p.root()))));
     p.root().move_into_the_past().assert();
 
     File::create(&p.root().join("src/a.rs")).write_str("fn main() {}").assert();
     assert_that(p.process(cargo_dir().join("cargo-build")),
                 execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-", compiling = COMPILING, dir = p.root().display())));
+{compiling} foo v0.0.1 ({dir})
+", compiling = COMPILING, dir = path2url(p.root()))));
 
     fs::rename(&p.root().join("src/a.rs"), &p.root().join("src/b.rs")).assert();
     assert_that(p.process(cargo_dir().join("cargo-build")),
@@ -61,8 +61,8 @@ test!(modify_only_some_files {
 
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-", compiling = COMPILING, dir = p.root().display())));
+{compiling} foo v0.0.1 ({dir})
+", compiling = COMPILING, dir = path2url(p.root()))));
     assert_that(p.process(cargo_dir().join("cargo-test")),
                 execs().with_status(0));
 
@@ -81,7 +81,7 @@ test!(modify_only_some_files {
     assert_that(p.process(cargo_dir().join("cargo-build"))
                  .env("RUST_LOG", Some("cargo::ops::cargo_rustc::fingerprint")),
                 execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-", compiling = COMPILING, dir = p.root().display())));
+{compiling} foo v0.0.1 ({dir})
+", compiling = COMPILING, dir = path2url(p.root()))));
     assert_that(&p.bin("foo"), existing_file());
 })
index b4ec89c51214d03c774741ee98fd4e9dbca19b12..70ccd7714df67c15182fb26cf588ed7a79fdeb94 100644 (file)
@@ -1,6 +1,6 @@
 use std::path;
 
-use support::{project, execs};
+use support::{project, execs, path2url};
 use support::{COMPILING, RUNNING};
 use hamcrest::{assert_that, existing_file};
 
@@ -21,13 +21,13 @@ test!(simple {
 
     assert_that(p.cargo_process("cargo-run"),
                 execs().with_status(0).with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
 {running} `target{sep}foo`
 hello
 ",
         compiling = COMPILING,
         running = RUNNING,
-        dir = p.root().display(),
+        dir = path2url(p.root()),
         sep = path::SEP).as_slice()));
     assert_that(&p.bin("foo"), existing_file());
 })
index 15cb1e8e4dafbb3b322c732c4a63fab42f1ae717..bf1d1cd11b171bf847a2bdd93af2de27c6d2158e 100644 (file)
@@ -35,14 +35,14 @@ test!(cargo_test_simple {
 
     assert_that(p.process(cargo_dir().join("cargo-test")),
         execs().with_stdout(format!("\
-{} foo v0.5.0 (file:{})
+{} foo v0.5.0 ({})
 {} target[..]test[..]foo
 
 running 1 test
 test test_hello ... ok
 
 test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n",
-        COMPILING, p.root().display(),
+        COMPILING, p.url(),
         RUNNING)));
 })
 
@@ -101,7 +101,7 @@ test!(cargo_test_failing_test {
 
     assert_that(p.process(cargo_dir().join("cargo-test")),
         execs().with_stdout(format!("\
-{} foo v0.5.0 (file:{})
+{} foo v0.5.0 ({})
 {} target[..]test[..]foo
 
 running 1 test
@@ -122,7 +122,7 @@ failures:
 test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
 
 ",
-        COMPILING, p.root().display(), RUNNING,
+        COMPILING, p.url(), RUNNING,
         sep = path::SEP))
               .with_stderr(format!("\
 task '<main>' failed at 'Some tests failed', [..]
@@ -166,7 +166,7 @@ test!(test_with_lib_dep {
 
     assert_that(p.cargo_process("cargo-test"),
         execs().with_stdout(format!("\
-{} foo v0.0.1 (file:{})
+{} foo v0.0.1 ({})
 {running} target[..]test[..]baz-[..]
 
 running 1 test
@@ -189,7 +189,7 @@ test foo_0 ... ok
 test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
 
 ",
-        COMPILING, p.root().display(), running = RUNNING, doctest = DOCTEST)))
+        COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
 })
 
 test!(test_with_deep_lib_dep {
@@ -228,8 +228,8 @@ test!(test_with_deep_lib_dep {
     assert_that(p.cargo_process("cargo-test"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
-{compiling} bar v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
+{compiling} bar v0.0.1 ({dir})
 {running} target[..]
 
 running 1 test
@@ -245,7 +245,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        compiling = COMPILING, running = RUNNING,
                        doctest = DOCTEST,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
 })
 
 test!(external_test_explicit {
@@ -275,7 +275,7 @@ test!(external_test_explicit {
 
     assert_that(p.cargo_process("cargo-test"),
         execs().with_stdout(format!("\
-{} foo v0.0.1 (file:{})
+{} foo v0.0.1 ({})
 {running} target[..]test[..]foo-[..]
 
 running 1 test
@@ -297,7 +297,7 @@ running 0 tests
 test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
 
 ",
-        COMPILING, p.root().display(), running = RUNNING, doctest = DOCTEST)))
+        COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
 })
 
 test!(external_test_implicit {
@@ -323,7 +323,7 @@ test!(external_test_implicit {
 
     assert_that(p.cargo_process("cargo-test"),
         execs().with_stdout(format!("\
-{} foo v0.0.1 (file:{})
+{} foo v0.0.1 ({})
 {running} target[..]test[..]external-[..]
 
 running 1 test
@@ -345,7 +345,7 @@ running 0 tests
 test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
 
 ",
-        COMPILING, p.root().display(), running = RUNNING, doctest = DOCTEST)))
+        COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
 })
 
 test!(dont_run_examples {
@@ -381,7 +381,7 @@ test!(pass_through_command_line {
     assert_that(p.cargo_process("cargo-test").arg("bar"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
 {running} target[..]test[..]foo
 
 running 1 test
@@ -397,12 +397,12 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        compiling = COMPILING, running = RUNNING,
                        doctest = DOCTEST,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
 
     assert_that(p.cargo_process("cargo-test").arg("foo"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
 {running} target[..]test[..]foo
 
 running 1 test
@@ -418,7 +418,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        compiling = COMPILING, running = RUNNING,
                        doctest = DOCTEST,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
 })
 
 // Regression test for running cargo-test twice with
@@ -466,7 +466,7 @@ test!(lib_bin_same_name {
 
     assert_that(p.cargo_process("cargo-test"),
         execs().with_stdout(format!("\
-{} foo v0.0.1 (file:{})
+{} foo v0.0.1 ({})
 {running} target[..]test[..]foo-[..]
 
 running 1 test
@@ -488,7 +488,7 @@ running 0 tests
 test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
 
 ",
-        COMPILING, p.root().display(), running = RUNNING, doctest = DOCTEST)))
+        COMPILING, p.url(), running = RUNNING, doctest = DOCTEST)))
 })
 
 test!(lib_with_standard_name {
@@ -516,7 +516,7 @@ test!(lib_with_standard_name {
     assert_that(p.cargo_process("cargo-test"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{compiling} syntax v0.0.1 (file:{dir})
+{compiling} syntax v0.0.1 ({dir})
 {running} target[..]test[..]test-[..]
 
 running 1 test
@@ -525,7 +525,7 @@ test test ... ok
 test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        compiling = COMPILING, running = RUNNING,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
 })
 
 test!(lib_with_standard_name2 {
@@ -555,7 +555,7 @@ test!(lib_with_standard_name2 {
     assert_that(p.cargo_process("cargo-test"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{compiling} syntax v0.0.1 (file:{dir})
+{compiling} syntax v0.0.1 ({dir})
 {running} target[..]test[..]syntax-[..]
 
 running 1 test
@@ -564,7 +564,7 @@ test test ... ok
 test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        compiling = COMPILING, running = RUNNING,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
 })
 
 test!(bin_there_for_integration {
@@ -614,7 +614,7 @@ test!(test_dylib {
     assert_that(p.cargo_process("cargo-test"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
 {running} target[..]test[..]foo-[..]
 
 running 1 test
@@ -630,12 +630,12 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        compiling = COMPILING, running = RUNNING,
                        doctest = DOCTEST,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
     p.root().move_into_the_past().assert();
     assert_that(p.process(cargo_dir().join("cargo-test")),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{fresh} foo v0.0.1 (file:{dir})
+{fresh} foo v0.0.1 ({dir})
 {running} target[..]test[..]foo-[..]
 
 running 1 test
@@ -651,7 +651,7 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        fresh = FRESH, running = RUNNING,
                        doctest = DOCTEST,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
 })
 
 test!(test_twice_with_build_cmd {
@@ -671,7 +671,7 @@ test!(test_twice_with_build_cmd {
     assert_that(p.cargo_process("cargo-test"),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{compiling} foo v0.0.1 (file:{dir})
+{compiling} foo v0.0.1 ({dir})
 {running} target[..]test[..]foo-[..]
 
 running 1 test
@@ -687,12 +687,12 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        compiling = COMPILING, running = RUNNING,
                        doctest = DOCTEST,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
 
     assert_that(p.process(cargo_dir().join("cargo-test")),
                 execs().with_status(0)
                        .with_stdout(format!("\
-{fresh} foo v0.0.1 (file:{dir})
+{fresh} foo v0.0.1 ({dir})
 {running} target[..]test[..]foo-[..]
 
 running 1 test
@@ -708,5 +708,5 @@ test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured\n\n\
                        ",
                        fresh = FRESH, running = RUNNING,
                        doctest = DOCTEST,
-                       dir = p.root().display()).as_slice()));
+                       dir = p.url()).as_slice()));
 })
index 3672cd33a3c762390831c52e85ed41f444760816..47cb12c661e59daa43fb3c467722e19748d7495b 100644 (file)
@@ -4,6 +4,7 @@
 extern crate term;
 extern crate cargo;
 extern crate hamcrest;
+extern crate url;
 
 #[phase(plugin, link)]
 extern crate log;