1
1
# Assert CLI
2
2
3
- > Test CLI Applications.
3
+ > ** Test CLI Applications** - This crate checks the output of a child process is as expected .
4
4
5
- Currently, this crate only includes basic functionality to check the output of a child process
6
- is as expected.
7
-
8
- [ ![ Build Status] ( https://travis-ci.org/killercup/assert_cli.svg )] ( https://travis-ci.org/killercup/assert_cli ) [ ![ Coverage Status] ( https://coveralls.io/repos/killercup/assert_cli/badge.svg?branch=master&service=github )] ( https://coveralls.io/github/killercup/assert_cli?branch=master )
9
-
10
- ** [ Documentation] ( http://killercup.github.io/assert_cli/ ) **
5
+ [ ![ Build Status] ( https://travis-ci.org/killercup/assert_cli.svg )] ( https://travis-ci.org/killercup/assert_cli ) [ ![ Documentation] ( https://img.shields.io/badge/docs-master-blue.svg )] [ Documentation ]
11
6
12
7
## Install
13
8
@@ -30,13 +25,13 @@ fn main() {
30
25
}
31
26
```
32
27
33
- Or if you'd rather use the macro:
28
+ Or if you'd rather use the macro, to save you some writing :
34
29
35
30
``` rust
36
31
#[macro_use] extern crate assert_cli;
37
32
38
33
fn main () {
39
- assert_cmd! (echo 42 ) . succeeds () . and ( ). prints (" 42" ). unwrap ();
34
+ assert_cmd! (echo " 42 " ). prints (" 42" ). unwrap ();
40
35
}
41
36
```
42
37
@@ -47,33 +42,42 @@ And here is one that will fail (which also shows `execute` which returns a
47
42
#[macro_use] extern crate assert_cli;
48
43
49
44
fn main () {
50
- let test = assert_cmd! (grep amet Cargo . toml)
51
- . fails_with (1 )
45
+ let test = assert_cmd! (ls " foo-bar-foo" )
46
+ . fails ()
47
+ . and ()
48
+ . prints_error (" foo-bar-foo" )
52
49
. execute ();
53
- assert! (test . is_err ());
50
+ assert! (test . is_ok ());
54
51
}
55
52
```
56
53
57
- If you want to check for the program's output, you can use ` print ` or
58
- ` print_exactly ` :
54
+ If you want to match the program's output _ exactly _ , you can use
55
+ ` prints_exactly ` :
59
56
60
- ``` rust,should_panic="Assert CLI failure"
57
+ ``` rust,should_panic
61
58
#[macro_use] extern crate assert_cli;
62
59
63
60
fn main() {
64
- assert_cmd!("wc" "README.md")
61
+ assert_cmd!(wc "README.md")
65
62
.prints_exactly("1337 README.md")
66
63
.unwrap();
67
64
}
68
65
```
69
66
70
- this will show a nice, colorful diff in your terminal, like this:
67
+ ... which has the benefit to show a nice, colorful diff in your terminal,
68
+ like this:
71
69
72
70
``` diff
73
71
- 1337
74
72
+ 92
75
73
```
76
74
75
+ ** Tip** : Enclose arguments in the ` assert_cmd! ` macro in quotes ` " ` ,
76
+ if there are special characters, which the macro doesn't accept, e.g.
77
+ ` assert_cmd!(cat "foo.txt") ` .
78
+
79
+ More detailed information is available in the [ documentation] . :-)
80
+
77
81
## License
78
82
79
83
Licensed under either of
@@ -89,3 +93,5 @@ Unless you explicitly state otherwise, any contribution intentionally
89
93
submitted for inclusion in the work by you, as defined in the Apache-2.0
90
94
license, shall be dual licensed as above, without any additional terms or
91
95
conditions.
96
+
97
+ [ Documentation ] : http://killercup.github.io/assert_cli/
0 commit comments