-
Notifications
You must be signed in to change notification settings - Fork 537
/
Copy pathshell.rs
204 lines (172 loc) · 3.4 KB
/
shell.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
use super::*;
const JUSTFILE: &str = "
expression := `EXPRESSION`
recipe default=`DEFAULT`:
{{expression}}
{{default}}
RECIPE
";
/// Test that --shell correctly sets the shell
#[test]
#[cfg_attr(windows, ignore)]
fn flag() {
let tmp = temptree! {
justfile: JUSTFILE,
shell: "#!/usr/bin/env bash\necho \"$@\"",
};
let shell = tmp.path().join("shell");
#[cfg(not(windows))]
{
let permissions = std::os::unix::fs::PermissionsExt::from_mode(0o700);
fs::set_permissions(&shell, permissions).unwrap();
}
let output = Command::new(executable_path("just"))
.current_dir(tmp.path())
.arg("--shell")
.arg(shell)
.output()
.unwrap();
let stdout = "-cu -cu EXPRESSION\n-cu -cu DEFAULT\n-cu RECIPE\n";
assert_stdout(&output, stdout);
}
/// Test that we can use `set shell` to use cmd.exe on windows
#[test]
#[cfg(windows)]
fn cmd() {
let tmp = temptree! {
justfile: r#"
set shell := ["cmd.exe", "/C"]
x := `Echo`
recipe:
REM foo
Echo "{{x}}"
"#,
};
let output = Command::new(executable_path("just"))
.current_dir(tmp.path())
.output()
.unwrap();
let stdout = "\\\"ECHO is on.\\\"\r\n";
assert_stdout(&output, stdout);
}
/// Test that we can use `set shell` to use cmd.exe on windows
#[test]
#[cfg(windows)]
fn powershell() {
let tmp = temptree! {
justfile: r#"
set shell := ["powershell.exe", "-c"]
x := `Write-Host "Hello, world!"`
recipe:
For ($i=0; $i -le 10; $i++) { Write-Host $i }
Write-Host "{{x}}"
"#
,
};
let output = Command::new(executable_path("just"))
.current_dir(tmp.path())
.output()
.unwrap();
let stdout = "0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\nHello, world!\n";
assert_stdout(&output, stdout);
}
#[test]
fn shell_args() {
Test::new()
.arg("--shell-arg")
.arg("-c")
.justfile(
"
default:
echo A${foo}A
",
)
.shell(false)
.stdout("AA\n")
.stderr("echo A${foo}A\n")
.run();
}
#[test]
fn shell_override() {
Test::new()
.arg("--shell")
.arg("bash")
.justfile(
"
set shell := ['foo-bar-baz']
default:
echo hello
",
)
.shell(false)
.stdout("hello\n")
.stderr("echo hello\n")
.run();
}
#[test]
fn shell_arg_override() {
Test::new()
.arg("--shell-arg")
.arg("-cu")
.justfile(
"
set shell := ['foo-bar-baz']
default:
echo hello
",
)
.stdout("hello\n")
.stderr("echo hello\n")
.shell(false)
.run();
}
#[test]
fn set_shell() {
Test::new()
.justfile(
"
set shell := ['echo', '-n']
x := `bar`
foo:
echo {{x}}
echo foo
",
)
.stdout("echo barecho foo")
.stderr("echo bar\necho foo\n")
.shell(false)
.run();
}
#[test]
fn recipe_shell_not_found_error_message() {
Test::new()
.justfile(
"
foo:
@echo bar
",
)
.shell(false)
.args(["--shell", "NOT_A_REAL_SHELL"])
.stderr_regex(
"error: Recipe `foo` could not be run because just could not find the shell: .*\n",
)
.status(1)
.run();
}
#[test]
fn backtick_recipe_shell_not_found_error_message() {
Test::new()
.justfile(
"
bar := `echo bar`
foo:
echo {{bar}}
",
)
.shell(false)
.args(["--shell", "NOT_A_REAL_SHELL"])
.stderr_regex("(?s)error: Backtick could not be run because just could not find the shell:.*")
.status(1)
.run();
}