Test that we return an error if the out-dir is a file
- ID
8591105- date
2024-08-20 12:11:36+00:00- author
Alex Chan <alex@alexwlchan.net>- parent
07d5d24- message
Test that we return an error if the out-dir is a file- changed files
2 files, 20 additions, 2 deletions
Changed files
README.md (218) → README.md (188)
diff --git a/README.md b/README.md
index a829860..482b66e 100644
--- a/README.md
+++ b/README.md
@@ -5,4 +5,3 @@ focusing on a small piece of code makes it better
* errors:
-> creates thumbnail directory
-> /dev/null
- -> thumbnail dir is file?
src/main.rs (6384) → src/main.rs (6958)
diff --git a/src/main.rs b/src/main.rs
index afda6e6..5e48558 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -129,12 +129,31 @@ mod test_cli {
assert_eq!(output.stdout, "");
}
+ // TODO: Improve this error message.
+ //
+ // It's good to know the tool won't completely break when this happens, but ideally
+ // we'd return a more meaningful error message in this case.
+ #[test]
+ fn it_fails_if_out_dir_is_a_file() {
+ let output = get_failure(&["src/images/noise.jpg", "--width=50", "--out-dir=README.md"]);
+
+ assert_eq!(output.exit_code, 1);
+ assert_eq!(
+ output.stderr,
+ "File exists (os error 17)\n"
+ );
+ assert_eq!(output.stdout, "");
+ }
+
#[test]
fn it_fails_if_you_try_to_overwrite_the_original_file() {
let output = get_failure(&["src/images/noise.jpg", "--width=50", "--out-dir=src/images"]);
assert_eq!(output.exit_code, 1);
- assert_eq!(output.stderr, "Cannot write thumbnail to the same directory as the original image\n");
+ assert_eq!(
+ output.stderr,
+ "Cannot write thumbnail to the same directory as the original image\n"
+ );
assert_eq!(output.stdout, "");
}