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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
extern crate assert_cli;
#[macro_use]
extern crate textwrap_macros;
use std::path::Path;
/// Get the path to a resource in the `data` folder as a string.
fn data(name: &str) -> String {
Path::new(file!())
.parent()
.unwrap()
.join("data")
.join(name)
.into_os_string()
.into_string()
.expect("invalid Unicode data")
}
/// Tests to mimick the original behaviour of `cksfv`.
mod behaviour {
use super::data;
#[test]
#[allow(non_snake_case)]
/// Check that running with both `-g` and `-C` flags fails.
fn failure_g_and_C_flags() {
assert_cli::Assert::main_binary()
.with_args(&["-C", "/tmp", "-g", "list.sfv"])
.fails()
.unwrap();
}
#[test]
/// Check that running with multiple `-f` values checks the last one.
fn multiple_f_last() {
assert_cli::Assert::main_binary()
.with_args(&["-C", &data(""), "-f", &data("1.sfv"), "-f", &data("2.sfv")])
.succeeds()
.and()
.stderr().contains(format!("Verifying: {}", data("2.sfv")).as_str())
.unwrap()
}
#[test]
/// Check that running with multiple `-g` values checks the last one.
fn multiple_g_last() {
assert_cli::Assert::main_binary()
.with_args(&["-g", &data("1.sfv"), "-g", &data("2.sfv")])
.succeeds()
.and()
.stderr().contains(format!("Verifying: {}", data("2.sfv")).as_str())
.unwrap()
}
#[test]
#[ignore]
/// Check that when given both files to check and files to create a new
/// SFV for the program only checks the existing SFV.
///
/// TODO
fn cksfv_priority_over_newsfv() {
assert_cli::Assert::main_binary()
.with_args(&["-g", &data("1.sfv"), &data("2.txt")])
.succeeds()
.and()
.stderr().contains(format!("Verifying: {}", data("1.sfv")).as_str())
.unwrap()
}
}
/// Tests to check stdout / stderr redirection
mod io {
use super::data;
#[test]
fn test_g() {
assert_cli::Assert::main_binary()
.with_args(&["-g", &data("12.sfv")])
.succeeds()
.and()
.stdout().is("")
.and()
.stderr().contains(
dedent!(
r#"
--( Verifying: tests/data/12.sfv )----------------------------------------------
1.txt OK
2.txt OK
--------------------------------------------------------------------------------
Everything OK
"#
)
)
.unwrap()
}
#[test]
fn test_g_with_c() {
assert_cli::Assert::main_binary()
.with_args(&["-c", "-g", &data("12.sfv")])
.succeeds()
.and()
.stdout().is(
dedent!(
r#"
1.txt OK
2.txt OK
Everything OK
"#
)
)
.and()
.stderr().satisfies(|x|
x.ends_with(dedent!(
r#"
--( Verifying: tests/data/12.sfv )----------------------------------------------
--------------------------------------------------------------------------------
"#
)),
"wrong output\n"
)
.unwrap()
}
#[test]
/// Check that `-r` flag outputs everything to stderr
fn test_recursive() {
assert_cli::Assert::main_binary()
.with_args(&["-r"])
.succeeds()
.and()
.stdout().is("")
.and()
.stderr()
.contains(
textwrap::dedent(&format!(
r#"
Entering directory: {projdir}/tests/data
--( Verifying: 12.sfv )---------------------------------------------------------
1.txt OK
2.txt OK
--------------------------------------------------------------------------------
Everything OK
"#,
projdir = env!("CARGO_MANIFEST_DIR"))
).trim()
)
.stderr()
.contains(
textwrap::dedent(&format!(
r#"
Entering directory: {projdir}/tests/data
--( Verifying: 2.sfv )----------------------------------------------------------
2.txt OK
--------------------------------------------------------------------------------
Everything OK
"#,
projdir = env!("CARGO_MANIFEST_DIR"))
).trim()
)
.stderr()
.contains(
textwrap::dedent(&format!(
r#"
Entering directory: {projdir}/tests/data
--( Verifying: 1.sfv )----------------------------------------------------------
1.txt OK
--------------------------------------------------------------------------------
Everything OK
"#,
projdir = env!("CARGO_MANIFEST_DIR"))
).trim()
)
.stderr()
.contains(
textwrap::dedent(&format!(
r#"
Entering directory: {projdir}/tests/data
--( Verifying: 0.sfv )----------------------------------------------------------
--------------------------------------------------------------------------------
Everything OK
"#,
projdir = env!("CARGO_MANIFEST_DIR")
)).trim()
)
.unwrap()
}
#[test]
fn test_recursive_with_c() {
assert_cli::Assert::main_binary()
.with_args(&["-r", "-c"])
.succeeds()
.and()
.stdout()
.contains(dedent!(
r#"
1.txt OK
2.txt OK
Everything OK
"#
).trim())
.stdout()
.contains(dedent!(
r#"
1.txt OK
Everything OK
"#
).trim())
.stdout()
.contains(dedent!(
r#"
2.txt OK
Everything OK
"#
).trim())
.stdout()
.contains(dedent!(
r#"
Everything OK
"#
).trim())
.and()
.stderr()
.contains(textwrap::dedent(&format!(
r#"
Entering directory: {projdir}/tests/data
--( Verifying: 12.sfv )---------------------------------------------------------
--------------------------------------------------------------------------------
"#,
projdir = env!("CARGO_MANIFEST_DIR")
)).trim())
.stderr()
.contains(textwrap::dedent(&format!(
r#"
Entering directory: {projdir}/tests/data
--( Verifying: 2.sfv )----------------------------------------------------------
--------------------------------------------------------------------------------
"#,
projdir = env!("CARGO_MANIFEST_DIR")
)).trim())
.stderr()
.contains(textwrap::dedent(&format!(
r#"
Entering directory: {projdir}/tests/data
--( Verifying: 1.sfv )----------------------------------------------------------
--------------------------------------------------------------------------------
"#,
projdir = env!("CARGO_MANIFEST_DIR")
)).trim())
.stderr()
.contains(textwrap::dedent(&format!(
r#"
Entering directory: {projdir}/tests/data
--( Verifying: 0.sfv )----------------------------------------------------------
--------------------------------------------------------------------------------
"#,
projdir = env!("CARGO_MANIFEST_DIR")
)).trim())
.unwrap()
}
#[test]
fn test_recursive_with_q() {
assert_cli::Assert::main_binary()
.with_args(&["-r", "-q"])
.succeeds()
.and()
.stdout().is("")
.and()
.stderr().doesnt_contain("Everything OK")
.unwrap()
}
}