Skip to content

Commit 145fde7

Browse files
committed
Add tests for findmnt
1 parent 7479731 commit 145fde7

File tree

4 files changed

+23
-11
lines changed

4 files changed

+23
-11
lines changed

src/uu/findmnt/src/findmnt.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct Findmnt<'a> {
3131
file_name: &'a str,
3232
}
3333

34-
impl<'a> Findmnt<'a> {
34+
impl Findmnt<'_> {
3535
pub fn new(file_name: &str) -> Findmnt {
3636
Findmnt {
3737
file_name,
@@ -95,7 +95,7 @@ impl<'a> Findmnt<'a> {
9595

9696
fn filter(&self, pattern: Types) -> Vec<Node> {
9797
let mut temp_vec = Vec::<Node>::new();
98-
let _ = self.filter_with_pattern(pattern).iter().for_each(|node| {
98+
self.filter_with_pattern(pattern).iter().for_each(|node| {
9999
temp_vec.push(node.clone());
100100
});
101101
temp_vec
@@ -125,13 +125,13 @@ pub enum Types {
125125
impl fmt::Display for Types {
126126
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
127127
match self {
128-
Types::ROOT => write!(f, "{}", "/"),
129-
Types::PROC => write!(f, "{}", "/proc"),
130-
Types::SYS => write!(f, "{}", "/sys"),
131-
Types::DEV => write!(f, "{}", "/dev"),
132-
Types::RUN => write!(f, "{}", "/run"),
133-
Types::TMP => write!(f, "{}", "/tmp"),
134-
Types::BOOT => write!(f, "{}", "/boot"),
128+
Types::ROOT => write!(f, "/"),
129+
Types::PROC => write!(f, "/proc"),
130+
Types::SYS => write!(f, "/sys"),
131+
Types::DEV => write!(f, "/dev"),
132+
Types::RUN => write!(f, "/run"),
133+
Types::TMP => write!(f, "/tmp"),
134+
Types::BOOT => write!(f, "/boot"),
135135
}
136136
}
137137
}
@@ -155,7 +155,7 @@ impl Node {
155155
}
156156
}
157157

158-
pub fn filter_with_pattern(node_vec: &Vec<Node>, pattern: Types) -> Vec<Node> {
158+
pub fn filter_with_pattern(node_vec: &[Node], pattern: Types) -> Vec<Node> {
159159
node_vec
160160
.iter()
161161
.filter(|node| node.target.starts_with(&pattern.to_string()))
@@ -171,7 +171,7 @@ impl Node {
171171
let (_, rest) = rest.trim().split_once("-").unwrap();
172172
let (fstype, rest) = rest.trim().split_once(" ").unwrap();
173173
let (source, rest) = rest.trim().split_once(" ").unwrap();
174-
let options_added = if let Some(_) = rest.split_once("rw") {
174+
let options_added = if rest.split_once("rw").is_some() {
175175
rest.split_once("rw").unwrap().1
176176
} else {
177177
rest

src/uu/findmnt/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
#[cfg(target_os = "linux")]
12
uucore::bin!(uu_findmnt);

tests/by-util/test_findmnt.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use crate::common::util::TestScenario;
2+
3+
#[cfg(target_os = "linux")]
4+
#[test]
5+
fn test_findmnt() {
6+
new_ucmd!().succeeds().stdout_contains("/proc");
7+
}

tests/tests.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,7 @@ mod test_dmesg;
4040
#[cfg(feature = "fsfreeze")]
4141
#[path = "by-util/test_fsfreeze.rs"]
4242
mod test_fsfreeze;
43+
44+
#[cfg(feature = "findmnt")]
45+
#[path = "by-util/test_findmnt.rs"]
46+
mod test_findmnt;

0 commit comments

Comments
 (0)