Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Wei Zhang <[email protected]>
  • Loading branch information
zwpaper committed Sep 18, 2023
1 parent c082c03 commit f5e7bcc
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 69 deletions.
4 changes: 2 additions & 2 deletions src/config_file.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This module provides methods to handle the program's config files and
//! operations related to this.
use crate::flags::display::Display;
use crate::flags::icons::{IconOption, IconTheme};
use crate::flags::layout::Layout;
Expand All @@ -6,8 +8,6 @@ use crate::flags::size::SizeFlag;
use crate::flags::sorting::{DirGrouping, SortColumn};
use crate::flags::HyperlinkOption;
use crate::flags::{ColorOption, ThemeOption};
///! This module provides methods to handle the program's config files and operations related to
///! this.
use crate::print_error;

use std::path::{Path, PathBuf};
Expand Down
27 changes: 15 additions & 12 deletions src/core.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::color::Colors;
use crate::display;
use crate::flags::{ColorOption, Display, Flags, HyperlinkOption, Layout, SortOrder, PermissionFlag, ThemeOption};
use crate::flags::{
ColorOption, Display, Flags, HyperlinkOption, Layout, PermissionFlag, SortOrder, ThemeOption,
};
use crate::git::GitCache;
use crate::icon::Icons;

Expand Down Expand Up @@ -103,17 +105,18 @@ impl Core {
};

