From b1c86069186224f1ed7340be94ae42f58aec1433 Mon Sep 17 00:00:00 2001 From: sharkdp Date: Fri, 30 Oct 2020 19:32:45 +0100 Subject: [PATCH] Print warning on empty content closes #107 closes #108 --- src/lib.rs | 3 +++ tests/examples/empty | 0 tests/integration_tests.rs | 29 +++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tests/examples/empty diff --git a/src/lib.rs b/src/lib.rs index 2bdbdc3..b81f35a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -428,8 +428,10 @@ impl<'a, Writer: Write> Printer<'a, Writer> { // Finish last line self.print_textline().ok(); + if !self.header_was_printed() { self.header(); + writeln!(self.writer, "│ │ No content to print │ │ │ │").ok(); } self.footer(); @@ -459,6 +461,7 @@ mod tests { let input = io::empty(); let expected_string = "\ ┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐ +│ │ No content to print │ │ │ │ └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘ " .to_owned(); diff --git a/tests/examples/empty b/tests/examples/empty new file mode 100644 index 0000000..e69de29 diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index e8b9462..b7d642e 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -41,6 +41,35 @@ fn length_restricts_output_size() { ); } +#[test] +fn prints_warning_on_empty_content() { + hexyl() + .arg("empty") + .arg("--color=never") + .assert() + .success() + .stdout( + "┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\ + │ │ No content to print │ │ │ │\n\ + └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", + ); +} + +#[test] +fn prints_warning_when_skipping_past_the_end() { + hexyl() + .arg("ascii") + .arg("--color=never") + .arg("--skip=1000") + .assert() + .success() + .stdout( + "┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\ + │ │ No content to print │ │ │ │\n\ + └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", + ); +} + #[test] fn fail_if_length_and_bytes_options_are_used_simultaneously() { hexyl()