Debian Codegraph @

debian/missing-sources/assert_cmd/src/lib.rs

raw symbols SCIP
1 //! **Assert [`Command`]** - Easy command initialization and assertions.
2 //!
3 //! `assert_cmd` aims to simplify the process for doing integration testing of CLIs, including:
4 //! - Finding your crate's binary to test
5 //! - Assert on the result of your program's run.
6 //!
7 //! ## Overview
8 //!
9 //! Create a [`Command`]:
10 //! - `Command::new(path)`
11 //! - `Command::from_std(...)`
12 //! - `Command::cargo_bin(name)`
13 //!
14 //! Configure a [`Command`]:
15 //! - `arg` / `args`
16 //! - `current_dir`
17 //! - `env` / `envs` / `env_remove` / `env_clear`
18 //! - `write_stdin` / `pipe_stdin`
19 //! - `timeout`
20 //!
21 //! Validate a [`Command`]:
22 //! - `ok` / `unwrap` / `unwrap_err`
23 //! - `assert`
24 //! - `success`, see [`Assert`]
25 //! - `failure`, see [`Assert`]
26 //! - `interrupted`, see [`Assert`]
27 //! - `code`, see [`Assert`]
28 //! - `stdout`, see [`Assert`]
29 //! - `stderr`, see [`Assert`]
30 //! - `get_output` for everything else, see [`Assert`]
31 //!
32 //! Note: [`Command`] is provided as a convenience. Extension traits for [`std::process::Command`]
33 //! and `Output` are provided for interoperability:
34 //! - [`CommandCargoExt`]
35 //! - [`OutputOkExt`]
36 //! - [`OutputAssertExt`]
37 //!
38 //! ## Examples
39 //!
40 //! Here's a trivial example:
41 //! ```rust,no_run
42 //! use assert_cmd::Command;
43 //!
44 //! let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
45 //! cmd.assert().success();
46 //! ```
47 //!
48 //! And a little of everything:
49 //! ```rust,no_run
50 //! use assert_cmd::Command;
51 //!
52 //! let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
53 //! let assert = cmd
54 //! .arg("-A")
55 //! .env("stdout", "hello")
56 //! .env("exit", "42")
57 //! .write_stdin("42")
58 //! .assert();
59 //! assert
60 //! .failure()
61 //! .code(42)
62 //! .stdout("hello\n");
63 //! ```
64 //!
65 //! ## Relevant crates
66 //!
67 //! Other crates that might be useful in testing command line programs.
68 //! * [escargot] for more control over configuring the crate's binary.
69 //! * [duct] for orchestrating multiple processes.
70 //! * or [commandspec] for easier writing of commands
71 //! * [rexpect][rexpect] for testing interactive programs.
72 //! * [assert_fs] for filesystem fixtures and assertions.
73 //! * or [tempfile] for scratchpad directories.
74 //! * [dir-diff] for testing file side-effects.
75 //!
76 //! ## Migrating from `assert_cli` v0.6
77 //!
78 //! `assert_cmd` is the successor to [the original `assert_cli`][assert_cli]:
79 //! - More flexible, reusable assertions (also used by [assert_fs]).
80 //! - Can integrate with other process-management crates, like `duct`.
81 //! - Addresses several architectural problems.
82 //!
83 //! Key points in migrating from `assert_cli`:
84 //! - The command-under-test is run eagerly, with assertions happening immediately.
85 //! - [`success()`] is not implicit and requires being explicitly called.
86 //! - `stdout`/`stderr` aren't automatically trimmed before being passed to the `Predicate`.
87 //!
88 //! [commandspec]: https://crates.io/crates/commandspec
89 //! [assert_cli]: https://crates.io/crates/assert_cli/0.6.3
90 //! [dir-diff]: https://crates.io/crates/dir-diff
91 //! [tempfile]: https://crates.io/crates/tempfile
92 //! [escargot]: https://crates.io/crates/escargot
93 //! [duct]: https://crates.io/crates/duct
94 //! [assert_fs]: https://crates.io/crates/assert_fs
95 //! [rexpect]: https://crates.io/crates/rexpect
96 //! [`Command`]: cmd::Command
97 //! [`Assert`]: assert::Assert
98 //! [`success()`]: assert::Assert::success()
99 //! [`CommandCargoExt`]: cargo::CommandCargoExt
100 //! [`OutputOkExt`]: output::OutputOkExt
101 //! [`OutputAssertExt`]: assert::OutputAssertExt
102
103 #![cfg_attr(docsrs, feature(doc_cfg))]
104 #![warn(clippy::print_stderr)]
105 #![warn(clippy::print_stdout)]
106
107 mod macrosrust-analyzer cargo assert_cmd 2.1.2 macros/;
108
109 pub mod assertrust-analyzer cargo assert_cmd 2.1.2 assert/;
110 pub mod cargorust-analyzer cargo assert_cmd 2.1.2 cargo/;
111 pub mod cmdrust-analyzer cargo assert_cmd 2.1.2 cmd/;
112 pub mod outputrust-analyzer cargo assert_cmd 2.1.2 output/;
113
114 /// Extension traits that are useful to have available.
115 pub mod preluderust-analyzer cargo assert_cmd 2.1.2 prelude/ {
116 pub use craterust-analyzer cargo assert_cmd 2.1.2 crate/::assertrust-analyzer cargo assert_cmd 2.1.2 assert/::OutputAssertExtrust-analyzer cargo assert_cmd 2.1.2 assert/OutputAssertExt#;
117 pub use craterust-analyzer cargo assert_cmd 2.1.2 crate/::cargorust-analyzer cargo assert_cmd 2.1.2 cargo/::CommandCargoExtrust-analyzer cargo assert_cmd 2.1.2 cargo/CommandCargoExt#;
118 pub use craterust-analyzer cargo assert_cmd 2.1.2 crate/::outputrust-analyzer cargo assert_cmd 2.1.2 output/::OutputOkExtrust-analyzer cargo assert_cmd 2.1.2 output/OutputOkExt#;
119 }
120
121 pub use craterust-analyzer cargo assert_cmd 2.1.2 crate/::cmdrust-analyzer cargo assert_cmd 2.1.2 cmd/::Commandrust-analyzer cargo assert_cmd 2.1.2 cmd/Command#;
122
123 mod colorrust-analyzer cargo assert_cmd 2.1.2 color/;
124 use colorrust-analyzer cargo assert_cmd 2.1.2 color/::Paletterust-analyzer cargo assert_cmd 2.1.2 color/Palette#;
125
126 #[doc = include_strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/include_str!!("../README.md")]
127 #[cfg(doctest)]
128 pub struct ReadmeDoctests;