Repository: dotenv-linter/dotenv-linter
Pull request #490 (2022-03-17 09:31:07)

test: add tests to verify cli application
<!--
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-commenter: # [Codecov](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter) Report
> Merging [#490](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter) (ba83985) into [master](https://codecov.io/gh/dotenv-linter/dotenv-linter/commit/61a19288b8493fdbae8c4aaa33b75f9bbb434981?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter) (61a1928) will **increase** coverage by `0.00%`.
> The diff coverage is `83.33%`.

```diff
@@           Coverage Diff           @@
##           master     #490   +/-   ##
=======================================
  Coverage   98.92%   98.92%           
=======================================
  Files          41       41           
  Lines        2698     2702    +4     
=======================================
+ Hits         2669     2673    +4     
  Misses         29       29           
```


| [Impacted Files](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter) | Coverage Δ | |
|---|---|---|
| [src/checks/duplicated\_key.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2NoZWNrcy9kdXBsaWNhdGVkX2tleS5ycw==) | `100.00% <ø> (ø)` | |
| [src/common/comment.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2NvbW1vbi9jb21tZW50LnJz) | `100.00% <ø> (ø)` | |
| [src/common/file\_entry.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2NvbW1vbi9maWxlX2VudHJ5LnJz) | `100.00% <ø> (ø)` | |
| [src/common/output/check.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2NvbW1vbi9vdXRwdXQvY2hlY2sucnM=) | `100.00% <ø> (ø)` | |
| [src/common/output/fix.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2NvbW1vbi9vdXRwdXQvZml4LnJz) | `87.87% <ø> (ø)` | |
| [src/common/warning.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2NvbW1vbi93YXJuaW5nLnJz) | `100.00% <ø> (ø)` | |
| [src/fixes/duplicated\_key.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2ZpeGVzL2R1cGxpY2F0ZWRfa2V5LnJz) | `100.00% <ø> (ø)` | |
| [src/fs\_utils.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2ZzX3V0aWxzLnJz) | `95.40% <0.00%> (ø)` | |
| [src/cli.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2NsaS5ycw==) | `100.00% <100.00%> (ø)` | |
| [src/lib.rs](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter#diff-c3JjL2xpYi5ycw==) | `98.99% <100.00%> (ø)` | |
| ... and [3 more](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490/diff?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter). Last update [61a1928...ba83985](https://codecov.io/gh/dotenv-linter/dotenv-linter/pull/490?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=dotenv-linter).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5345691..b542877 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,7 @@ ### 🚀 Added
 - Add dependabot [#472](https://github.com/dotenv-linter/dotenv-linter/pull/472) ([@mgrachev](https://github.com/mgrachev))
 
 ### 🔧 Changed
+- Add tests to verify CLI application [#490](https://github.com/dotenv-linter/dotenv-linter/pull/490) ([@mgrachev](https://github.com/mgrachev))
 - Move CLI commands to separate functions [#489](https://github.com/dotenv-linter/dotenv-linter/pull/489) ([@mgrachev](https://github.com/mgrachev))
 - Refactor check ci with all-targets arg [#488](https://github.com/dotenv-linter/dotenv-linter/pull/488) ([@shapurid](https://github.com/shapurid))
 - Refactor usage of fix and compare [#486](https://github.com/dotenv-linter/dotenv-linter/pull/486) ([@shapurid](https://github.com/shapurid))
diff --git a/Cargo.lock b/Cargo.lock
index cab2bc9..cb5e655 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -519,9 +519,9 @@ dependencies = [
 
 [[package]]
 name = "once_cell"
-version = "1.9.0"
+version = "1.10.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5"
+checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
 
 [[package]]
 name = "oorandom"
diff --git a/rust-toolchain.toml b/rust-toolchain.toml
new file mode 100644
index 0000000..7bdffcd
--- /dev/null
+++ b/rust-toolchain.toml
@@ -0,0 +1,3 @@
+[toolchain]
+channel = "1.59.0"
+components = ["rustfmt", "clippy"]
diff --git a/src/checks/duplicated_key.rs b/src/checks/duplicated_key.rs
index c41f8e2..43db204 100644
--- a/src/checks/duplicated_key.rs
+++ b/src/checks/duplicated_key.rs
@@ -1,7 +1,6 @@
-use std::collections::HashSet;
-
 use super::Check;
 use crate::common::{LineEntry, LintKind, Warning};
+use std::collections::HashSet;
 
 pub(crate) struct DuplicatedKeyChecker<'a> {
     template: &'a str,
diff --git a/src/cli.rs b/src/cli.rs
index 77c0d6f..8deece3 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -102,3 +102,15 @@ fn not_check_updates_flag<'a>() -> Arg<'a> {
         .long("not-check-updates")
         .help("Doesn't check for updates")
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+    use std::env;
+
+    #[test]
+    fn verify_app() {
+        let current_dir = env::current_dir().expect("Failed to get current dir");
+        new(current_dir.as_os_str()).debug_assert();
+    }
+}
diff --git a/src/common/comment.rs b/src/common/comment.rs
index f2d461f..7d34aa6 100644
--- a/src/common/comment.rs
+++ b/src/common/comment.rs
@@ -1,6 +1,5 @@
-use std::str::FromStr;
-
 use super::LintKind;
+use std::str::FromStr;
 
 const PREFIX: &str = "dotenv-linter";
 const ON: &str = "on";
diff --git a/src/common/file_entry.rs b/src/common/file_entry.rs
index 9a5036b..1f92fbf 100644
--- a/src/common/file_entry.rs
+++ b/src/common/file_entry.rs
@@ -1,8 +1,7 @@
+use super::LF;
 use std::path::{Path, PathBuf};
 use std::{fmt, fs};
 
-use super::LF;
-
 const EXCLUDED_FILES: &[&str] = &[".envrc"];
 
 #[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
diff --git a/src/common/output/check.rs b/src/common/output/check.rs
index 607e216..28a38e4 100644
--- a/src/common/output/check.rs
+++ b/src/common/output/check.rs
@@ -1,6 +1,5 @@
-use colored::*;
-
 use crate::common::{FileEntry, Warning};
+use colored::*;
 
 pub struct CheckOutput {
     // Quiet program output mode
diff --git a/src/common/output/fix.rs b/src/common/output/fix.rs
index 04d9562..713d4b2 100644
--- a/src/common/output/fix.rs
+++ b/src/common/output/fix.rs
@@ -1,8 +1,7 @@
+use crate::common::{FileEntry, Warning};
 use colored::*;
 use std::path::Path;
 
-use crate::common::{FileEntry, Warning};
-
 /// Prefix for the backup output
 const BACKUP_PREFIX: &str = "Original file was backed up to: ";
 
diff --git a/src/common/warning.rs b/src/common/warning.rs
index b7a4a2b..63a39fe 100644
--- a/src/common/warning.rs
+++ b/src/common/warning.rs
@@ -1,8 +1,7 @@
+use super::LintKind;
 use colored::*;
 use std::fmt;
 
-use super::LintKind;
-
 #[derive(Clone, Debug, PartialEq)]
 pub struct Warning {
     pub check_name: LintKind,
diff --git a/src/fixes/duplicated_key.rs b/src/fixes/duplicated_key.rs
index fb748a7..30793f1 100644
--- a/src/fixes/duplicated_key.rs
+++ b/src/fixes/duplicated_key.rs
@@ -1,7 +1,6 @@
-use std::collections::HashSet;
-
 use super::Fix;
 use crate::common::{LineEntry, LintKind};
+use std::collections::HashSet;
 
 #[derive(Default)]
 pub(crate) struct DuplicatedKeyFixer {}
diff --git a/src/fs_utils.rs b/src/fs_utils.rs
index 3cf2d27..be1a8c0 100644
--- a/src/fs_utils.rs
+++ b/src/fs_utils.rs
@@ -1,10 +1,13 @@
-use std::fs::{copy, File};
-use std::io::{self, Write};
-use std::path::{Path, PathBuf};
-use std::time::SystemTime;
-
-use crate::common::{FileEntry, LineEntry};
-use crate::Result;
+use crate::{
+    common::{FileEntry, LineEntry},
+    Result,
+};
+use std::{
+    fs::{copy, File},
+    io::{self, Write},
+    path::{Path, PathBuf},
+    time::SystemTime,
+};
 
 /// For the Windows platform, we need to remove the UNC prefix.
 #[cfg(windows)]
diff --git a/src/lib.rs b/src/lib.rs
index 8febf37..0d1de8b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,10 +1,11 @@
-use crate::common::*;
-use crate::quote_type::QuoteType;
+use crate::{common::*, quote_type::QuoteType};
 use clap::Values;
 use colored::*;
-use std::collections::{BTreeMap, HashSet};
-use std::path::{Path, PathBuf};
-use std::str::FromStr;
+use std::{
+    collections::{BTreeMap, HashSet},
+    path::{Path, PathBuf},
+    str::FromStr,
+};
 use update_informer::{registry::Crates, Check};
 
 pub use checks::available_check_names;


Test patch:
diff --git a/tests/flags/mod.rs b/tests/flags/mod.rs
index 953813d..95bdfaf 100644
--- a/tests/flags/mod.rs
+++ b/tests/flags/mod.rs
@@ -1,6 +1,7 @@
 mod backup;
 mod quiet;
 mod recursive;
+mod version;
 
 #[cfg(feature = "stub_check_version")]
 mod check_updates;
diff --git a/tests/flags/version.rs b/tests/flags/version.rs
new file mode 100644
index 0000000..609b90e
--- /dev/null
+++ b/tests/flags/version.rs
@@ -0,0 +1,9 @@
+use crate::common::TestDir;
+
+#[test]
+fn short_version() {
+    let testdir = TestDir::new();
+    let expected = format!("{} {}\n", env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
+
+    testdir.test_command_success_with_args(["-v"], expected);
+}