Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
qarmin committed Oct 7, 2024
1 parent b4d4cc7 commit c9b58e4
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 20 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/linux_cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ jobs:
name: czkawka_cli-${{ runner.os }}
path: target/release/czkawka_cli

- name: Build test version
run: cargo build --profile test --bin czkawka_cli

- name: Linux Regression Test
run: |
wget https://github.com/qarmin/czkawka/releases/download/6.0.0/TestFiles.zip
Expand Down
7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ overflow-checks = true

# Optimize all dependencies except application/workspaces, even in debug builds
[profile.dev.package."*"]
opt-level = 3
opt-level = 3

[profile.test]
debug-assertions = true # Forces to crash when there is duplicated item in cli
overflow-checks = true
opt-level = 3
5 changes: 5 additions & 0 deletions ci_tester/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ edition = "2021"

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


[profile.release]
debug-assertions = true
overflow-checks = true

[dependencies]
state = "0.6.0"
handsome_logger = "0.8.0"
Expand Down
12 changes: 12 additions & 0 deletions ci_tester/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,24 @@ static COLLECTED_FILES: state::InitCell<CollectedFiles> = state::InitCell::new()
const ATTEMPTS: u32 = 10;
const PRINT_MESSAGES_CZKAWKA: bool = true;

fn test_args() {
let modes = ["dup", "big", "empty-folders", "empty-files", "temp", "image", "symlinks", "broken", "ext", "video", "music"];
for mode in modes {
let _ = fs::remove_dir_all("RandomDirWithoutContent");
fs::create_dir_all("RandomDirWithoutContent").expect("Should not fail in tests");
run_with_good_status(&[CZKAWKA_PATH.get().as_str(), mode, "-d", "RandomDirWithoutContent"], false);
}
}

