-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_cli.rs
54 lines (43 loc) · 1.36 KB
/
test_cli.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#[cfg(test)]
extern crate assert_cmd;
extern crate predicates;
use assert_cmd::prelude::*;
use predicates::prelude::*;
use std::process::Command;
// CLI Test
//
// Test the CLI interface of the application. This is done by running the binary
// and expecting that the execution is passed to Git.
//
// In this case, we expect the initial output to be the usage of Git.
#[test]
fn test_cli() {
let expected_initial = "usage: git [-v | --version]";
let mut cmd = Command::cargo_bin("giton").expect("Calling binary failed");
cmd.assert()
.stdout(predicate::str::contains(expected_initial));
}
// CLI Version Test
//
// This is a similar test to the previous one, but we are testing the ability to
// pass the `version` argument to the binary.
#[test]
fn test_version() {
let expected_initial = "git version";
let mut cmd = Command::cargo_bin("giton").expect("Calling binary failed");
cmd.arg("version")
.assert()
.stdout(predicate::str::contains(expected_initial));
}
// CLI Passthrough Test
//
// This tests the ability to call Clap commands. The command tested here is
// `onconfig`.
#[test]
fn test_passthrough() {
let expected_initial = "+--";
let mut cmd = Command::cargo_bin("giton").expect("Calling binary failed");
cmd.arg("onconfig")
.assert()
.stdout(predicate::str::contains(expected_initial));
}