Skip to content

Commit

Permalink
wrote some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LowPolyCat1 committed Jan 2, 2025
1 parent 065d7d8 commit 49482c1
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ thiserror = { version = "2.0.9" }
[build-dependencies]
windows_exe_info = "0.4.2"


[dev-dependencies]
tempfile = "3.2.0"


[profile.release]
lto = true
codegen-units = 1
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::{

use dirs;

fn get_download_dir() -> Result<PathBuf, errors::custom_errors::CustomError> {
pub fn get_download_dir() -> Result<PathBuf, errors::custom_errors::CustomError> {
match dirs::download_dir() {
Some(pathbuf) => {
tracing::info!("Download directory found: {:?}", pathbuf);
Expand All @@ -25,7 +25,7 @@ fn get_download_dir() -> Result<PathBuf, errors::custom_errors::CustomError> {
}
}

fn get_content(download_dir: &Path) -> Result<fs::ReadDir, errors::custom_errors::CustomError> {
pub fn get_content(download_dir: &Path) -> Result<fs::ReadDir, errors::custom_errors::CustomError> {
match fs::read_dir(download_dir) {
Ok(iterator) => {
tracing::info!("Download directory read successfully");
Expand Down
32 changes: 32 additions & 0 deletions src/tests/custom_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
use std::fs::{self, File};
use std::io::Write;
use tempfile;

use crate::{get_content, get_download_dir, run_sorting};

#[test]
fn test_get_download_dir() {
let result = get_download_dir();
assert!(result.is_ok());
}

#[test]
fn test_get_content() {
let temp_dir = tempfile::tempdir().unwrap();
let temp_path = temp_dir.path().to_path_buf();
File::create(temp_path.join("testfile.txt")).unwrap();

let result = get_content(&temp_path);
assert!(result.is_ok());
}

#[test]
fn test_run_sorting() {
let temp_dir = tempfile::tempdir().unwrap();
let temp_path = temp_dir.path().to_path_buf();
let mut file = File::create(temp_path.join("testfile.txt")).unwrap();
writeln!(file, "Test content").unwrap();

let result = run_sorting();
assert!(result.is_ok());
}
2 changes: 1 addition & 1 deletion src/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub mod tests;
pub mod custom_tests;
Empty file removed src/tests/tests.rs
Empty file.

0 comments on commit 49482c1

Please sign in to comment.