Skip to content

Commit

Permalink
feat: test main
Browse files Browse the repository at this point in the history
  • Loading branch information
Its-Just-Nans committed Jan 24, 2024
1 parent 12ad9d2 commit d80f96d
Show file tree
Hide file tree
Showing 4 changed files with 213 additions and 1 deletion.
171 changes: 171 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ serde_json = { version = "1.0", optional = true }
[features]
default = ["serde"]
serde = ["dep:serde", "dep:serde_json"]

[dev-dependencies]
assert_cmd = "2.0.13"
predicates = "3.1.0"
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,11 @@ pub fn print_output(
println!("{:?} -> {:?}", one_res.path, one_res.modified.unwrap());
}
}
println!("{} files checked", len);
if len == 1 {
println!("{} file checked", len);
} else {
println!("{} files checked", len);
}
} else if options.json.json {
#[cfg(feature = "serde")]
{
Expand Down
33 changes: 33 additions & 0 deletions tests/tests_main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#[cfg(test)]
mod tests {
use assert_cmd::prelude::*; // Add methods on commands
use predicates::prelude::*; // Used for writing assertions
use std::process::Command; // Run programs

#[test]
fn test_main_wrong_path() {
let mut cmd = Command::cargo_bin("notox").unwrap();

cmd.arg("READ ME.md");
cmd.assert().failure().stdout(predicate::str::contains(
" need to provide at least one valid",
));
}

#[test]
fn test_main_normal() {
let mut cmd = Command::cargo_bin("notox").unwrap();

cmd.arg("README.md");
cmd.assert()
.stdout(predicate::str::contains("1 file checked"));
}

#[test]
fn test_main_quiet() {
let mut cmd = Command::cargo_bin("notox").unwrap();

cmd.arg("README.md").arg("-q");
cmd.assert().stdout(predicate::str::is_empty());
}
}

0 comments on commit d80f96d

Please sign in to comment.