-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(libmake): ✅ Add new tests for
test_directory.rs
and refactorin…
…g others
- Loading branch information
1 parent
9d0375a
commit b0a5901
Showing
13 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/// The `test_ascii_macros` module contains tests for the ascii_macros module. | ||
pub mod test_ascii_macros; | ||
|
||
/// The `test_directory_macros` module contains tests for the directory_macros module. | ||
pub mod test_directory_macros; | ||
|
||
/// The `test_file_macros` module contains tests for the file_macros module. | ||
pub mod test_file_macros; | ||
|
||
/// The `test_generator_macros` module contains tests for the generator_macros module. | ||
pub mod test_generator_macros; | ||
|
||
/// The `test_log_macros` module contains tests for the log_macros module. | ||
pub mod test_log_macros; | ||
|
||
/// The `test_utility_macros` module contains tests for the utility_macros module. | ||
pub mod test_utility_macros; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// This module contains the tests for the `macros` module. | ||
pub mod macros; | ||
|
||
/// This module contains the tests for the `models` module. | ||
pub mod models; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/// The `test_error_ascii_art` module contains tests for the error_ascii_art module. | ||
pub mod test_error_ascii_art; | ||
|
||
/// The `test_model_params` module contains tests for the model_params module. | ||
pub mod test_model_params; |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/// The `test_directory.rs` module contains tests for the directory module. | ||
pub mod test_directory; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use libmake::utilities::directory::directory; | ||
use std::fs; | ||
use std::io::Error; | ||
use std::path::Path; | ||
use tempfile::tempdir; | ||
|
||
#[test] | ||
fn test_directory_exists() { | ||
let dir = tempdir().unwrap(); | ||
let path = dir.path().join("logs"); | ||
|
||
fs::create_dir(&path).unwrap(); | ||
let result = directory(&path, "logs"); | ||
assert!(result.is_ok()); | ||
assert_eq!(result.unwrap(), ""); | ||
} | ||
|
||
#[test] | ||
fn test_directory_create() { | ||
let dir = tempdir().unwrap(); | ||
let path = dir.path().join("logs"); | ||
|
||
let result = directory(&path, "logs"); | ||
assert!(result.is_ok()); | ||
assert_eq!(result.unwrap(), ""); | ||
assert!(path.exists()); | ||
} | ||
|
||
#[test] | ||
fn test_directory_not_a_directory() { | ||
let dir = tempdir().unwrap(); | ||
let file_path = dir.path().join("not_a_directory"); | ||
|
||
fs::File::create(&file_path).unwrap(); | ||
let result = directory(&file_path, "not_a_directory"); | ||
assert!(result.is_err()); | ||
assert_eq!(result.unwrap_err(), "❌ Error: not_a_directory is not a directory."); | ||
} | ||
|
||
#[test] | ||
fn test_move_output_directory() { | ||
let dir = tempdir().unwrap(); | ||
let out_dir = dir.path().join("out"); | ||
|
||
fs::create_dir(&out_dir).unwrap(); | ||
let result = move_output_directory("site_name", &out_dir); | ||
assert!(result.is_ok()); | ||
|
||
let public_dir = dir.path().join("public"); | ||
let new_project_dir = public_dir.join("site_name"); | ||
assert!(new_project_dir.exists()); | ||
} | ||
|
||
#[test] | ||
fn test_cleanup_directory() { | ||
let dir = tempdir().unwrap(); | ||
let cleanup_dir = dir.path().join("cleanup"); | ||
|
||
fs::create_dir(&cleanup_dir).unwrap(); | ||
let result = cleanup_directory(&[cleanup_dir.as_path()]); | ||
assert!(result.is_ok()); | ||
assert!(!cleanup_dir.exists()); | ||
} | ||
|
||
#[test] | ||
fn test_create_directory() { | ||
let dir = tempdir().unwrap(); | ||
let create_dir = dir.path().join("create"); | ||
|
||
let result = create_directory(&[create_dir.as_path()]); | ||
assert!(result.is_ok()); | ||
assert!(create_dir.exists()); | ||
} | ||
|
||
#[test] | ||
fn test_truncate_path() { | ||
let path = Path::new("/a/b/c/d/e"); | ||
|
||
let result = truncate(&path, 3); | ||
assert_eq!(result, Some("c/d/e".to_string())); | ||
|
||
let result = truncate(&path, 0); | ||
assert_eq!(result, None); | ||
|
||
let result = truncate(&path, 10); | ||
assert_eq!(result, None); | ||
} | ||
} |