Add test for cli help

This commit is contained in:
Félix Saparelli 2021-05-10 23:02:31 +12:00
parent eafbc9a77b
commit 0d2f28c91a
No known key found for this signature in database
GPG Key ID: B948C4BAE44FC474
5 changed files with 328 additions and 0 deletions

218
Cargo.lock generated
View File

@ -9,6 +9,20 @@ dependencies = [
"memchr",
]
[[package]]
name = "assert_cmd"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2475b58cd94eb4f70159f4fd8844ba3b807532fe3131b3373fae060bbe30396"
dependencies = [
"bstr",
"doc-comment",
"predicates",
"predicates-core",
"predicates-tree",
"wait-timeout",
]
[[package]]
name = "bitflags"
version = "1.2.1"
@ -21,9 +35,17 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a40b47ad93e1a5404e6c18dec46b628214fee441c70f4ab5d6942142cc268a3d"
dependencies = [
"lazy_static",
"memchr",
"regex-automata",
]
[[package]]
name = "byteorder"
version = "1.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610"
[[package]]
name = "cc"
version = "1.0.67"
@ -67,6 +89,19 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "console"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45"
dependencies = [
"encode_unicode",
"lazy_static",
"libc",
"terminal_size",
"winapi 0.3.9",
]
[[package]]
name = "darling"
version = "0.12.4"
@ -133,6 +168,12 @@ dependencies = [
"syn",
]
[[package]]
name = "difference"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198"
[[package]]
name = "dirs"
version = "2.0.2"
@ -154,6 +195,18 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "doc-comment"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10"
[[package]]
name = "dtoa"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56899898ce76aaf4a0f24d914c97ea6ed976d42fec6ad33fcbb0a1103e07b2b0"
[[package]]
name = "either"
version = "1.6.1"
@ -171,6 +224,12 @@ dependencies = [
"winreg",
]
[[package]]
name = "encode_unicode"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f"
[[package]]
name = "env_logger"
version = "0.8.3"
@ -300,6 +359,21 @@ dependencies = [
"libc",
]
[[package]]
name = "insta"
version = "1.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4a1b21a2971cea49ca4613c0e9fe8225ecaf5de64090fddc6002284726e9244"
dependencies = [
"console",
"lazy_static",
"serde",
"serde_json",
"serde_yaml",
"similar",
"uuid",
]
[[package]]
name = "iovec"
version = "0.1.4"
@ -309,6 +383,12 @@ dependencies = [
"libc",
]
[[package]]
name = "itoa"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd25036021b0de88a0aff6b850051563c6516d0bf53f8638938edbb9de732736"
[[package]]
name = "kernel32-sys"
version = "0.2.2"
@ -337,6 +417,12 @@ version = "0.2.93"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9385f66bf6105b241aa65a61cb923ef20efc665cb9f9bb50ac2f0c4b7f378d41"
[[package]]
name = "linked-hash-map"
version = "0.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fb9b38af92608140b86b693604b9ffcc5824240a484d1ecd4795bacb2fe88f3"
[[package]]
name = "log"
version = "0.4.14"
@ -490,6 +576,32 @@ version = "0.2.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857"
[[package]]
name = "predicates"
version = "1.0.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f49cfaf7fdaa3bfacc6fa3e7054e65148878354a5cfddcf661df4c851f8021df"
dependencies = [
"difference",
"predicates-core",
]
[[package]]
name = "predicates-core"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57e35a3326b75e49aa85f5dc6ec15b41108cf5aee58eabb1f274dd18b73c2451"
[[package]]
name = "predicates-tree"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15f553275e5721409451eb85e15fd9a860a6e5ab4496eb215987502b5f5391f2"
dependencies = [
"predicates-core",
"treeline",
]
[[package]]
name = "proc-macro2"
version = "1.0.26"
@ -589,12 +701,27 @@ dependencies = [
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ae1ded71d66a4a97f5e961fd0cb25a5f366a42a41570d16a763a69c092c26ae4"
dependencies = [
"byteorder",
]
[[package]]
name = "regex-syntax"
version = "0.6.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
[[package]]
name = "ryu"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
[[package]]
name = "same-file"
version = "1.0.6"
@ -604,6 +731,55 @@ dependencies = [
"winapi-util",
]
[[package]]
name = "serde"
version = "1.0.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "558dc50e1a5a5fa7112ca2ce4effcb321b0300c0d4ccf0776a9f60cd89031171"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.125"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b093b7a2bb58203b5da3056c05b4ec1fed827dcfdb37347a8841695263b3d06d"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.64"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "799e97dc9fdae36a5c8b8f2cae9ce2ee9fdce2058c57a93e6099d919fd982f79"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.8.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15654ed4ab61726bf918a39cb8d98a2e2995b002387807fa6ba58fdf7f59bb23"
dependencies = [
"dtoa",
"linked-hash-map",
"serde",
"yaml-rust",
]
[[package]]
name = "similar"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ad1d488a557b235fc46dae55512ffbfc429d2482b08b4d9435ab07384ca8aec"
[[package]]
name = "siphasher"
version = "0.3.5"
@ -643,6 +819,16 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "terminal_size"
version = "0.1.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86ca8ced750734db02076f44132d802af0b33b09942331f4459dde8636fd2406"
dependencies = [
"libc",
"winapi 0.3.9",
]
[[package]]
name = "terminfo"
version = "0.7.3"
@ -686,6 +872,12 @@ dependencies = [
"syn",
]
[[package]]
name = "treeline"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41"
[[package]]
name = "unicode-width"
version = "0.1.8"
@ -698,6 +890,12 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564"
[[package]]
name = "uuid"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
[[package]]
name = "version_check"
version = "0.9.3"
@ -724,6 +922,15 @@ dependencies = [
"libc",
]
[[package]]
name = "wait-timeout"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f200f5b12eb75f8c1ed65abd4b2db8a6e1b138a20de009dacee265a2498f3f6"
dependencies = [
"libc",
]
[[package]]
name = "walkdir"
version = "2.3.2"
@ -767,9 +974,11 @@ dependencies = [
name = "watchexec-cli"
version = "1.16.0"
dependencies = [
"assert_cmd",
"clap",
"embed-resource",
"env_logger",
"insta",
"log",
"watchexec",
]
@ -845,3 +1054,12 @@ dependencies = [
"winapi 0.2.8",
"winapi-build",
]
[[package]]
name = "yaml-rust"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85"
dependencies = [
"linked-hash-map",
]

View File

@ -36,6 +36,10 @@ features = []
[build-dependencies]
embed-resource = "1.6.1"
[dev-dependencies]
assert_cmd = "1.0.3"
insta = "1.7.1"
[package.metadata.binstall]
pkg-url = "{ repo }/releases/download/cli-v{ version }/watchexec-{ version }-{ target }.tar.xz"
bin-dir = "watchexec-{ version }-{ target }/{ bin }{ format }"

17
cli/tests/help.rs Normal file
View File

@ -0,0 +1,17 @@
use std::process::Command;
use assert_cmd::prelude::*;
use insta::assert_snapshot;
#[test]
fn help() {
let output = Command::cargo_bin("watchexec")
.unwrap()
.arg("--help")
.output()
.unwrap();
assert!(output.status.success(), "--help returns 0");
assert_eq!(output.stderr, Vec::<u8>::new(), "--help stderr is empty");
assert_snapshot!(if cfg!(windows) { "help_windows" } else { "help_unix" }, String::from_utf8(output.stdout).unwrap());
}

View File

@ -0,0 +1,44 @@
---
source: cli/tests/help.rs
expression: String::from_utf8(output.stdout).unwrap()
---
watchexec 1.16.0
Execute commands when watched files change
USAGE:
watchexec [FLAGS] [OPTIONS] <command>...
FLAGS:
--changes-only Only print path change information. Overridden by --verbose
-c, --clear Clear screen before executing command
-h, --help Prints help information
--no-default-ignore Skip auto-ignoring of commonly ignored globs
--no-environment Do not set WATCHEXEC_*_PATH environment variables for the command
--no-ignore Skip auto-loading of ignore files (.gitignore, .ignore, etc.) for filtering
--no-meta Ignore metadata changes
-n, --no-shell Do not wrap command in a shell. Deprecated: use --shell=none instead.
--no-vcs-ignore Skip auto-loading of .gitignore files for filtering
-p, --postpone Wait until first change to execute command
-r, --restart Restart the process if it's still running. Shorthand for --on-busy-update=restart
-V, --version Prints version information
-v, --verbose Print debugging messages to stderr
-W, --watch-when-idle Deprecated alias for --on-busy-update=do-nothing, which will become the default in 2.0.
OPTIONS:
-d, --debounce <milliseconds> Set the timeout between detected change and command execution, defaults to
150ms
-e, --exts <extensions> Comma-separated list of file extensions to watch (e.g. js,css,html)
-f, --filter <pattern>... Ignore all modifications except those matching the pattern
-i, --ignore <pattern>... Ignore modifications to paths matching the pattern
--on-busy-update <on-busy-update> Select the behaviour to use when receiving events while the command is
running. Current default is queue, will change to do-nothing in 2.0.
[possible values: do-nothing, queue, restart, signal]
-w, --watch <path>... Watch a specific file or directory
--force-poll <interval> Force polling mode (interval in milliseconds)
--shell <shell> Use a different shell, or `none`. E.g. --shell=bash
-s, --signal <signal> Send signal to process upon changes, e.g. SIGHUP
ARGS:
<command>... Command to execute

View File

@ -0,0 +1,45 @@
---
source: cli/tests/help.rs
expression: String::from_utf8(output.stdout).unwrap()
---
watchexec 1.16.0
Execute commands when watched files change
USAGE:
watchexec [FLAGS] [OPTIONS] <command>...
FLAGS:
--changes-only Only print path change information. Overridden by --verbose
-c, --clear Clear screen before executing command
-h, --help Prints help information
--no-default-ignore Skip auto-ignoring of commonly ignored globs
--no-environment Do not set WATCHEXEC_*_PATH environment variables for the command
--no-ignore Skip auto-loading of ignore files (.gitignore, .ignore, etc.) for filtering
--no-meta Ignore metadata changes
-n, --no-shell Do not wrap command in a shell. Deprecated: use --shell=none instead.
--no-vcs-ignore Skip auto-loading of .gitignore files for filtering
-p, --postpone Wait until first change to execute command
-r, --restart Restart the process if it's still running. Shorthand for --on-busy-update=restart
-V, --version Prints version information
-v, --verbose Print debugging messages to stderr
-W, --watch-when-idle Deprecated alias for --on-busy-update=do-nothing, which will become the default in 2.0.
OPTIONS:
-d, --debounce <milliseconds> Set the timeout between detected change and command execution, defaults to
150ms
-e, --exts <extensions> Comma-separated list of file extensions to watch (e.g. js,css,html)
-f, --filter <pattern>... Ignore all modifications except those matching the pattern
-i, --ignore <pattern>... Ignore modifications to paths matching the pattern
--on-busy-update <on-busy-update> Select the behaviour to use when receiving events while the command is
running. Current default is queue, will change to do-nothing in 2.0.
[possible values: do-nothing, queue, restart, signal]
-w, --watch <path>... Watch a specific file or directory
--force-poll <interval> Force polling mode (interval in milliseconds)
--shell <shell> Use a different shell, or `none`. Try --shell=powershell, which will become
the default in 2.0.
-s, --signal <signal> Send signal to process upon changes, e.g. SIGHUP
ARGS:
<command>... Command to execute