for path in paths {
let mut meta =
match Meta::from_path(&path,
self.flags.dereference.0,
self.flags.permission == PermissionFlag::Disable) {
Ok(meta) => meta,
Err(err) => {
print_error!("{}: {}.", path.display(), err);
exit_code.set_if_greater(ExitCode::MajorIssue);
continue;
}
};
let mut meta = match Meta::from_path(
&path,
self.flags.dereference.0,
self.flags.permission == PermissionFlag::Disable,
) {
Ok(meta) => meta,
Err(err) => {
print_error!("{}: {}.", path.display(), err);
exit_code.set_if_greater(ExitCode::MajorIssue);
continue;
}
};

let cache = if self.flags.blocks.0.contains(&Block::GitStatus) {
Some(GitCache::new(&path))
Expand Down
22 changes: 11 additions & 11 deletions src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ mod tests {
dir.child("one.d").create_dir_all().unwrap();
dir.child("one.d/two").touch().unwrap();
dir.child("one.d/.hidden").touch().unwrap();
let mut metas = Meta::from_path(Path::new(dir.path()), false)
let mut metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(42, &flags, None)
.unwrap()
Expand Down Expand Up @@ -716,7 +716,7 @@ mod tests {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("dir").create_dir_all().unwrap();
dir.child("dir/file").touch().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(42, &flags, None)
.unwrap()
Expand Down Expand Up @@ -757,7 +757,7 @@ mod tests {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("dir").create_dir_all().unwrap();
dir.child("dir/file").touch().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(42, &flags, None)
.unwrap()
Expand Down Expand Up @@ -797,7 +797,7 @@ mod tests {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("one.d").create_dir_all().unwrap();
dir.child("one.d/two").touch().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(42, &flags, None)
.unwrap()
Expand Down Expand Up @@ -828,7 +828,7 @@ mod tests {
let dir = assert_fs::TempDir::new().unwrap();
dir.child("testdir").create_dir_all().unwrap();
dir.child("test").touch().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(1, &flags, None)
.unwrap()
Expand Down Expand Up @@ -862,7 +862,7 @@ mod tests {

let dir = assert_fs::TempDir::new().unwrap();
dir.child("testdir").create_dir_all().unwrap();
let metas = Meta::from_path(Path::new(dir.path()), false)
let metas = Meta::from_path(Path::new(dir.path()), false, false)
.unwrap()
.recurse_into(1, &flags, None)
.unwrap()
Expand Down Expand Up @@ -892,11 +892,11 @@ mod tests {

let file_path = tmp_dir.path().join("file");
std::fs::File::create(&file_path).expect("failed to create the file");
let file = Meta::from_path(&file_path, false).unwrap();
let file = Meta::from_path(&file_path, false, false).unwrap();

let dir_path = tmp_dir.path().join("dir");
std::fs::create_dir(&dir_path).expect("failed to create the dir");
let dir = Meta::from_path(&dir_path, false).unwrap();
let dir = Meta::from_path(&dir_path, false, false).unwrap();

assert_eq!(
display_folder_path(&dir),
Expand Down Expand Up @@ -942,15 +942,15 @@ mod tests {

let file_path = tmp_dir.path().join("file");
std::fs::File::create(&file_path).expect("failed to create the file");
let file = Meta::from_path(&file_path, false).unwrap();
let file = Meta::from_path(&file_path, false, false).unwrap();

let dir_path = tmp_dir.path().join("dir");
std::fs::create_dir(&dir_path).expect("failed to create the dir");
let dir = Meta::from_path(&dir_path, false).unwrap();
let dir = Meta::from_path(&dir_path, false, false).unwrap();

let link_path = tmp_dir.path().join("link");
std::os::unix::fs::symlink("dir", &link_path).unwrap();
let link = Meta::from_path(&link_path, false).unwrap();
let link = Meta::from_path(&link_path, false, false).unwrap();

let grid_flags = Flags {
layout: Layout::Grid,
Expand Down
22 changes: 11 additions & 11 deletions src/icon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icons = Icons::new(true, IconOption::Never, FlagTheme::Fancy, " ".to_string());
let icon = icons.get(&meta.name);
Expand All @@ -97,7 +97,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icons = Icons::new(false, IconOption::Never, FlagTheme::Fancy, " ".to_string());
let icon = icons.get(&meta.name);
Expand All @@ -110,7 +110,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icons = Icons::new(false, IconOption::Auto, FlagTheme::Fancy, " ".to_string());
let icon = icons.get(&meta.name);
Expand All @@ -122,7 +122,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icons = Icons::new(true, IconOption::Auto, FlagTheme::Fancy, " ".to_string());
let icon = icons.get(&meta.name);
Expand All @@ -135,7 +135,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(true, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand All @@ -148,7 +148,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand All @@ -161,7 +161,7 @@ mod test {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path().join("file");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(
false,
Expand All @@ -178,7 +178,7 @@ mod test {
fn get_icon_default_directory() {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path();
let meta = Meta::from_path(file_path, false).unwrap();
let meta = Meta::from_path(file_path, false, false).unwrap();

let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand All @@ -190,7 +190,7 @@ mod test {
fn get_icon_default_directory_unicode() {
let tmp_dir = tempdir().expect("failed to create temp dir");
let file_path = tmp_dir.path();
let meta = Meta::from_path(file_path, false).unwrap();
let meta = Meta::from_path(file_path, false, false).unwrap();

let icon = Icons::new(
false,
Expand All @@ -210,7 +210,7 @@ mod test {
for (file_name, file_icon) in &IconTheme::get_default_icons_by_name() {
let file_path = tmp_dir.path().join(file_name);
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand All @@ -226,7 +226,7 @@ mod test {
for (ext, file_icon) in &IconTheme::get_default_icons_by_extension() {
let file_path = tmp_dir.path().join(format!("file.{ext}"));
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let icon = Icons::new(false, IconOption::Always, FlagTheme::Fancy, " ".to_string());
let icon_str = icon.get(&meta.name);
Expand Down
2 changes: 1 addition & 1 deletion src/meta/filetype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ mod test {
fn test_dir_type() {
let tmp_dir = tempdir().expect("failed to create temp dir");
#[cfg(not(windows))]
let meta = crate::meta::Meta::from_path(tmp_dir.path(), false)
let meta = crate::meta::Meta::from_path(tmp_dir.path(), false, false)
.expect("failed to get tempdir path");
let metadata = tmp_dir.path().metadata().expect("failed to get metas");

Expand Down
14 changes: 9 additions & 5 deletions src/meta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ impl Meta {
// path.symlink_metadata would have errored out
if dereference {
broken_link = true;
eprintln!("lsd: {}: {}\n", path.to_str().unwrap_or(""), e);
eprintln!("lsd: {}: {}", path.to_str().unwrap_or(""), e);
}
}
}
Expand All @@ -292,7 +292,11 @@ impl Meta {
match windows_utils::get_file_data(path) {
Ok((owner, permissions)) => (Some(owner), Some(permissions)),
Err(e) => {
eprintln!("lsd: {}: {}\n", path.to_str().unwrap_or(""), e);
eprintln!(
"lsd: {}: {}(Hint: Consider using `--permission disabled`.)",
path.to_str().unwrap_or(""),
e
);
(None, None)
}
}
Expand Down Expand Up @@ -352,7 +356,7 @@ mod tests {
#[test]
fn test_from_path_path() {
let dir = assert_fs::TempDir::new().unwrap();
let meta = Meta::from_path(dir.path(), false).unwrap();
let meta = Meta::from_path(dir.path(), false, false).unwrap();
assert_eq!(meta.path, dir.path())
}

Expand All @@ -362,7 +366,7 @@ mod tests {

let path_a = tmp_dir.path().join("aaa.aa");
File::create(&path_a).expect("failed to create file");
let meta_a = Meta::from_path(&path_a, false).expect("failed to get meta");
let meta_a = Meta::from_path(&path_a, false, false).expect("failed to get meta");

let path_b = tmp_dir.path().join("bbb.bb");
let path_c = tmp_dir.path().join("ccc.cc");
Expand All @@ -377,7 +381,7 @@ mod tests {
std::os::windows::fs::symlink_file(&path_c, &path_b)
.expect("failed to create broken symlink");

let meta_b = Meta::from_path(&path_b, true).expect("failed to get meta");
let meta_b = Meta::from_path(&path_b, true, false).expect("failed to get meta");

assert!(
meta_a.inode.is_some()
Expand Down
6 changes: 3 additions & 3 deletions src/meta/name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ mod test {
// Create the directory
let dir_path = tmp_dir.path().join("directory");
fs::create_dir(&dir_path).expect("failed to create the dir");
let meta = Meta::from_path(&dir_path, false).unwrap();
let meta = Meta::from_path(&dir_path, false, false).unwrap();

let colors = Colors::new(color::ThemeOption::NoLscolors);

Expand Down Expand Up @@ -395,7 +395,7 @@ mod test {
// Create the file;
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let colors = Colors::new(color::ThemeOption::NoColor);

Expand All @@ -421,7 +421,7 @@ mod test {
// Create the file;
let file_path = tmp_dir.path().join("file.txt");
File::create(&file_path).expect("failed to create file");
let meta = Meta::from_path(&file_path, false).unwrap();
let meta = Meta::from_path(&file_path, false, false).unwrap();

let colors = Colors::new(color::ThemeOption::NoColor);

Expand Down
Loading

0 comments on commit f5e7bcc

Please sign in to comment.