Add tests for passing the wrong combo of --width/--height tags
- ID
2ac60e6- date
2024-08-20 00:21:19+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
0065bc6- message
Add tests for passing the wrong combo of `--width`/`--height` tags- changed files
2 files, 40 additions, 2 deletions
Changed files
README.md (580) → README.md (527)
diff --git a/README.md b/README.md
index 0783c93..ba4d74d 100644
--- a/README.md
+++ b/README.md
@@ -3,8 +3,6 @@ create-thumbnail PATH [--width=WIDTH | --height=HEIGHT] --out-dir=OUT_DIR
focusing on a small piece of code makes it better
* CLI:
- -> width + height
- -> neither of width/height
-> width only
-> height only
src/main.rs (3826) → src/main.rs (5142)
diff --git a/src/main.rs b/src/main.rs
index b295e45..2a949ee 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -104,6 +104,35 @@ mod test_cli {
use regex::Regex;
#[test]
+ fn it_errors_if_you_pass_width_and_height() {
+ let output = get_failure(&[
+ "src/tests/red.png",
+ "--width=100",
+ "--height=100",
+ "--out-dir=/tmp",
+ ]);
+
+ let re =
+ Regex::new(r"the argument '--width <WIDTH>' cannot be used with '--height <HEIGHT>'")
+ .unwrap();
+ assert!(re.is_match(&output.stderr));
+
+ assert_eq!(output.exit_code, 2);
+ assert_eq!(output.stdout, "");
+ }
+
+ #[test]
+ fn it_errors_if_you_pass_neither_width_nor_height() {
+ let output = get_failure(&["src/tests/red.png", "--out-dir=/tmp"]);
+
+ let re = Regex::new(r"the following required arguments were not provided:").unwrap();
+ assert!(re.is_match(&output.stderr));
+
+ assert_eq!(output.exit_code, 2);
+ assert_eq!(output.stdout, "");
+ }
+
+ #[test]
fn it_prints_the_version() {
let output = get_success(&["--version"]);
@@ -149,4 +178,15 @@ mod test_cli {
stderr: str::from_utf8(&output.stderr).unwrap().to_owned(),
}
}
+
+ fn get_failure(args: &[&str]) -> DcOutput {
+ let mut cmd = Command::cargo_bin("create_thumbnail").unwrap();
+ let output = cmd.args(args).unwrap_err().as_output().unwrap().to_owned();
+
+ DcOutput {
+ exit_code: output.status.code().unwrap(),
+ stdout: str::from_utf8(&output.stdout).unwrap().to_owned(),
+ stderr: str::from_utf8(&output.stderr).unwrap().to_owned(),
+ }
+ }
}