]> git.proxmox.com Git - rustc.git/blob - vendor/xshell/tests/it/compile_failures.rs
New upstream version 1.64.0+dfsg1
[rustc.git] / vendor / xshell / tests / it / compile_failures.rs
1 use xshell::{cmd, Shell};
2
3 #[track_caller]
4 fn check(code: &str, err_msg: &str) {
5 let sh = Shell::new().unwrap();
6 let xshell_dir = sh.current_dir();
7 let temp_dir = sh.create_temp_dir().unwrap();
8 sh.change_dir(temp_dir.path());
9
10 let manifest = format!(
11 r#"
12 [package]
13 name = "cftest"
14 version = "0.0.0"
15 edition = "2018"
16 [workspace]
17
18 [lib]
19 path = "main.rs"
20
21 [dependencies]
22 xshell = {{ path = {xshell_dir:?} }}
23 "#,
24 );
25
26 let snip = format!(
27 "
28 use xshell::*;
29 pub fn f() {{
30 let sh = Shell::new().unwrap();
31 {code};
32 }}
33 "
34 );
35
36 sh.write_file("Cargo.toml", manifest).unwrap();
37 sh.write_file("main.rs", snip).unwrap();
38
39 let stderr = cmd!(sh, "cargo build").ignore_status().read_stderr().unwrap();
40 assert!(
41 stderr.contains(err_msg),
42 "\n\nCompile fail fail!\n\nExpected:\n{}\n\nActual:\n{}\n",
43 err_msg,
44 stderr
45 );
46 }
47
48 #[test]
49 fn not_a_string_literal() {
50 check("cmd!(sh, 92)", "expected a plain string literal");
51 }
52
53 #[test]
54 fn not_raw_string_literal() {
55 check(r#"cmd!(sh, r"raw")"#, "expected a plain string literal");
56 }
57
58 #[test]
59 fn interpolate_complex_expression() {
60 check(
61 r#"cmd!(sh, "{echo.as_str()}")"#,
62 "error: can only interpolate simple variables, got this expression instead: `echo.as_str()`",
63 );
64 }
65
66 #[test]
67 fn interpolate_splat_concat_prefix() {
68 check(
69 r#"cmd!(sh, "echo a{args...}")"#,
70 "error: can't combine splat with concatenation, add spaces around `{args...}`",
71 );
72 }
73
74 #[test]
75 fn interpolate_splat_concat_suffix() {
76 check(
77 r#"cmd!(sh, "echo {args...}b")"#,
78 "error: can't combine splat with concatenation, add spaces around `{args...}`",
79 );
80 }
81
82 #[test]
83 fn interpolate_splat_concat_mixfix() {
84 check(
85 r#"cmd!(sh, "echo a{args...}b")"#,
86 "error: can't combine splat with concatenation, add spaces around `{args...}`",
87 );
88 }
89
90 #[test]
91 fn empty_command() {
92 check(r#"cmd!(sh, "")"#, "error: command can't be empty");
93 }
94
95 #[test]
96 fn spalt_program() {
97 check(r#"cmd!(sh, "{cmd...}")"#, "error: can't splat program name");
98 }
99
100 #[test]
101 fn unclosed_quote() {
102 check(r#"cmd!(sh, "echo 'hello world")"#, "error: unclosed `'` in command");
103 }
104
105 #[test]
106 fn unclosed_curly() {
107 check(r#"cmd!(sh, "echo {hello world")"#, "error: unclosed `{` in command");
108 }
109
110 #[test]
111 fn interpolate_integer() {
112 check(
113 r#"
114 let x = 92;
115 cmd!(sh, "make -j {x}")"#,
116 r#"is not implemented"#,
117 );
118 }
119
120 #[test]
121 fn splat_fn_pointer() {
122 check(
123 r#"
124 let dry_run: fn() -> Option<&'static str> = || None;
125 cmd!(sh, "make -j {dry_run...}")"#,
126 r#"is not implemented"#,
127 );
128 }