From 565f65c787abeeebb21510ef0a8079bfaa8e5650 Mon Sep 17 00:00:00 2001
From: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Date: Sat, 27 Jul 2024 15:43:01 +0200
Subject: [PATCH 1/2] rev: add some tests

---
 tests/by-util/test_rev.rs | 59 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/tests/by-util/test_rev.rs b/tests/by-util/test_rev.rs
index ac8f594..b1ad67a 100644
--- a/tests/by-util/test_rev.rs
+++ b/tests/by-util/test_rev.rs
@@ -9,3 +9,62 @@ use crate::common::util::TestScenario;
 fn test_invalid_arg() {
     new_ucmd!().arg("--definitely-invalid").fails().code_is(1);
 }
+
+#[test]
+fn test_piped_in_data() {
+    new_ucmd!().pipe_in("a test").succeeds().stdout_is("tset a");
+}
+
+#[test]
+fn test_existing_file() {
+    let (at, mut ucmd) = at_and_ucmd!();
+
+    at.write("a.txt", "line A\nline B");
+
+    ucmd.arg("a.txt").succeeds().stdout_is("A enil\nB enil");
+}
+
+#[test]
+fn test_multiple_files() {
+    let (at, mut ucmd) = at_and_ucmd!();
+
+    at.write("a.txt", "file A\n");
+    at.write("b.txt", "file B\n");
+
+    ucmd.args(&["a.txt", "b.txt"])
+        .succeeds()
+        .stdout_is("A elif\nB elif\n");
+}
+
+#[test]
+fn test_empty_file() {
+    let (at, mut ucmd) = at_and_ucmd!();
+
+    at.touch("empty.txt");
+
+    ucmd.arg("empty.txt").succeeds().no_output();
+}
+
+#[test]
+fn test_non_existing_file() {
+    new_ucmd!()
+        .arg("non_existing_file")
+        .fails()
+        .code_is(1)
+        .no_stdout()
+        .stderr_contains("cannot open non_existing_file: No such file or directory");
+}
+
+#[test]
+fn test_non_existing_and_existing_file() {
+    let (at, mut ucmd) = at_and_ucmd!();
+
+    at.write("a.txt", "file A");
+
+    ucmd.arg("non_existing_file")
+        .arg("a.txt")
+        .fails()
+        .code_is(1)
+        .stderr_contains("cannot open non_existing_file: No such file or directory")
+        .stdout_is("A elif");
+}

From 04ccbe32aba3c65c388775412ec2a6256f08cd93 Mon Sep 17 00:00:00 2001
From: Daniel Hofstetter <daniel.hofstetter@42dh.com>
Date: Sat, 27 Jul 2024 16:09:11 +0200
Subject: [PATCH 2/2] rev: adapt error msg, replace match with let/else

---
 src/uu/rev/src/rev.rs | 13 +++++--------
 1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/src/uu/rev/src/rev.rs b/src/uu/rev/src/rev.rs
index 75e56fe..db1a907 100644
--- a/src/uu/rev/src/rev.rs
+++ b/src/uu/rev/src/rev.rs
@@ -20,17 +20,14 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> {
     match files {
         Some(files) => {
             for path in files {
-                let file = match std::fs::File::open(path) {
-                    Ok(val) => val,
-                    Err(err) => {
-                        uucore::error::set_exit_code(1);
-                        uucore::show_error!("cannot open {}: {}", path, err);
-                        continue;
-                    }
+                let Ok(file) = std::fs::File::open(path) else {
+                    uucore::error::set_exit_code(1);
+                    uucore::show_error!("cannot open {path}: No such file or directory");
+                    continue;
                 };
                 if let Err(err) = rev_stream(file) {
                     uucore::error::set_exit_code(1);
-                    uucore::show_error!("cannot read {}: {}", path, err);
+                    uucore::show_error!("cannot read {path}: {err}");
                 }
             }
         }