diff options
| author | Sean McArthur <sean.monstar@gmail.com> | 2014-12-20 00:09:35 -0800 |
|---|---|---|
| committer | Sean McArthur <sean.monstar@gmail.com> | 2015-01-06 14:49:42 -0800 |
| commit | 44440e5c18a1dbcc9685866ffffe00c508929079 (patch) | |
| tree | b66c50cd1e471dc0e37b8a0db2cf7f8f28fbac5f /src/libstd/path | |
| parent | 8efd9901b628d687d11a4d0ccc153553b38ada49 (diff) | |
| download | rust-44440e5c18a1dbcc9685866ffffe00c508929079.tar.gz rust-44440e5c18a1dbcc9685866ffffe00c508929079.zip | |
core: split into fmt::Show and fmt::String
fmt::Show is for debugging, and can and should be implemented for
all public types. This trait is used with `{:?}` syntax. There still
exists #[derive(Show)].
fmt::String is for types that faithfully be represented as a String.
Because of this, there is no way to derive fmt::String, all
implementations must be purposeful. It is used by the default format
syntax, `{}`.
This will break most instances of `{}`, since that now requires the type
to impl fmt::String. In most cases, replacing `{}` with `{:?}` is the
correct fix. Types that were being printed specifically for users should
receive a fmt::String implementation to fix this.
Part of #20013
[breaking-change]
Diffstat (limited to 'src/libstd/path')
| -rw-r--r-- | src/libstd/path/mod.rs | 31 | ||||
| -rw-r--r-- | src/libstd/path/posix.rs | 101 | ||||
| -rw-r--r-- | src/libstd/path/windows.rs | 119 |
3 files changed, 113 insertions, 138 deletions
diff --git a/src/libstd/path/mod.rs b/src/libstd/path/mod.rs index b020164158c..0ee7bdf12e6 100644 --- a/src/libstd/path/mod.rs +++ b/src/libstd/path/mod.rs @@ -459,7 +459,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("abc/def.txt"); /// p.set_extension("csv"); - /// assert!(p == Path::new("abc/def.csv")); + /// assert_eq!(p, Path::new("abc/def.csv")); /// # } /// ``` /// @@ -508,7 +508,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("abc/def.txt"); - /// assert!(p.with_filename("foo.dat") == Path::new("abc/foo.dat")); + /// assert_eq!(p.with_filename("foo.dat"), Path::new("abc/foo.dat")); /// # } /// ``` /// @@ -533,7 +533,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("abc/def.txt"); - /// assert!(p.with_extension("csv") == Path::new("abc/def.csv")); + /// assert_eq!(p.with_extension("csv"), Path::new("abc/def.csv")); /// # } /// ``` /// @@ -557,7 +557,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { /// let p = Path::new("abc/def/ghi"); - /// assert!(p.dir_path() == Path::new("abc/def")); + /// assert_eq!(p.dir_path(), Path::new("abc/def")); /// # } /// ``` fn dir_path(&self) -> Self { @@ -575,8 +575,8 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # foo(); /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { - /// assert!(Path::new("abc/def").root_path() == None); - /// assert!(Path::new("/abc/def").root_path() == Some(Path::new("/"))); + /// assert_eq!(Path::new("abc/def").root_path(), None); + /// assert_eq!(Path::new("/abc/def").root_path(), Some(Path::new("/"))); /// # } /// ``` fn root_path(&self) -> Option<Self>; @@ -592,7 +592,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("foo/bar"); /// p.push("baz.txt"); - /// assert!(p == Path::new("foo/bar/baz.txt")); + /// assert_eq!(p, Path::new("foo/bar/baz.txt")); /// # } /// ``` /// @@ -616,7 +616,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("foo"); /// p.push_many(&["bar", "baz.txt"]); - /// assert!(p == Path::new("foo/bar/baz.txt")); + /// assert_eq!(p, Path::new("foo/bar/baz.txt")); /// # } /// ``` #[inline] @@ -645,7 +645,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let mut p = Path::new("foo/bar/baz.txt"); /// p.pop(); - /// assert!(p == Path::new("foo/bar")); + /// assert_eq!(p, Path::new("foo/bar")); /// # } /// ``` fn pop(&mut self) -> bool; @@ -661,7 +661,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(windows)] fn foo() {} /// # #[cfg(unix)] fn foo() { /// let p = Path::new("/foo"); - /// assert!(p.join("bar.txt") == Path::new("/foo/bar.txt")); + /// assert_eq!(p.join("bar.txt"), Path::new("/foo/bar.txt")); /// # } /// ``` /// @@ -687,7 +687,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// # #[cfg(unix)] fn foo() { /// let p = Path::new("foo"); /// let fbbq = Path::new("foo/bar/baz/quux.txt"); - /// assert!(p.join_many(&["bar", "baz", "quux.txt"]) == fbbq); + /// assert_eq!(p.join_many(&["bar", "baz", "quux.txt"]), fbbq); /// # } /// ``` #[inline] @@ -764,7 +764,7 @@ pub trait GenericPath: Clone + GenericPathUnsafe { /// let p = Path::new("foo/bar/baz/quux.txt"); /// let fb = Path::new("foo/bar"); /// let bq = Path::new("baz/quux.txt"); - /// assert!(p.path_relative_from(&fb) == Some(bq)); + /// assert_eq!(p.path_relative_from(&fb), Some(bq)); /// # } /// ``` fn path_relative_from(&self, base: &Self) -> Option<Self>; @@ -822,8 +822,15 @@ pub struct Display<'a, P:'a> { filename: bool } +//NOTE(stage0): replace with deriving(Show) after snapshot impl<'a, P: GenericPath> fmt::Show for Display<'a, P> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::String::fmt(self, f) + } +} + +impl<'a, P: GenericPath> fmt::String for Display<'a, P> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.as_cow().fmt(f) } } diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index d9981ace030..3f8ab47e150 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -12,6 +12,7 @@ use clone::Clone; use cmp::{Ordering, Eq, Ord, PartialEq, PartialOrd}; +use fmt; use hash; use io::Writer; use iter::{AdditiveIterator, Extend}; @@ -56,6 +57,12 @@ pub fn is_sep(c: char) -> bool { c == SEP } +impl fmt::Show for Path { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Path {{ {} }}", self.display()) + } +} + impl PartialEq for Path { #[inline] fn eq(&self, other: &Path) -> bool { @@ -438,13 +445,13 @@ mod tests { (s: $path:expr, $exp:expr) => ( { let path = $path; - assert!(path.as_str() == Some($exp)); + assert_eq!(path.as_str(), Some($exp)); } ); (v: $path:expr, $exp:expr) => ( { let path = $path; - assert!(path.as_vec() == $exp); + assert_eq!(path.as_vec(), $exp); } ) } @@ -458,7 +465,7 @@ mod tests { t!(v: Path::new(b"a/b/c\xFF"), b"a/b/c\xFF"); t!(v: Path::new(b"\xFF/../foo\x80"), b"foo\x80"); let p = Path::new(b"a/b/c\xFF"); - assert!(p.as_str() == None); + assert!(p.as_str().is_none()); t!(s: Path::new(""), "."); t!(s: Path::new("/"), "/"); @@ -488,14 +495,14 @@ mod tests { b"/bar"); let p = Path::new(b"foo/bar\x80"); - assert!(p.as_str() == None); + assert!(p.as_str().is_none()); } #[test] fn test_opt_paths() { - assert!(Path::new_opt(b"foo/bar\0") == None); + assert!(Path::new_opt(b"foo/bar\0").is_none()); t!(v: Path::new_opt(b"foo/bar").unwrap(), b"foo/bar"); - assert!(Path::new_opt("foo/bar\0") == None); + assert!(Path::new_opt("foo/bar\0").is_none()); t!(s: Path::new_opt("foo/bar").unwrap(), "foo/bar"); } @@ -524,7 +531,7 @@ mod tests { ($path:expr, $disp:ident, $exp:expr) => ( { let path = Path::new($path); - assert!(path.$disp().to_string() == $exp); + assert_eq!(path.$disp().to_string(), $exp); } ) } @@ -540,14 +547,14 @@ mod tests { { let path = Path::new($path); let mo = path.display().as_cow(); - assert!(mo.as_slice() == $exp); + assert_eq!(mo.as_slice(), $exp); } ); ($path:expr, $exp:expr, filename) => ( { let path = Path::new($path); let mo = path.filename_display().as_cow(); - assert!(mo.as_slice() == $exp); + assert_eq!(mo.as_slice(), $exp); } ) } @@ -567,9 +574,9 @@ mod tests { { let path = Path::new($path); let f = format!("{}", path.display()); - assert!(f == $exp); + assert_eq!(f, $exp); let f = format!("{}", path.filename_display()); - assert!(f == $expf); + assert_eq!(f, $expf); } ) } @@ -589,21 +596,21 @@ mod tests { (s: $path:expr, $op:ident, $exp:expr) => ( { let path = Path::new($path); - assert!(path.$op() == ($exp).as_bytes()); + assert_eq!(path.$op(), ($exp).as_bytes()); } ); (s: $path:expr, $op:ident, $exp:expr, opt) => ( { let path = Path::new($path); let left = path.$op().map(|x| str::from_utf8(x).unwrap()); - assert!(left == $exp); + assert_eq!(left, $exp); } ); (v: $path:expr, $op:ident, $exp:expr) => ( { let arg = $path; let path = Path::new(arg); - assert!(path.$op() == $exp); + assert_eq!(path.$op(), $exp); } ); } @@ -677,7 +684,7 @@ mod tests { let mut p1 = Path::new(path); let p2 = p1.clone(); p1.push(join); - assert!(p1 == p2.join(join)); + assert_eq!(p1, p2.join(join)); } ) } @@ -696,7 +703,7 @@ mod tests { let mut p = Path::new($path); let push = Path::new($push); p.push(&push); - assert!(p.as_str() == Some($exp)); + assert_eq!(p.as_str(), Some($exp)); } ) } @@ -716,14 +723,14 @@ mod tests { { let mut p = Path::new($path); p.push_many(&$push); - assert!(p.as_str() == Some($exp)); + assert_eq!(p.as_str(), Some($exp)); } ); (v: $path:expr, $push:expr, $exp:expr) => ( { let mut p = Path::new($path); p.push_many(&$push); - assert!(p.as_vec() == $exp); + assert_eq!(p.as_vec(), $exp); } ) } @@ -744,16 +751,16 @@ mod tests { { let mut p = Path::new($path); let result = p.pop(); - assert!(p.as_str() == Some($left)); - assert!(result == $right); + assert_eq!(p.as_str(), Some($left)); + assert_eq!(result, $right); } ); (b: $path:expr, $left:expr, $right:expr) => ( { let mut p = Path::new($path); let result = p.pop(); - assert!(p.as_vec() == $left); - assert!(result == $right); + assert_eq!(p.as_vec(), $left); + assert_eq!(result, $right); } ) } @@ -776,8 +783,8 @@ mod tests { #[test] fn test_root_path() { - assert!(Path::new(b"a/b/c").root_path() == None); - assert!(Path::new(b"/a/b/c").root_path() == Some(Path::new("/"))); + assert_eq!(Path::new(b"a/b/c").root_path(), None); + assert_eq!(Path::new(b"/a/b/c").root_path(), Some(Path::new("/"))); } #[test] @@ -801,7 +808,7 @@ mod tests { let path = Path::new($path); let join = Path::new($join); let res = path.join(&join); - assert!(res.as_str() == Some($exp)); + assert_eq!(res.as_str(), Some($exp)); } ) } @@ -821,14 +828,14 @@ mod tests { { let path = Path::new($path); let res = path.join_many(&$join); - assert!(res.as_str() == Some($exp)); + assert_eq!(res.as_str(), Some($exp)); } ); (v: $path:expr, $join:expr, $exp:expr) => ( { let path = Path::new($path); let res = path.join_many(&$join); - assert!(res.as_vec() == $exp); + assert_eq!(res.as_vec(), $exp); } ) } @@ -902,7 +909,7 @@ mod tests { let mut p1 = Path::new(path); p1.$set(arg); let p2 = Path::new(path); - assert!(p1 == p2.$with(arg)); + assert_eq!(p1, p2.$with(arg)); } ); (v: $path:expr, $set:ident, $with:ident, $arg:expr) => ( @@ -912,7 +919,7 @@ mod tests { let mut p1 = Path::new(path); p1.$set(arg); let p2 = Path::new(path); - assert!(p1 == p2.$with(arg)); + assert_eq!(p1, p2.$with(arg)); } ) } @@ -942,31 +949,19 @@ mod tests { (s: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; - let filename = $filename; - assert!(path.filename_str() == filename, - "{}.filename_str(): Expected `{}`, found {}", - path.as_str().unwrap(), filename, path.filename_str()); - let dirname = $dirname; - assert!(path.dirname_str() == dirname, - "`{}`.dirname_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), dirname, path.dirname_str()); - let filestem = $filestem; - assert!(path.filestem_str() == filestem, - "`{}`.filestem_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), filestem, path.filestem_str()); - let ext = $ext; - assert!(path.extension_str() == ext, - "`{}`.extension_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), ext, path.extension_str()); - } + assert_eq!(path.filename_str(), $filename); + assert_eq!(path.dirname_str(), $dirname); + assert_eq!(path.filestem_str(), $filestem); + assert_eq!(path.extension_str(), $ext); + } ); (v: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; - assert!(path.filename() == $filename); - assert!(path.dirname() == $dirname); - assert!(path.filestem() == $filestem); - assert!(path.extension() == $ext); + assert_eq!(path.filename(), $filename); + assert_eq!(path.dirname(), $dirname); + assert_eq!(path.filestem(), $filestem); + assert_eq!(path.extension(), $ext); } ) } @@ -1154,12 +1149,10 @@ mod tests { let comps = path.components().collect::<Vec<&[u8]>>(); let exp: &[&str] = &$exp; let exps = exp.iter().map(|x| x.as_bytes()).collect::<Vec<&[u8]>>(); - assert!(comps == exps, "components: Expected {}, found {}", - comps, exps); + assert_eq!(comps, exprs); let comps = path.components().rev().collect::<Vec<&[u8]>>(); let exps = exps.into_iter().rev().collect::<Vec<&[u8]>>(); - assert!(comps == exps, "rev_components: Expected {}, found {}", - comps, exps); + assert_eq!(comps, exps); } ); (b: $arg:expr, [$($exp:expr),*]) => ( diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index 4b5d793355b..58bda339580 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -18,6 +18,7 @@ use ascii::AsciiExt; use char::CharExt; use clone::Clone; use cmp::{Ordering, Eq, Ord, PartialEq, PartialOrd}; +use fmt; use hash; use io::Writer; use iter::{AdditiveIterator, Extend}; @@ -83,6 +84,12 @@ pub struct Path { sepidx: Option<uint> // index of the final separator in the non-prefix portion of repr } +impl fmt::Show for Path { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Path {{ {} }}", self.display()) + } +} + impl PartialEq for Path { #[inline] fn eq(&self, other: &Path) -> bool { @@ -1114,13 +1121,13 @@ mod tests { (s: $path:expr, $exp:expr) => ( { let path = $path; - assert!(path.as_str() == Some($exp)); + assert_eq!(path.as_str(), Some($exp)); } ); (v: $path:expr, $exp:expr) => ( { let path = $path; - assert!(path.as_vec() == $exp); + assert_eq!(path.as_vec(), $exp); } ) } @@ -1133,8 +1140,7 @@ mod tests { let path = $path; let exp = $exp; let res = parse_prefix(path); - assert!(res == exp, - "parse_prefix(\"{}\"): expected {}, found {}", path, exp, res); + assert_eq!(res, exp); } ) } @@ -1350,7 +1356,7 @@ mod tests { { let path = $path; let path = Path::new(path); - assert!(path.$op() == Some($exp)); + assert_eq!(path.$op(), Some($exp)); } ); (s: $path:expr, $op:ident, $exp:expr, opt) => ( @@ -1358,14 +1364,14 @@ mod tests { let path = $path; let path = Path::new(path); let left = path.$op(); - assert!(left == $exp); + assert_eq!(left, $exp); } ); (v: $path:expr, $op:ident, $exp:expr) => ( { let path = $path; let path = Path::new(path); - assert!(path.$op() == $exp); + assert_eq!(path.$op(), $exp); } ) } @@ -1476,7 +1482,7 @@ mod tests { let mut p1 = Path::new(path); let p2 = p1.clone(); p1.push(join); - assert!(p1 == p2.join(join)); + assert_eq!(p1, p2.join(join)); } ) } @@ -1490,9 +1496,9 @@ mod tests { // we do want to check one odd case though to ensure the prefix is re-parsed let mut p = Path::new("\\\\?\\C:"); - assert!(prefix(&p) == Some(VerbatimPrefix(2))); + assert_eq!(prefix(&p), Some(VerbatimPrefix(2))); p.push("foo"); - assert!(prefix(&p) == Some(VerbatimDiskPrefix)); + assert_eq!(prefix(&p), Some(VerbatimDiskPrefix)); assert_eq!(p.as_str(), Some("\\\\?\\C:\\foo")); // and another with verbatim non-normalized paths @@ -1591,10 +1597,8 @@ mod tests { let mut p = Path::new(pstr); let result = p.pop(); let left = $left; - assert!(p.as_str() == Some(left), - "`{}`.pop() failed; expected remainder `{}`, found `{}`", - pstr, left, p.as_str().unwrap()); - assert!(result == $right); + assert_eq!(p.as_str(), Some(left)); + assert_eq!(result, $right); } ); (b: $path:expr, $left:expr, $right:expr) => ( @@ -1602,7 +1606,7 @@ mod tests { let mut p = Path::new($path); let result = p.pop(); assert_eq!(p.as_vec(), $left); - assert!(result == $right); + assert_eq!(result, $right); } ) } @@ -1645,16 +1649,16 @@ mod tests { #[test] fn test_root_path() { - assert!(Path::new("a\\b\\c").root_path() == None); - assert!(Path::new("\\a\\b\\c").root_path() == Some(Path::new("\\"))); - assert!(Path::new("C:a").root_path() == Some(Path::new("C:"))); - assert!(Path::new("C:\\a").root_path() == Some(Path::new("C:\\"))); - assert!(Path::new("\\\\a\\b\\c").root_path() == Some(Path::new("\\\\a\\b"))); - assert!(Path::new("\\\\?\\a\\b").root_path() == Some(Path::new("\\\\?\\a"))); - assert!(Path::new("\\\\?\\C:\\a").root_path() == Some(Path::new("\\\\?\\C:\\"))); - assert!(Path::new("\\\\?\\UNC\\a\\b\\c").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(), Some(Path::new("C:"))); + 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!(Path::new("\\\\.\\a\\b").root_path() == Some(Path::new("\\\\.\\a"))); + assert_eq!(Path::new("\\\\.\\a\\b").root_path(), Some(Path::new("\\\\.\\a"))); } #[test] @@ -1732,9 +1736,7 @@ mod tests { let arg = $arg; let res = path.$op(arg); let exp = $res; - assert!(res.as_str() == Some(exp), - "`{}`.{}(\"{}\"): Expected `{}`, found `{}`", - pstr, stringify!($op), arg, exp, res.as_str().unwrap()); + assert_eq!(Path::new($path).$op($arg), $res); } ) } @@ -1817,7 +1819,7 @@ mod tests { let mut p1 = Path::new(path); p1.$set(arg); let p2 = Path::new(path); - assert!(p1 == p2.$with(arg)); + assert_eq!(p1, p2.$with(arg)); } ); (v: $path:expr, $set:ident, $with:ident, $arg:expr) => ( @@ -1827,7 +1829,7 @@ mod tests { let mut p1 = Path::new(path); p1.$set(arg); let p2 = Path::new(path); - assert!(p1 == p2.$with(arg)); + assert_eq!(p1, p2.$with(arg)); } ) } @@ -1858,31 +1860,19 @@ mod tests { (s: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; - let filename = $filename; - assert!(path.filename_str() == filename, - "`{}`.filename_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), filename, path.filename_str()); - let dirname = $dirname; - assert!(path.dirname_str() == dirname, - "`{}`.dirname_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), dirname, path.dirname_str()); - let filestem = $filestem; - assert!(path.filestem_str() == filestem, - "`{}`.filestem_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), filestem, path.filestem_str()); - let ext = $ext; - assert!(path.extension_str() == ext, - "`{}`.extension_str(): Expected `{}`, found `{}`", - path.as_str().unwrap(), ext, path.extension_str()); + assert_eq!(path.filename_str(), $filename); + assert_eq!(path.dirname_str(), $dirname); + assert_eq!(path.filestem_str(), $filestem); + assert_eq!(path.extension_str(), $ext); } ); (v: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; - assert!(path.filename() == $filename); - assert!(path.dirname() == $dirname); - assert!(path.filestem() == $filestem); - assert!(path.extension() == $ext); + assert_eq!(path.filename(), $filename); + assert_eq!(path.dirname(), $dirname); + assert_eq!(path.filestem(), $filestem); + assert_eq!(path.extension(), $ext); } ) } @@ -1926,17 +1916,10 @@ mod tests { let path = Path::new($path); let (abs, vol, cwd, rel) = ($abs, $vol, $cwd, $rel); let b = path.is_absolute(); - assert!(b == abs, "Path '{}'.is_absolute(): expected {}, found {}", - path.as_str().unwrap(), abs, b); - let b = is_vol_relative(&path); - assert!(b == vol, "is_vol_relative('{}'): expected {}, found {}", - path.as_str().unwrap(), vol, b); - let b = is_cwd_relative(&path); - assert!(b == cwd, "is_cwd_relative('{}'): expected {}, found {}", - path.as_str().unwrap(), cwd, b); - let b = path.is_relative(); - assert!(b == rel, "Path '{}'.is_relativf(): expected {}, found {}", - path.as_str().unwrap(), rel, b); + assert_eq!(path.is_absolute(), asb); + assert_eq!(is_vol_relative(&path), vol); + assert_eq!(is_cwd_relative(&path), cwd); + assert_eq!(path.is_relative(), rel); } ) } @@ -1967,9 +1950,7 @@ mod tests { let dest = Path::new($dest); let exp = $exp; let res = path.is_ancestor_of(&dest); - assert!(res == exp, - "`{}`.is_ancestor_of(`{}`): Expected {}, found {}", - path.as_str().unwrap(), dest.as_str().unwrap(), exp, res); + assert_eq!(Path::new($path).is_ancestor_of(Path::new($dest)), $exp); } ) } @@ -2098,14 +2079,8 @@ mod tests { macro_rules! t { (s: $path:expr, $other:expr, $exp:expr) => ( { - let path = Path::new($path); - let other = Path::new($other); - let res = path.path_relative_from(&other); - let exp = $exp; - assert!(res.as_ref().and_then(|x| x.as_str()) == exp, - "`{}`.path_relative_from(`{}`): Expected {}, got {}", - path.as_str().unwrap(), other.as_str().unwrap(), exp, - res.as_ref().and_then(|x| x.as_str())); + assert_eq!(Path::new($path).path_relative_from(Path::new($other)) + .as_ref().and_then(|x| x.as_str()), $exp); } ) } @@ -2314,7 +2289,7 @@ mod tests { let path = Path::new($path); let exp: Option<&str> = $exp; let exp = exp.map(|s| Path::new(s)); - assert!(make_non_verbatim(&path) == exp); + assert_eq!(make_non_verbatim(&path), exp); } ) } |
