-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement assert a file matches a fixture on disk #43
Conversation
src/path/ft.rs
Outdated
@@ -59,6 +72,17 @@ impl FileTypePredicate { | |||
self.follow = yes; | |||
self | |||
} | |||
|
|||
pub(crate) fn new(path: &path::Path) -> io::Result<FileTypePredicate> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be useful to make this pub
?
What about naming it from_path
or with_path
?
src/path/ft.rs
Outdated
}) | ||
} | ||
|
||
pub(crate) fn is_file(&self) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd rather we just return the file type.
src/path/fs.rs
Outdated
|
||
impl Predicate<path::Path> for StrFilePredicate { | ||
fn eval(&self, path: &path::Path) -> bool { | ||
let content = FileContent::new(path).unwrap().utf8(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address unwrap
src/path/fs.rs
Outdated
|
||
impl fmt::Display for StrFilePredicate { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "content is {}", self.content) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- this should be
var is {}
- Should we print
content
or path?
src/path/fs.rs
Outdated
|
||
/// Predicate that compares file matches | ||
#[derive(Clone, Debug)] | ||
pub struct FileSystemEntryPredicate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this only work with files? We can handle dirs like we handle symlinks or non-existent files
If we keep it handling dirs, maybe shorten the name to EntryPredicate
?
src/path/fs.rs
Outdated
impl Predicate<path::Path> for FileSystemEntryPredicate { | ||
fn eval(&self, path: &path::Path) -> bool { | ||
if self.file_type.is_file() { | ||
if !self.file_type.eval(path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like it might be simpler if we just reused FileType
and not FileTypePredicate
src/path/fs.rs
Outdated
if !self.file_type.eval(path) { | ||
false | ||
} else { | ||
self.file_content.clone().unwrap() == FileContent::new(path).unwrap() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self.file_content.as_ref().unwrap()
addresses the clone
The first unwrap
should probably be an expect
so you can document your assumption of why it is always safe to unwrap
in this context.
Should the second unwrap
instead have us return false
?
src/path/fs.rs
Outdated
|
||
impl fmt::Display for FileSystemEntryPredicate { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "var is {}", self.file_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be file_type
or the path? The downside being we'd have to store off the path
src/path/fs.rs
Outdated
/// assert_eq!(false, predicate_dir.eval(Path::new("Cargo.toml"))); | ||
/// assert_eq!(true, predicate_dir.eval(Path::new("src"))); | ||
/// ``` | ||
pub fn eq_file_system_entry(path: &path::Path) -> FileSystemEntryPredicate { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, we can shorten this to eq_entry
if it accepts multiple types f eq_file
if it only works with files
d223bb0
to
9c62111
Compare
I integrated all changes. |
For background, we decided to simplify the If someone wants to compare a dir, they can use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor clean up that I thought I'd point out since you have to go back and address clippy.
If you already have addressed clippy. oh well, this PR can move forward and it can be cleaned up later.
src/prelude.rs
Outdated
@@ -41,6 +41,8 @@ pub mod predicate { | |||
/// | |||
/// This module contains predicates specific to path handling. | |||
pub mod path { | |||
pub use path::eq_file; | |||
pub use path::FileTypePredicate; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why was FileTypePredicate
added to the prelude?
The goal has been just to expose the minimum for creating predicates and not for general operation of the crate.
Was it because FileTypePredicate::from_path
? I'd say remove the predicate from the prelude and lets worry later about how we want it exposed in to the user.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was it because FileTypePredicate::from_path? Correct!
src/path/mod.rs
Outdated
@@ -16,3 +16,5 @@ mod ft; | |||
pub use self::ft::{is_dir, is_file, is_symlink, FileTypePredicate}; | |||
mod fc; | |||
pub use self::fc::{FileContentPredicate, PredicateFileContentExt}; | |||
mod fs; | |||
pub use self::fs::eq_file; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should publicly expose BinaryFilePredicate
and StrFilePredicate
9c62111
to
4d0569f
Compare
4d0569f
to
a69f72f
Compare
Fixed both request and the clippy failure |
Partial fixes #32