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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
use xshell::{cmd, Shell};
#[track_caller]
fn check(code: &str, err_msg: &str) {
let sh = Shell::new().unwrap();
let xshell_dir = sh.current_dir();
let temp_dir = sh.create_temp_dir().unwrap();
sh.change_dir(temp_dir.path());
let manifest = format!(
r#"
[package]
name = "cftest"
version = "0.0.0"
edition = "2018"
[workspace]
[lib]
path = "main.rs"
[dependencies]
xshell = {{ path = {xshell_dir:?} }}
"#,
);
let snip = format!(
"
use xshell::*;
pub fn f() {{
let sh = Shell::new().unwrap();
{code};
}}
"
);
sh.write_file("Cargo.toml", manifest).unwrap();
sh.write_file("main.rs", snip).unwrap();
let stderr = cmd!(sh, "cargo build").ignore_status().read_stderr().unwrap();
assert!(
stderr.contains(err_msg),
"\n\nCompile fail fail!\n\nExpected:\n{}\n\nActual:\n{}\n",
err_msg,
stderr
);
}
#[test]
fn not_a_string_literal() {
check("cmd!(sh, 92)", "expected a plain string literal");
}
#[test]
fn not_raw_string_literal() {
check(r#"cmd!(sh, r"raw")"#, "expected a plain string literal");
}
#[test]
fn interpolate_complex_expression() {
check(
r#"cmd!(sh, "{echo.as_str()}")"#,
"error: can only interpolate simple variables, got this expression instead: `echo.as_str()`",
);
}
#[test]
fn interpolate_splat_concat_prefix() {
check(
r#"cmd!(sh, "echo a{args...}")"#,
"error: can't combine splat with concatenation, add spaces around `{args...}`",
);
}
#[test]
fn interpolate_splat_concat_suffix() {
check(
r#"cmd!(sh, "echo {args...}b")"#,
"error: can't combine splat with concatenation, add spaces around `{args...}`",
);
}
#[test]
fn interpolate_splat_concat_mixfix() {
check(
r#"cmd!(sh, "echo a{args...}b")"#,
"error: can't combine splat with concatenation, add spaces around `{args...}`",
);
}
#[test]
fn empty_command() {
check(r#"cmd!(sh, "")"#, "error: command can't be empty");
}
#[test]
fn spalt_program() {
check(r#"cmd!(sh, "{cmd...}")"#, "error: can't splat program name");
}
#[test]
fn unclosed_quote() {
check(r#"cmd!(sh, "echo 'hello world")"#, "error: unclosed `'` in command");
}
#[test]
fn unclosed_curly() {
check(r#"cmd!(sh, "echo {hello world")"#, "error: unclosed `{` in command");
}
#[test]
fn interpolate_integer() {
check(
r#"
let x = 92;
cmd!(sh, "make -j {x}")"#,
r#"is not implemented"#,
);
}
#[test]
fn splat_fn_pointer() {
check(
r#"
let dry_run: fn() -> Option<&'static str> = || None;
cmd!(sh, "make -j {dry_run...}")"#,
r#"is not implemented"#,
);
}
|