-
Notifications
You must be signed in to change notification settings - Fork 499
/
shell.rs
189 lines (155 loc) · 3.32 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
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);
}
const JUSTFILE_CMD: &str = r#"
set shell := ["cmd.exe", "/C"]
x := `Echo`
recipe:
REM foo
Echo "{{x}}"
"#;
/// Test that we can use `set shell` to use cmd.exe on windows
#[test]
#[cfg_attr(unix, ignore)]
fn cmd() {
let tmp = temptree! {
justfile: JUSTFILE_CMD,
};
let output = Command::new(executable_path("just"))
.current_dir(tmp.path())
.output()
.unwrap();
let stdout = "\\\"ECHO is on.\\\"\r\n";
assert_stdout(&output, stdout);
}
const JUSTFILE_POWERSHELL: &str = 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}}"
"#;
/// Test that we can use `set shell` to use cmd.exe on windows
#[test]
#[cfg_attr(unix, ignore)]
fn powershell() {
let tmp = temptree! {
justfile: JUSTFILE_POWERSHELL,
};
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! {
name: shell_args,
justfile: "
default:
echo A${foo}A
",
args: ("--shell-arg", "-c"),
stdout: "AA\n",
stderr: "echo A${foo}A\n",
shell: false,
}
test! {
name: shell_override,
justfile: "
set shell := ['foo-bar-baz']
default:
echo hello
",
args: ("--shell", "bash"),
stdout: "hello\n",
stderr: "echo hello\n",
shell: false,
}
test! {
name: shell_arg_override,
justfile: "
set shell := ['foo-bar-baz']
default:
echo hello
",
args: ("--shell-arg", "-cu"),
stdout: "hello\n",
stderr: "echo hello\n",
shell: false,
}
test! {
name: set_shell,
justfile: "
set shell := ['echo', '-n']
x := `bar`
foo:
echo {{x}}
echo foo
",
args: (),
stdout: "echo barecho foo",
stderr: "echo bar\necho foo\n",
shell: false,
}
#[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();
}