From c48f0f48f50bbee4246e34916537653bfbc98538 Mon Sep 17 00:00:00 2001 From: Icxolu <10486322+Icxolu@users.noreply.github.com> Date: Thu, 24 Nov 2022 19:34:17 +0100 Subject: [PATCH] add tests to verify executable state on Windows --- src/meta/filetype.rs | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/meta/filetype.rs b/src/meta/filetype.rs index aa3f45b..e3fa1cc 100644 --- a/src/meta/filetype.rs +++ b/src/meta/filetype.rs @@ -112,7 +112,6 @@ mod test { #[cfg(unix)] use crate::meta::Permissions; use crossterm::style::{Color, Stylize}; - #[cfg(unix)] use std::fs::File; #[cfg(unix)] use std::os::unix::fs::symlink; @@ -281,4 +280,42 @@ mod test { file_type.render(&colors) ); } + + #[cfg(windows)] + #[test] + fn test_file_executable() { + let tmp_dir = tempdir().expect("failed to create temp dir"); + for ext in FileType::EXECUTABLE_EXTENSIONS { + // Create the file; + let file_path = tmp_dir.path().join(format!("file.{ext}")); + File::create(&file_path).expect("failed to create file"); + let meta = file_path.metadata().expect("failed to get metas"); + + let colors = Colors::new(ThemeOption::NoLscolors); + let file_type = FileType::new(&meta, None, &file_path); + + assert_eq!( + ".".to_string().with(Color::AnsiValue(40)), + file_type.render(&colors) + ); + } + } + + #[cfg(windows)] + #[test] + fn test_file_not_executable() { + let tmp_dir = tempdir().expect("failed to create temp dir"); + // Create the file; + let file_path = tmp_dir.path().join("file.txt"); + File::create(&file_path).expect("failed to create file"); + let meta = file_path.metadata().expect("failed to get metas"); + + let colors = Colors::new(ThemeOption::NoLscolors); + let file_type = FileType::new(&meta, None, &file_path); + + assert_eq!( + ".".to_string().with(Color::AnsiValue(184)), + file_type.render(&colors) + ); + } }