Repository: dotenv-linter/dotenv-linter
Pull request #398 (2021-03-21 02:23:31)

Print a message "Nothing to compare" (#398)
<!--
Thank you for your pull request. Please provide a description above and review
the requirements below.

Bug fixes and new features should include tests.
-->

<!-- _Please make sure to review and check all of these items:_ -->

#### ✔ Checklist:
<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

- [x] Commit messages have been written in [Conventional Commits](https://www.conventionalcommits.org) format;
- [x] This PR has been added to [CHANGELOG.md](https://github.com/dotenv-linter/dotenv-linter/blob/master/CHANGELOG.md) (at the top of the list);
- [x] Tests for the changes have been added (for bug fixes / features);
- [ ] Docs have been added / updated on the [dotenv-linter.github.io](https://github.com/dotenv-linter/dotenv-linter.github.io) (for bug fixes / features).

<!-- _NOTE: these things are not required to open a PR and can be done afterwards / while the PR is open._ -->


codecov-io: # [Codecov](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398?src=pr&el=h1) Report
> Merging [#398](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398?src=pr&el=desc) (1d340b4) into [master](https://codecov.io/gh/dotenv-linter/dotenv-linter/commit/492d3a4046fd97cdfbeb7484e430375683a06a2f?el=desc) (492d3a4) will **increase** coverage by `0.01%`.
> The diff coverage is `100.00%`.

[![Impacted file tree graph](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398/graphs/tree.svg?width=650&height=150&src=pr&token=wQybePfHI1)](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #398      +/-   ##
==========================================
+ Coverage   95.32%   95.34%   +0.01%     
==========================================
  Files          37       37              
  Lines        2376     2382       +6     
==========================================
+ Hits         2265     2271       +6     
  Misses        111      111              
```


| [Impacted Files](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [src/common/output/compare.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398/diff?src=pr&el=tree#diff-c3JjL2NvbW1vbi9vdXRwdXQvY29tcGFyZS5ycw==) | `100.00% <100.00%> (ø)` | |
| [src/lib.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398/diff?src=pr&el=tree#diff-c3JjL2xpYi5ycw==) | `87.96% <100.00%> (+0.18%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398?src=pr&el=footer). Last update [492d3a4...1d340b4](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/398?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

mgrachev: @jakecorrenti Please update your branch from the master branch.

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a841027..ca82a51 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,7 @@ # Changelog
 
 ## [Unreleased]
 ### 🚀 Added
+- Print a message "Nothing to compare" [#398](https://github.com/dotenv-linter/dotenv-linter/pull/398) ([@jakecorrenti](https://github.com/jakecorrenti))
 - Add action-hadolint [#400](https://github.com/dotenv-linter/dotenv-linter/pull/400) ([@iovanom](https://github.com/iovanom))
 - Add method to get substitution keys to LineEntry [#391](https://github.com/dotenv-linter/dotenv-linter/pull/391) ([@zotho](https://github.com/zotho))
 - Added a Fix Benchmark [#399](https://github.com/dotenv-linter/dotenv-linter/pull/399) ([@a4blue](https://github.com/a4blue))
diff --git a/src/common/output/compare.rs b/src/common/output/compare.rs
index 137f197..dd45c29 100644
--- a/src/common/output/compare.rs
+++ b/src/common/output/compare.rs
@@ -21,4 +21,11 @@ pub fn print_processing_info(&self, file: &FileEntry) {
     pub fn print_warnings(&self, warnings: &[CompareWarning]) {
         warnings.iter().for_each(|w| println!("{}", w))
     }
+
+    /// Prints 'Nothing to compare' in the absence of '.env' files for compare
+    pub fn print_nothing_to_compare(&self) {
+        if !self.is_quiet_mode {
+            println!("Nothing to compare");
+        }
+    }
 }
diff --git a/src/lib.rs b/src/lib.rs
index 69cdacc..0b7dec0 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -105,6 +105,7 @@ pub fn compare(
 
     // Nothing to check
     if lines_map.is_empty() {
+        output.print_nothing_to_compare();
         return Ok(warnings);
     }
 


Test patch:
diff --git a/tests/output/compare.rs b/tests/output/compare.rs
new file mode 100644
index 0000000..b02e909
--- /dev/null
+++ b/tests/output/compare.rs
@@ -0,0 +1,20 @@
+use crate::common::TestDir;
+
+#[test]
+fn files_non_existent() {
+    let test_dir = TestDir::new();
+    let expected_output = format!("Nothing to compare\n");
+    let output = test_dir.test_command_success_and_get_output(&["compare", ".env1", ".env2"]);
+
+    assert_eq!(output, expected_output);
+}
+
+#[test]
+fn files_non_existent_in_quiet_mode() {
+    let test_dir = TestDir::new();
+    let output =
+        test_dir.test_command_success_and_get_output(&["compare", "--quiet", ".env1", ".env2"]);
+    let unexpected_output = format!("Nothing to compare\n");
+
+    assert_ne!(output, unexpected_output);
+}
diff --git a/tests/output/mod.rs b/tests/output/mod.rs
index 7edb210..36f712d 100644
--- a/tests/output/mod.rs
+++ b/tests/output/mod.rs
@@ -1,2 +1,3 @@
 mod check;
+mod compare;
 mod fix;