Skip to content

Commit

Permalink
Merge pull request #20 from rust-lang-ar/stage4_tests
Browse files Browse the repository at this point in the history
added stage4 tests
  • Loading branch information
hernangonzalez authored Nov 4, 2024
2 parents f6409ed + fd38b9c commit 11356ba
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ authors = [
"Nicolas <nicolas.antinori.7@gmail.com>",
]
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"
Expand All @@ -25,4 +26,5 @@ stage0 = []
stage1 = []
stage2 = []
stage3 = []
stage4 = []
stage5 = []
38 changes: 38 additions & 0 deletions tests/stage4.rs
Original file line number Diff line number Diff line change
@@ -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] <PATH>
Arguments:
<PATH> 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()
);
}
1 change: 1 addition & 0 deletions tests/stage5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit 11356ba

Please sign in to comment.