Skip to content

Commit

Permalink
test(cli): Add test to make sure CLI flags are handled
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jan 8, 2024
1 parent 0065ca2 commit db4a253
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions tests/cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use assert_cmd::Command;

Check warning on line 1 in tests/cli.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `assert_cmd::Command`
use predicates::prelude::*;

Check warning on line 2 in tests/cli.rs

View workflow job for this annotation

GitHub Actions / test

unused import: `predicates::prelude::*`

#[cfg(feature = "cli")]
#[test]
Expand All @@ -13,3 +14,19 @@ fn main_stdin() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.write_stdin("foo").assert().success().stdout("Foo\n").stderr("");
}

#[cfg(feature = "cli")]
#[test]
fn main_help() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
cmd.args(["--help"]).assert().success().stdout(predicate::str::contains("Usage: ")).stderr("");
}

#[cfg(feature = "cli")]
#[test]
fn main_lang() {
let mut en_cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
en_cmd.args(["-l", "en", "ide"]).assert().success().stdout("Ide\n").stderr("");
let mut tr_cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
tr_cmd.args(["-l", "tr", "ilk"]).assert().success().stdout("İlk\n").stderr("");
}

0 comments on commit db4a253

Please sign in to comment.