Skip to content

Commit

Permalink
Added tests for the command line application.
Browse files Browse the repository at this point in the history
  • Loading branch information
awinterstein committed Jan 13, 2025
1 parent b97e441 commit 73bf74c
Show file tree
Hide file tree
Showing 3 changed files with 205 additions and 0 deletions.
186 changes: 186 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions net_income_germany_cmd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,7 @@ edition = "2021"
[dependencies]
clap = { version = "4.5.4", features = ["deprecated", "derive"] }
net-income-germany = { path = "../net_income_germany" }

[dev-dependencies]
assert_cmd = "2.0.14"
predicates = "3.1.0"
15 changes: 15 additions & 0 deletions net_income_germany_cmd/tests/cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use assert_cmd::prelude::*; // Add methods on commands
use predicates::prelude::*; // Used for writing assertions
use std::process::Command; // Run programs

#[test]
fn calculate_for_current_year() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("net-income-germany-cmd")?;

cmd.arg("--income").arg("80000");
cmd.assert()
.success()
.stdout(predicate::str::contains(" 48173,"));

Ok(())
}

0 comments on commit 73bf74c

Please sign in to comment.