Skip to content

Commit

Permalink
Merge pull request #21 from AmineZouitine/integration_test
Browse files Browse the repository at this point in the history
Integration test
  • Loading branch information
AmineZouitine authored Oct 15, 2022
2 parents ae4f4c6 + 778f422 commit d5943a6
Show file tree
Hide file tree
Showing 9 changed files with 248 additions and 30 deletions.
146 changes: 146 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ repository = "https://github.com/AmineZouitine/rmt.rs"
version = "0.1.4"
edition = "2021"

[lib]
name = "rmt_lib"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
Expand All @@ -22,4 +25,6 @@ shellexpand = "2.1.2"
rustyline = "10.0.0"
colored = "2.0.0"
termion = "1.5.6"
clap = { version = "4.0.13", features = ["derive"] }
clap = { version = "4.0.13", features = ["derive"] }
assert_cmd = "2.0"
predicates = "2.1"
4 changes: 2 additions & 2 deletions src/argument_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum RmtArgumentErrors {
InvalidEmptyFolderFlags {
folder_name: String,
},
InvalidPath {
InvalidPathWithoutForceFlags {
element_name: String,
},
}
Expand All @@ -31,7 +31,7 @@ impl RmtArgumentErrors {
RmtArgumentErrors::InvalidDirFlags { folder_name, element_in_folder } => format!("You cannot delete {} folder with the {} flags because there is {} elements inside, you should use {} flags instead.", folder_name.red().bold(), "-d".red().bold().green(), element_in_folder.to_string().red().bold(), "-r".green().bold()),
RmtArgumentErrors::InvalidEmptyFolderFlags { folder_name } => format!("You cannot delete {} folder without using {} or {} flags.", folder_name.red().bold(), "-r".green().bold(), "-d".green().bold()),
RmtArgumentErrors::InvalidFillFolderFlags { folder_name } => format!("You cannot delete {} folder without using {} flags (do no use {} flags because your directory isn't empty).", folder_name.red().bold(), "-r".green().bold(), "-d".green().bold()),
RmtArgumentErrors::InvalidPath { element_name} => format!("you cannot destroy your {} because it doesn't exist (use the {} option to stop getting this warning).", element_name.red().bold(), "-f".green().bold())
RmtArgumentErrors::InvalidPathWithoutForceFlags { element_name} => format!("you cannot destroy your {} because it doesn't exist (use the {} option to stop getting this warning).", element_name.red().bold(), "-f".green().bold()),
}
}

Expand Down
23 changes: 18 additions & 5 deletions src/arguments_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,27 @@ pub struct ArgumentsManager {
}

impl ArgumentsManager {
pub fn filter_all_errors(&mut self) {
pub fn filter_all_errors(&mut self) -> i32 {
let mut exit_code = 0;
let mut result: Vec<String> = Vec::new();
self.elements
.iter()
.for_each(|path| match self.filter_error(path) {
Ok(absolute_path) => result.push(absolute_path),
Ok(absolute_path_opt) => {
if let Some(absolute_path) = absolute_path_opt {
result.push(absolute_path);
}
}
Err(arg_error) => {
println!("{}", arg_error);
exit_code = 1;
}
});
self.elements = result;
exit_code
}

fn filter_error(&self, path: &str) -> Result<String, RmtArgumentErrors> {
fn filter_error(&self, path: &str) -> Result<Option<String>, RmtArgumentErrors> {
match relative_path_to_absolute(path) {
Ok(path) => {
if Path::new(&path).is_dir() {
Expand All @@ -83,9 +90,15 @@ impl ArgumentsManager {
});
}
}
Ok(path)
Ok(Some(path))
}
Err(invalid_path) => {
if self.is_force {
Ok(None)
} else {
Err(invalid_path)
}
}
Err(invalid_path) => Err(invalid_path),
}
}
}
11 changes: 11 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub mod argument_errors;
pub mod arguments_manager;
pub mod config;
pub mod config_manager;
pub mod data_manager;
pub mod database_errors;
pub mod display_manager;
pub mod input_manager;
pub mod structure_manager;
pub mod trash_item;
pub mod trash_manager;
20 changes: 7 additions & 13 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
pub mod argument_errors;
pub mod arguments_manager;
pub mod config;
pub mod config_manager;
pub mod data_manager;
pub mod database_errors;
pub mod display_manager;
pub mod input_manager;
pub mod structure_manager;
pub mod trash_item;
pub mod trash_manager;
use rmt_lib::*;

use arguments_manager::ArgumentsManager;
use clap::Parser;
use colored::Colorize;
Expand All @@ -17,6 +8,7 @@ use crate::argument_errors::RmtArgumentErrors;

const IS_TEST: bool = false;
fn main() {
std::env::set_var("CLICOLOR_FORCE", "true");
let mut arguments_manager = ArgumentsManager::parse();
let (config, connection) = structure_manager::setup_structure(IS_TEST);

Expand All @@ -26,10 +18,10 @@ fn main() {
&& !arguments_manager.is_trash_info
{
println!("{}", RmtArgumentErrors::InvalidNumberOfArguments(0));
return;
std::process::exit(1);
}

arguments_manager.filter_all_errors();
let exit_code = arguments_manager.filter_all_errors();

if arguments_manager.is_trash_display {
input_manager::start_display(&connection, IS_TEST);
Expand All @@ -52,4 +44,6 @@ fn main() {
&arguments_manager,
);
}

std::process::exit(exit_code)
}
2 changes: 1 addition & 1 deletion src/structure_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ pub fn relative_path_to_absolute(relative_path: &str) -> Result<String, RmtArgum
Ok(absolute_path)
}
} else {
Err(RmtArgumentErrors::InvalidPath {
Err(RmtArgumentErrors::InvalidPathWithoutForceFlags {
element_name: original_path.to_string(),
})
}
Expand Down
Loading

0 comments on commit d5943a6

Please sign in to comment.