Skip to main content

Merge pull request #41 from alexwlchan/test-version

ID
d0b8a83
date
2024-06-17 19:37:41+00:00
author
Alex Chan <alex@alexwlchan.net>
parents
9f32e5e, a58de6e
message
Merge pull request #41 from alexwlchan/test-version

Add a test for the `--version` flag
changed files
3 files, 47 additions

Changed files

Cargo.lock (16805) → Cargo.lock (17574)

diff --git a/Cargo.lock b/Cargo.lock
index b2f1f60..e77faf7 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -9,6 +9,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
 
 [[package]]
+name = "aho-corasick"
+version = "1.1.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
 name = "anstream"
 version = "0.6.14"
 source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -203,6 +212,7 @@ dependencies = [
  "image",
  "kmeans_colors",
  "palette",
+ "regex",
 ]
 
 [[package]]
@@ -441,10 +451,33 @@ dependencies = [
 ]
 
 [[package]]
+name = "regex"
+version = "1.10.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-automata",
+ "regex-syntax",
+]
+
+[[package]]
 name = "regex-automata"
 version = "0.4.6"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.8.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b"
 
 [[package]]
 name = "serde"

Cargo.toml (424) → Cargo.toml (441)

diff --git a/Cargo.toml b/Cargo.toml
index 5578e1d..334e5bc 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -6,6 +6,7 @@ edition = "2018"
 [dependencies]
 assert_cmd = "2.0.14"
 clap = "4.5.7"
+regex = "1.10.5"
 
 [dependencies.kmeans_colors]
 version = "0.6.0"

src/main.rs (8026) → src/main.rs (8365)

diff --git a/src/main.rs b/src/main.rs
index 705a627..3031a60 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -48,6 +48,7 @@ mod tests {
 
     use assert_cmd::assert::OutputAssertExt;
     use assert_cmd::Command;
+    use regex::Regex;
 
     // Note: for the purposes of these tests, I mostly trust the k-means code
     // provided by the external library.
@@ -245,6 +246,18 @@ mod tests {
         assert_eq!(output.stdout, "#693900\n");
     }
 
+    #[test]
+    fn it_prints_the_version() {
+        let output = get_success(&["--version"]);
+
+        let re = Regex::new(r"^dominant_colours [0-9]+\.[0-9]+\.[0-9]+\n$").unwrap();
+
+        assert!(re.is_match(&output.stdout));
+
+        assert_eq!(output.exit_code, 0);
+        assert_eq!(output.stderr, "");
+    }
+
     struct DcOutput {
         exit_code: i32,
         stdout: String,