Skip to main content

Add a test for dealing with malformed images

ID
f8bc7e4
date
2022-05-05 06:41:36+00:00
author
Alex Chan <alex@alexwlchan.net>
parent
6f08e32
message
Add a test for dealing with malformed images
changed files
2 files, 10 additions

Changed files

src/main.rs (8732) → src/main.rs (9037)

diff --git a/src/main.rs b/src/main.rs
index bf7a924..17824d2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -254,6 +254,15 @@ mod tests {
         assert_eq!(output.stderr, "The image format Tiff is not supported\n");
     }
 
+    #[test]
+    fn it_fails_if_you_pass_a_malformed_image() {
+        let output = get_failure(&["./src/tests/malformed.txt.png"]);
+
+        assert_eq!(output.exit_code, 1);
+        assert_eq!(output.stdout, "");
+        assert_eq!(output.stderr, "Format error decoding Png: invalid signature\n");
+    }
+
     struct DcOutput {
         exit_code: i32,
         stdout: String,

src/tests/malformed.txt.png (0) → src/tests/malformed.txt.png (22)

diff --git a/src/tests/malformed.txt.png b/src/tests/malformed.txt.png
new file mode 100644
index 0000000..d6d2570
--- /dev/null
+++ b/src/tests/malformed.txt.png
@@ -0,0 +1 @@
+Ceci n'est pas une png
\ No newline at end of file