Skip to content

Commit

Permalink
Rollup merge of rust-lang#36631 - frewsxcv:dir-entry-debug, r=sfackler
Browse files Browse the repository at this point in the history
Implement Debug for DirEntry.

None
  • Loading branch information
Jonathan Turner authored Sep 21, 2016
2 parents 9c469ff + 8b8681e commit 9b25f10
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1055,6 +1055,15 @@ impl DirEntry {
}
}

#[stable(feature = "dir_entry_debug", since = "1.13.0")]
impl fmt::Debug for DirEntry {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("DirEntry")
.field(&self.path())
.finish()
}
}

impl AsInner<fs_imp::DirEntry> for DirEntry {
fn as_inner(&self) -> &fs_imp::DirEntry { &self.0 }
}
Expand Down Expand Up @@ -2641,6 +2650,18 @@ mod tests {
}
}

#[test]
fn dir_entry_debug() {
let tmpdir = tmpdir();
let file_path = &tmpdir.join("b");
File::create(file_path).unwrap();
let mut read_dir = tmpdir.path().read_dir().unwrap();
let dir_entry = read_dir.next().unwrap().unwrap();
let actual = format!("{:?}", dir_entry);
let expected = format!("DirEntry(\"{}\")", file_path.display());
assert_eq!(actual, expected);
}

#[test]
fn read_dir_not_found() {
let res = fs::read_dir("/path/that/does/not/exist");
Expand Down

0 comments on commit 9b25f10

Please sign in to comment.