forked from assert-rs/assert_cmd
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcargo.rs
More file actions
65 lines (58 loc) · 1.73 KB
/
cargo.rs
File metadata and controls
65 lines (58 loc) · 1.73 KB
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
55
56
57
58
59
60
61
62
63
64
65
use std::process::Command;
use assert_cmd::pkg_name;
use assert_cmd::prelude::*;
use escargot::CURRENT_TARGET;
#[test]
fn cargo_binary() {
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
cmd.env("stdout", "42");
cmd.assert().success().stdout("42\n");
}
#[test]
fn cargo_binary_with_empty_env() {
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
cmd.env_clear().env("stdout", "42");
cmd.assert().success().stdout("42\n");
}
#[test]
fn mod_example() {
let runner_env = format!(
"CARGO_TARGET_{}_RUNNER",
CURRENT_TARGET.replace('-', "_").to_uppercase()
);
if std::env::var(runner_env).is_ok() {
// not running this test on cross because escargot doesn't support the cargo target runner yet
} else {
let bin_under_test = escargot::CargoBuild::new()
.bin("bin_fixture")
.current_release()
.current_target()
.run()
.unwrap();
let mut cmd = bin_under_test.command();
let output = cmd.unwrap();
println!("{output:?}");
}
}
#[test]
#[should_panic = "`CARGO_BIN_EXE_assert_cmd` is unset
help: available binary names are \"bin_fixture\""]
fn trait_example() {
let mut cmd = Command::cargo_bin(pkg_name!()).unwrap();
let output = cmd.unwrap();
println!("{output:?}");
}
#[test]
#[should_panic = "`CARGO_BIN_EXE_assert_cmd` is unset
help: available binary names are \"bin_fixture\""]
fn cargo_bin_example_1() {
let mut cmd = Command::cargo_bin(pkg_name!()).unwrap();
let output = cmd.unwrap();
println!("{output:?}");
}
#[test]
fn cargo_bin_example_2() {
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
let output = cmd.unwrap();
println!("{output:?}");
}