Fix tests for create directories, add tests for open directory

This commit is contained in:
Adrian Woźniak 2019-12-22 18:41:59 +01:00
parent ac0f55e18e
commit 7c64c20caf
3 changed files with 61 additions and 25 deletions

View File

@ -382,4 +382,17 @@ mod tests {
state.set_open_file_modal(Some(modal)); state.set_open_file_modal(Some(modal));
assert_eq!(state.open_settings(&mut renderer), Ok(())); assert_eq!(state.open_settings(&mut renderer), Ok(()));
} }
#[test]
fn must_open_directory() {
assert_eq!(
std::fs::create_dir_all("/tmp/must_open_directory").is_ok(),
true
);
let config = support::build_config();
let mut renderer = support::SimpleRendererMock::new(config.clone());
let mut state = AppState::new(Arc::clone(&config));
state.open_directory("/must_open_directory".to_owned(), &mut renderer);
}
} }

View File

@ -59,8 +59,8 @@ mod tests {
#[test] #[test]
fn assert_create_fonts() { fn assert_create_fonts() {
let uniq = Uuid::new_v4(); let unique = Uuid::new_v4();
let test_path = join("/tmp/rider-tests".to_owned(), uniq.to_string()); let test_path = join("/tmp/rider-tests".to_owned(), unique.to_string());
create_dir_all(test_path.clone()).unwrap(); create_dir_all(test_path.clone()).unwrap();
let directories = Directories::new(Some(test_path.clone()), None); let directories = Directories::new(Some(test_path.clone()), None);
assert_eq!(create(&directories).is_ok(), true); assert_eq!(create(&directories).is_ok(), true);
@ -72,8 +72,8 @@ mod tests {
#[test] #[test]
fn assert_create_log() { fn assert_create_log() {
let uniq = Uuid::new_v4(); let unique = Uuid::new_v4();
let test_path = join("/tmp/rider-tests".to_owned(), uniq.to_string()); let test_path = join("/tmp/rider-tests".to_owned(), unique.to_string());
create_dir_all(test_path.clone()).unwrap(); create_dir_all(test_path.clone()).unwrap();
let directories = Directories::new(Some(test_path.clone()), None); let directories = Directories::new(Some(test_path.clone()), None);
assert_eq!(create(&directories).is_ok(), true); assert_eq!(create(&directories).is_ok(), true);
@ -85,8 +85,8 @@ mod tests {
#[test] #[test]
fn assert_create_themes() { fn assert_create_themes() {
let uniq = Uuid::new_v4(); let unique = Uuid::new_v4();
let test_path = join("/tmp/rider-tests".to_owned(), uniq.to_string()); let test_path = join("/tmp/rider-tests".to_owned(), unique.to_string());
create_dir_all(test_path.clone()).unwrap(); create_dir_all(test_path.clone()).unwrap();
let directories = Directories::new(Some(test_path.clone()), None); let directories = Directories::new(Some(test_path.clone()), None);
assert_eq!( assert_eq!(

View File

@ -16,8 +16,13 @@ pub mod images;
pub mod themes; pub mod themes;
pub mod write_bytes_to; pub mod write_bytes_to;
#[cfg_attr(tarpaulin, skip)]
fn main() -> std::io::Result<()> { fn main() -> std::io::Result<()> {
let directories = Directories::new(None, None); run_generator(None, None)
}
fn run_generator(config_dir: Option<String>, project_dir: Option<String>) -> std::io::Result<()> {
let directories = Directories::new(config_dir, project_dir);
config::create(&directories)?; config::create(&directories)?;
themes::create(&directories)?; themes::create(&directories)?;
images::create(&directories)?; images::create(&directories)?;
@ -45,8 +50,8 @@ mod tests {
#[test] #[test]
fn assert_main() { fn assert_main() {
let uniq = Uuid::new_v4(); let unique = Uuid::new_v4();
let joined = join("/tmp/rider-tests".to_owned(), uniq.to_string()); let joined = join("/tmp/rider-tests".to_owned(), unique.to_string());
let test_path = joined.as_str(); let test_path = joined.as_str();
remove_dir_all(joined.clone()).unwrap_or_else(|_| ()); remove_dir_all(joined.clone()).unwrap_or_else(|_| ());
create_dir_all(test_path.to_owned()).unwrap(); create_dir_all(test_path.to_owned()).unwrap();
@ -58,7 +63,10 @@ mod tests {
!exists(&test_path.to_owned(), ".rider"), !exists(&test_path.to_owned(), ".rider"),
"rider config dir should not exists before generator run" "rider config dir should not exists before generator run"
); );
debug_assert!(main().is_ok(), "generator should not failed"); debug_assert!(
run_generator(Some(test_path.to_owned()), Some(test_path.to_owned())).is_ok(),
"generator should not failed"
);
debug_assert!( debug_assert!(
exists(&test_path.to_owned(), ".rider"), exists(&test_path.to_owned(), ".rider"),
"rider config dir should exists after generator run" "rider config dir should exists after generator run"
@ -67,8 +75,8 @@ mod tests {
#[test] #[test]
fn assert_fonts_dir() { fn assert_fonts_dir() {
let uniq = Uuid::new_v4(); let unique = Uuid::new_v4();
let joined = join("/tmp/rider-tests".to_owned(), uniq.to_string()); let joined = join("/tmp/rider-tests".to_owned(), unique.to_string());
remove_dir_all(joined.clone()).unwrap_or_else(|_| ()); remove_dir_all(joined.clone()).unwrap_or_else(|_| ());
create_dir_all(joined.clone()).unwrap(); create_dir_all(joined.clone()).unwrap();
@ -80,7 +88,10 @@ mod tests {
!exists(&joined, "rider/fonts"), !exists(&joined, "rider/fonts"),
"fonts director should not exists before run generator" "fonts director should not exists before run generator"
); );
debug_assert!(main().is_ok(), "generator should not failed"); debug_assert!(
run_generator(Some(joined.to_owned()), Some(joined.to_owned())).is_ok(),
"generator should not failed"
);
debug_assert!( debug_assert!(
exists(&joined, "rider/fonts"), exists(&joined, "rider/fonts"),
"fonts director should exists after run generator" "fonts director should exists after run generator"
@ -89,8 +100,8 @@ mod tests {
#[test] #[test]
fn assert_log_dir() { fn assert_log_dir() {
let uniq = Uuid::new_v4(); let unique = Uuid::new_v4();
let joined = join("/tmp/rider-tests".to_owned(), uniq.to_string()); let joined = join("/tmp/rider-tests".to_owned(), unique.to_string());
remove_dir_all(joined.clone()).unwrap_or_else(|_| ()); remove_dir_all(joined.clone()).unwrap_or_else(|_| ());
create_dir_all(joined.clone()).unwrap(); create_dir_all(joined.clone()).unwrap();
@ -102,7 +113,10 @@ mod tests {
!exists(&joined, "rider/log"), !exists(&joined, "rider/log"),
"log should not exists before run generator" "log should not exists before run generator"
); );
debug_assert!(main().is_ok(), "generator should not failed"); debug_assert!(
run_generator(Some(joined.to_owned()), Some(joined.to_owned())).is_ok(),
"generator should not failed"
);
debug_assert!( debug_assert!(
exists(&joined, "rider/log"), exists(&joined, "rider/log"),
"log should exists after run generator" "log should exists after run generator"
@ -111,8 +125,8 @@ mod tests {
#[test] #[test]
fn assert_themes_dir() { fn assert_themes_dir() {
let uniq = Uuid::new_v4(); let unique = Uuid::new_v4();
let joined = join("/tmp/rider-tests".to_owned(), uniq.to_string()); let joined = join("/tmp/rider-tests".to_owned(), unique.to_string());
remove_dir_all(joined.clone()).unwrap_or_else(|_| ()); remove_dir_all(joined.clone()).unwrap_or_else(|_| ());
create_dir_all(joined.clone()).unwrap(); create_dir_all(joined.clone()).unwrap();
@ -124,7 +138,10 @@ mod tests {
!exists(&joined, "rider/themes"), !exists(&joined, "rider/themes"),
"themes should not exists before run generator" "themes should not exists before run generator"
); );
debug_assert!(main().is_ok(), "generator should not failed"); debug_assert!(
run_generator(Some(joined.to_owned()), Some(joined.to_owned())).is_ok(),
"generator should not failed"
);
debug_assert!( debug_assert!(
exists(&joined, "rider/themes"), exists(&joined, "rider/themes"),
"themes should exists after run generator" "themes should exists after run generator"
@ -133,8 +150,8 @@ mod tests {
#[test] #[test]
fn assert_default_json() { fn assert_default_json() {
let uniq = Uuid::new_v4(); let unique = Uuid::new_v4();
let joined = join("/tmp/rider-tests".to_owned(), uniq.to_string()); let joined = join("/tmp/rider-tests".to_owned(), unique.to_string());
remove_dir_all(joined.clone()).unwrap_or_else(|_| ()); remove_dir_all(joined.clone()).unwrap_or_else(|_| ());
create_dir_all(joined.clone()).unwrap(); create_dir_all(joined.clone()).unwrap();
@ -146,7 +163,10 @@ mod tests {
!exists(&joined, "rider/themes/default.json"), !exists(&joined, "rider/themes/default.json"),
"default theme should not exists before run generator" "default theme should not exists before run generator"
); );
debug_assert!(main().is_ok(), "generator should not failed"); debug_assert!(
run_generator(Some(joined.to_owned()), Some(joined.to_owned())).is_ok(),
"generator should not failed"
);
debug_assert!( debug_assert!(
exists(&joined, "rider/themes/default.json"), exists(&joined, "rider/themes/default.json"),
"default theme should exists after run generator" "default theme should exists after run generator"
@ -155,8 +175,8 @@ mod tests {
#[test] #[test]
fn assert_railscasts_json() { fn assert_railscasts_json() {
let uniq = Uuid::new_v4(); let unique = Uuid::new_v4();
let joined = join("/tmp/rider-tests".to_owned(), uniq.to_string()); let joined = join("/tmp/rider-tests".to_owned(), unique.to_string());
remove_dir_all(joined.clone()).unwrap_or_else(|_| ()); remove_dir_all(joined.clone()).unwrap_or_else(|_| ());
create_dir_all(joined.clone()).unwrap(); create_dir_all(joined.clone()).unwrap();
@ -168,7 +188,10 @@ mod tests {
!exists(&joined, "rider/themes/railscasts.json"), !exists(&joined, "rider/themes/railscasts.json"),
"railscasts theme should not exists before run generator" "railscasts theme should not exists before run generator"
); );
debug_assert!(main().is_ok(), "generator should not failed"); debug_assert!(
run_generator(Some(joined.to_owned()), Some(joined.to_owned())).is_ok(),
"generator should not failed"
);
debug_assert!( debug_assert!(
exists(&joined, "rider/themes/railscasts.json"), exists(&joined, "rider/themes/railscasts.json"),
"railscasts theme should exists after run generator" "railscasts theme should exists after run generator"