-
Notifications
You must be signed in to change notification settings - Fork 499
/
confirm.rs
159 lines (147 loc) Β· 3.09 KB
/
confirm.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
use super::*;
#[test]
fn confirm_recipe_arg() {
Test::new()
.arg("--yes")
.justfile(
"
[confirm]
requires_confirmation:
echo confirmed
",
)
.stderr("echo confirmed\n")
.stdout("confirmed\n")
.run();
}
#[test]
fn recipe_with_confirm_recipe_dependency_arg() {
Test::new()
.arg("--yes")
.justfile(
"
dep_confirmation: requires_confirmation
echo confirmed2
[confirm]
requires_confirmation:
echo confirmed
",
)
.stderr("echo confirmed\necho confirmed2\n")
.stdout("confirmed\nconfirmed2\n")
.run();
}
#[test]
fn confirm_recipe() {
Test::new()
.justfile(
"
[confirm]
requires_confirmation:
echo confirmed
",
)
.stderr("Run recipe `requires_confirmation`? echo confirmed\n")
.stdout("confirmed\n")
.stdin("y")
.run();
}
#[test]
fn recipe_with_confirm_recipe_dependency() {
Test::new()
.justfile(
"
dep_confirmation: requires_confirmation
echo confirmed2
[confirm]
requires_confirmation:
echo confirmed
",
)
.stderr("Run recipe `requires_confirmation`? echo confirmed\necho confirmed2\n")
.stdout("confirmed\nconfirmed2\n")
.stdin("y")
.run();
}
#[test]
fn do_not_confirm_recipe() {
Test::new()
.justfile(
"
[confirm]
requires_confirmation:
echo confirmed
",
)
.stderr("Run recipe `requires_confirmation`? error: Recipe `requires_confirmation` was not confirmed\n")
.stdout("")
.status(1)
.run();
}
#[test]
fn do_not_confirm_recipe_with_confirm_recipe_dependency() {
Test::new()
.justfile(
"
dep_confirmation: requires_confirmation
echo mistake
[confirm]
requires_confirmation:
echo confirmed
",
)
.stderr("Run recipe `requires_confirmation`? error: Recipe `requires_confirmation` was not confirmed\n")
.status(1)
.run();
}
#[test]
fn confirm_recipe_with_prompt() {
Test::new()
.justfile(
"
[confirm(\"This is dangerous - are you sure you want to run it?\")]
requires_confirmation:
echo confirmed
",
)
.stderr("This is dangerous - are you sure you want to run it? echo confirmed\n")
.stdout("confirmed\n")
.stdin("y")
.run();
}
#[test]
fn confirm_recipe_with_prompt_too_many_args() {
Test::new()
.justfile(
r#"
[confirm("PROMPT","EXTRA")]
requires_confirmation:
echo confirmed
"#,
)
.stderr(
r#"
error: Attribute `confirm` got 2 arguments but takes at most 1 argument
βββΆ justfile:1:2
β
1 β [confirm("PROMPT","EXTRA")]
β ^^^^^^^
"#,
)
.stdout("")
.status(1)
.run();
}
#[test]
fn confirm_attribute_is_formatted_correctly() {
Test::new()
.justfile(
"
[confirm('prompt')]
foo:
",
)
.arg("--dump")
.stdout("[confirm('prompt')]\nfoo:\n")
.run();
}