// App runs - ./ci_tester PATH_TO_CZKAWKA
fn main() {
handsome_logger::init().expect("Should not fail in tests");
let args: Vec<String> = std::env::args().collect();
let path_to_czkawka = args[1].clone();
CZKAWKA_PATH.set(path_to_czkawka);

test_args();

remove_test_dir();
run_with_good_status(&["ls"], false);
unzip_files();
Expand Down
21 changes: 20 additions & 1 deletion czkawka_cli/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ pub enum Commands {
pub struct DuplicatesArgs {
#[clap(flatten)]
pub common_cli_items: CommonCliItems,
#[clap(flatten)]
pub referenced_folder: ReferencedFolder,
#[clap(
short = 'p',
long,
Expand Down Expand Up @@ -198,6 +200,8 @@ pub struct TemporaryArgs {
pub struct SimilarImagesArgs {
#[clap(flatten)]
pub common_cli_items: CommonCliItems,
#[clap(flatten)]
pub referenced_folder: ReferencedFolder,
#[clap(
short,
long,
Expand Down Expand Up @@ -264,6 +268,8 @@ pub struct SameMusicArgs {
#[clap(flatten)]
pub common_cli_items: CommonCliItems,
#[clap(flatten)]
pub referenced_folder: ReferencedFolder,
#[clap(flatten)]
pub delete_method: DMethod,
#[clap(flatten)]
pub dry_run: DryRun,
Expand Down Expand Up @@ -386,6 +392,8 @@ pub struct SimilarVideosArgs {
#[clap(flatten)]
pub common_cli_items: CommonCliItems,
#[clap(flatten)]
pub referenced_folder: ReferencedFolder,
#[clap(flatten)]
pub delete_method: DMethod,
#[clap(flatten)]
pub allow_hard_links: AllowHardLinks,
Expand Down Expand Up @@ -437,7 +445,7 @@ pub struct CommonCliItems {
long,
required = true,
help = "Directorie(s) to search",
long_help = "List of directorie(s) which will be searched(absolute path)"
long_help = "List of directorie(s) which will be searched(absolute path) - this directories are not set as reference folders"
)]
pub directories: Vec<PathBuf>,
#[clap(
Expand Down Expand Up @@ -495,6 +503,17 @@ pub struct FileToSave {
pub file_to_save: Option<PathBuf>,
}

#[derive(Debug, clap::Args)]
pub struct ReferencedFolder {
#[clap(
short,
long,
help = "Reference directorie(s) to search",
long_help = "List of directorie(s) which will be searched(absolute path) - this directories are set as reference folders, so will not be visible in the results"
)]
pub reference_folders: Vec<PathBuf>,
}

#[derive(Debug, clap::Args)]
pub struct JsonCompactFileToSave {
#[clap(short = 'C', long, value_name = "json-file-name", help = "Saves the results into the compact json file")]
Expand Down
35 changes: 23 additions & 12 deletions czkawka_cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(clippy::needless_late_init)]
#![warn(clippy::unwrap_used)]

use std::path::PathBuf;
use std::thread;

use clap::Parser;
Expand Down Expand Up @@ -79,6 +80,7 @@ fn main() {
fn duplicates(duplicates: DuplicatesArgs, stop_receiver: &Receiver<()>, progress_sender: &Sender<ProgressData>) {
let DuplicatesArgs {
common_cli_items,
referenced_folder,
minimal_file_size,
maximal_file_size,
minimal_cached_file_size,
Expand All @@ -103,7 +105,7 @@ fn duplicates(duplicates: DuplicatesArgs, stop_receiver: &Receiver<()>, progress
);
let mut item = DuplicateFinder::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, Some(referenced_folder.reference_folders.as_ref()));
item.set_minimal_file_size(minimal_file_size);
item.set_maximal_file_size(maximal_file_size);
item.set_delete_method(delete_method.delete_method);
Expand All @@ -119,7 +121,7 @@ fn empty_folders(empty_folders: EmptyFoldersArgs, stop_receiver: &Receiver<()>,

let mut item = EmptyFolder::new();

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_folders {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -141,7 +143,7 @@ fn biggest_files(biggest_files: BiggestFilesArgs, stop_receiver: &Receiver<()>,
let params = BigFileParameters::new(number_of_files, big_files_mode);
let mut item = BigFile::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -156,7 +158,7 @@ fn empty_files(empty_files: EmptyFilesArgs, stop_receiver: &Receiver<()>, progre

let mut item = EmptyFiles::new();

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -171,7 +173,7 @@ fn temporary(temporary: TemporaryArgs, stop_receiver: &Receiver<()>, progress_se

let mut item = Temporary::new();

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -184,6 +186,7 @@ fn temporary(temporary: TemporaryArgs, stop_receiver: &Receiver<()>, progress_se
fn similar_images(similar_images: SimilarImagesArgs, stop_receiver: &Receiver<()>, progress_sender: &Sender<ProgressData>) {
let SimilarImagesArgs {
common_cli_items,
referenced_folder,
minimal_file_size,
maximal_file_size,
similarity_preset,
Expand All @@ -207,7 +210,7 @@ fn similar_images(similar_images: SimilarImagesArgs, stop_receiver: &Receiver<()
);
let mut item = SimilarImages::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, Some(referenced_folder.reference_folders.as_ref()));
item.set_minimal_file_size(minimal_file_size);
item.set_maximal_file_size(maximal_file_size);
item.set_delete_method(delete_method.delete_method);
Expand All @@ -221,6 +224,7 @@ fn similar_images(similar_images: SimilarImagesArgs, stop_receiver: &Receiver<()
fn same_music(same_music: SameMusicArgs, stop_receiver: &Receiver<()>, progress_sender: &Sender<ProgressData>) {
let SameMusicArgs {
common_cli_items,
referenced_folder,
delete_method,
minimal_file_size,
maximal_file_size,
Expand All @@ -243,7 +247,7 @@ fn same_music(same_music: SameMusicArgs, stop_receiver: &Receiver<()>, progress_
);
let mut item = SameMusic::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, Some(referenced_folder.reference_folders.as_ref()));
item.set_minimal_file_size(minimal_file_size);
item.set_maximal_file_size(maximal_file_size);
item.set_delete_method(delete_method.delete_method);
Expand All @@ -259,7 +263,7 @@ fn invalid_symlinks(invalid_symlinks: InvalidSymlinksArgs, stop_receiver: &Recei

let mut item = InvalidSymlinks::new();

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -283,7 +287,7 @@ fn broken_files(broken_files: BrokenFilesArgs, stop_receiver: &Receiver<()>, pro
let params = BrokenFilesParameters::new(checked_type);
let mut item = BrokenFiles::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);
if delete_files {
item.set_delete_method(DeleteMethod::Delete);
}
Expand All @@ -295,6 +299,7 @@ fn broken_files(broken_files: BrokenFilesArgs, stop_receiver: &Receiver<()>, pro

fn similar_videos(similar_videos: SimilarVideosArgs, stop_receiver: &Receiver<()>, progress_sender: &Sender<ProgressData>) {
let SimilarVideosArgs {
referenced_folder,
common_cli_items,
tolerance,
minimal_file_size,
Expand All @@ -308,7 +313,7 @@ fn similar_videos(similar_videos: SimilarVideosArgs, stop_receiver: &Receiver<()
let params = SimilarVideosParameters::new(tolerance, ignore_same_size.ignore_same_size, !allow_hard_links.allow_hard_links);
let mut item = SimilarVideos::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, Some(referenced_folder.reference_folders.as_ref()));
item.set_minimal_file_size(minimal_file_size);
item.set_maximal_file_size(maximal_file_size);
item.set_delete_method(delete_method.delete_method);
Expand All @@ -325,7 +330,7 @@ fn bad_extensions(bad_extensions: BadExtensionsArgs, stop_receiver: &Receiver<()
let params = BadExtensionsParameters::new();
let mut item = BadExtensions::new(params);

set_common_settings(&mut item, &common_cli_items);
set_common_settings(&mut item, &common_cli_items, None);

item.find_bad_extensions_files(Some(stop_receiver), Some(progress_sender));

Expand Down Expand Up @@ -354,12 +359,18 @@ fn save_and_print_results<T: CommonData + PrintResults>(component: &mut T, commo
component.get_text_messages().print_messages();
}

fn set_common_settings<T>(component: &mut T, common_cli_items: &CommonCliItems)
fn set_common_settings<T>(component: &mut T, common_cli_items: &CommonCliItems, referenced_folders: Option<&Vec<PathBuf>>)
where
T: CommonData + PrintResults,
{
set_number_of_threads(common_cli_items.thread_number);

let mut included_directories = common_cli_items.directories.clone();
if let Some(referenced_folders) = referenced_folders {
included_directories.extend_from_slice(referenced_folders);
component.set_reference_directory(referenced_folders.clone());
}

component.set_included_directory(common_cli_items.directories.clone());
component.set_excluded_directory(common_cli_items.excluded_directories.clone());
component.set_excluded_items(common_cli_items.excluded_items.clone());
Expand Down
2 changes: 1 addition & 1 deletion czkawka_core/src/common_directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl Directories {
// Try to canonicalize them
if cfg!(windows) {
// Only canonicalize if it's not a network path
// This can be check by checking if path starts with \\?\UNC\
// This can be done by checking if path starts with \\?\UNC\
if let Ok(dir_can) = directory.canonicalize() {
let dir_can_str = dir_can.to_string_lossy().to_string();
if let Some(dir_can_str) = dir_can_str.strip_prefix(r"\\?\") {
Expand Down
2 changes: 1 addition & 1 deletion czkawka_core/src/same_music.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ impl SameMusic {
}
})
.while_some()
.filter_map(|e| e)
.flatten()
.collect::<Vec<_>>();
debug!("read_tags - ended reading tags");

Expand Down
8 changes: 4 additions & 4 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ krokiet_r:
krokiet_dark:
RUST_BACKTRACE=1 SLINT_STYLE=fluent-dark cargo run --bin krokiet

cli:
RUST_BACKTRACE=1 cargo run --bin czkawka_cli
cli_r:
RUST_BACKTRACE=1 cargo run --bin czkawka_cli --release
cli +args:
RUST_BACKTRACE=1 cargo run --bin czkawka_cli -- {{args}}
cli_r args:
RUST_BACKTRACE=1 cargo run --bin czkawka_cli --release -- {{args}}
cli_help:
cargo run --bin czkawka_cli -- --help

Expand Down

0 comments on commit c9b58e4

Please sign in to comment.