diff --git a/Cargo.lock b/Cargo.lock index 6c6be30..3bddbb3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -91,6 +91,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b97f376d85a664d5837dbae44bf546e6477a679ff6610010f17276f686d867e8" dependencies = [ "clap_builder", + "clap_derive", ] [[package]] @@ -105,6 +106,18 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_derive" +version = "4.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "clap_lex" version = "0.7.2" @@ -230,6 +243,12 @@ version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb" +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + [[package]] name = "indexmap" version = "2.6.0" diff --git a/Cargo.toml b/Cargo.toml index 434b508..e00309a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,12 +7,13 @@ authors = [ "Nicolas ", ] edition = "2021" +description = "A tiny version of ls command" [dependencies] anyhow = "1.0" bytes = "1.3" +clap = { version = "4.5.20", features = ["derive"] } thiserror = "1.0" -clap = "4.5.20" [dev-dependencies] rstest = "0.23.0" @@ -25,4 +26,5 @@ stage0 = [] stage1 = [] stage2 = [] stage3 = [] +stage4 = [] stage5 = [] diff --git a/tests/stage4.rs b/tests/stage4.rs new file mode 100644 index 0000000..ea30c4c --- /dev/null +++ b/tests/stage4.rs @@ -0,0 +1,38 @@ +#![cfg(feature = "stage4")] + +mod helpers; + +use helpers::{split_ls_column_output, split_ls_output_by_newline}; +use rstest::rstest; +use std::process::Command; + +const EXPECTED_HELP_TEXT: &str = r#"A tiny version of ls command + +Usage: oxidar-ls [OPTIONS] + +Arguments: + Path to list + +Options: + -a, --all Show hidden files + -F, --format Format file names. Appendds a symbol at the end indicating the type of file. Slash ('/') is for directories and at sign ('@') is for symbolic links + -l, --list Show the files in a list + -h, --human Show the file size in a human-redable format + --help +"#; + +#[rstest] +#[case::arguments_help(&["--help"])] +fn test_stage_4(#[case] ls_arguments: &[&'static str]) { + let output = Command::new("./target/debug/oxidar-ls") + .args([ls_arguments, &["./test_dir"]].concat()) + .output() + .expect("failed to execute process"); + + assert!(output.status.success()); + + assert_eq!( + EXPECTED_HELP_TEXT, + std::str::from_utf8(&output.stdout).unwrap() + ); +} diff --git a/tests/stage5.rs b/tests/stage5.rs index 84c0b36..a017b71 100644 --- a/tests/stage5.rs +++ b/tests/stage5.rs @@ -11,6 +11,7 @@ use std::process::Command; #[case::arguments_lF(&["-l", "-F"])] #[case::arguments_lFh(&["-l", "-F", "-h"])] #[case::arguments_lFha(&["-l", "-F", "-h", "-a"])] +#[case::arguments_lFha(&["-lFha"])] // This tests tha clap was introduced and works as expected fn test_stage_5(#[case] ls_arguments: &[&'static str]) { let output = Command::new("./target/debug/oxidar-ls") .args([ls_arguments, &["./test_dir"]].concat())