blob: 8021dffa9b208588dbd3c894ec31b8b2d7e66c9d [file] [log] [blame]
Charisee9cf67802022-06-30 20:04:09 +00001//! Tests for target filter flags with glob patterns.
ThiƩbaud Weksteen5bd94c12021-01-06 15:18:42 +01002
3use cargo_test_support::{project, Project};
4
5#[cargo_test]
6fn build_example() {
7 full_project()
8 .cargo("build -v --example 'ex*1'")
9 .with_stderr(
10 "\
11[COMPILING] foo v0.0.1 ([CWD])
12[RUNNING] `rustc --crate-name example1 [..]`
13[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
14",
15 )
16 .run();
17}
18
19#[cargo_test]
20fn build_bin() {
21 full_project()
22 .cargo("build -v --bin 'bi*1'")
23 .with_stderr(
24 "\
25[COMPILING] foo v0.0.1 ([CWD])
26[RUNNING] `rustc --crate-name bin1 [..]`
27[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
28",
29 )
30 .run();
31}
32
33#[cargo_test]
34fn build_bench() {
35 full_project()
36 .cargo("build -v --bench 'be*1'")
37 .with_stderr_contains("[RUNNING] `rustc --crate-name bench1 [..]`")
38 .with_stderr_contains("[RUNNING] `rustc --crate-name bin2 [..]`")
39 .with_stderr_contains("[RUNNING] `rustc --crate-name bin1 [..]`")
40 .with_stderr_contains("[RUNNING] `rustc --crate-name foo [..]`")
41 .with_stderr(
42 "\
43[COMPILING] foo v0.0.1 ([CWD])
44[RUNNING] `rustc --crate-name [..]`
45[RUNNING] `rustc --crate-name [..]`
46[RUNNING] `rustc --crate-name [..]`
47[RUNNING] `rustc --crate-name [..]`
48[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
49",
50 )
51 .run();
52}
53
54#[cargo_test]
55fn build_test() {
56 full_project()
57 .cargo("build -v --test 'te*1'")
58 .with_stderr_contains("[RUNNING] `rustc --crate-name test1 [..]`")
59 .with_stderr_contains("[RUNNING] `rustc --crate-name bin2 [..]`")
60 .with_stderr_contains("[RUNNING] `rustc --crate-name bin1 [..]`")
61 .with_stderr_contains("[RUNNING] `rustc --crate-name foo [..]`")
62 .with_stderr(
63 "\
64[COMPILING] foo v0.0.1 ([CWD])
65[RUNNING] `rustc --crate-name [..]`
66[RUNNING] `rustc --crate-name [..]`
67[RUNNING] `rustc --crate-name [..]`
68[RUNNING] `rustc --crate-name [..]`
69[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
70",
71 )
72 .run();
73}
74
75#[cargo_test]
76fn check_example() {
77 full_project()
78 .cargo("check -v --example 'ex*1'")
79 .with_stderr(
80 "\
81[CHECKING] foo v0.0.1 ([CWD])
82[RUNNING] `rustc --crate-name example1 [..]`
83[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
84",
85 )
86 .run();
87}
88
89#[cargo_test]
90fn check_bin() {
91 full_project()
92 .cargo("check -v --bin 'bi*1'")
93 .with_stderr(
94 "\
95[CHECKING] foo v0.0.1 ([CWD])
96[RUNNING] `rustc --crate-name bin1 [..]`
97[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
98",
99 )
100 .run();
101}
102
103#[cargo_test]
104fn check_bench() {
105 full_project()
106 .cargo("check -v --bench 'be*1'")
107 .with_stderr(
108 "\
109[CHECKING] foo v0.0.1 ([CWD])
110[RUNNING] `rustc --crate-name bench1 [..]`
111[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
112",
113 )
114 .run();
115}
116
117#[cargo_test]
118fn check_test() {
119 full_project()
120 .cargo("check -v --test 'te*1'")
121 .with_stderr(
122 "\
123[CHECKING] foo v0.0.1 ([CWD])
124[RUNNING] `rustc --crate-name test1 [..]`
125[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
126",
127 )
128 .run();
129}
130
131#[cargo_test]
132fn doc_bin() {
133 full_project()
134 .cargo("doc -v --bin 'bi*1'")
135 .with_stderr(
136 "\
137[DOCUMENTING] foo v0.0.1 ([CWD])
138[RUNNING] `rustdoc --crate-type bin --crate-name bin1 [..]`
139[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
140",
141 )
142 .run();
143}
144
145#[cargo_test]
146fn fix_example() {
147 full_project()
148 .cargo("fix -v --example 'ex*1' --allow-no-vcs")
149 .with_stderr(
150 "\
151[CHECKING] foo v0.0.1 ([CWD])
152[RUNNING] `[..] rustc --crate-name example1 [..]`
Chris Wailese3116c42021-07-13 14:40:48 -0700153[FIXING] examples/example1.rs
ThiƩbaud Weksteen5bd94c12021-01-06 15:18:42 +0100154[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
155",
156 )
157 .run();
158}
159
160#[cargo_test]
161fn fix_bin() {
162 full_project()
163 .cargo("fix -v --bin 'bi*1' --allow-no-vcs")
164 .with_stderr(
165 "\
166[CHECKING] foo v0.0.1 ([CWD])
167[RUNNING] `[..] rustc --crate-name bin1 [..]`
Chris Wailese3116c42021-07-13 14:40:48 -0700168[FIXING] src/bin/bin1.rs
ThiƩbaud Weksteen5bd94c12021-01-06 15:18:42 +0100169[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
170",
171 )
172 .run();
173}
174
175#[cargo_test]
176fn fix_bench() {
177 full_project()
178 .cargo("fix -v --bench 'be*1' --allow-no-vcs")
179 .with_stderr(
180 "\
181[CHECKING] foo v0.0.1 ([CWD])
182[RUNNING] `[..] rustc --crate-name bench1 [..]`
Chris Wailese3116c42021-07-13 14:40:48 -0700183[FIXING] benches/bench1.rs
ThiƩbaud Weksteen5bd94c12021-01-06 15:18:42 +0100184[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
185",
186 )
187 .run();
188}
189
190#[cargo_test]
191fn fix_test() {
192 full_project()
193 .cargo("fix -v --test 'te*1' --allow-no-vcs")
194 .with_stderr(
195 "\
196[CHECKING] foo v0.0.1 ([CWD])
197[RUNNING] `[..] rustc --crate-name test1 [..]`
Chris Wailese3116c42021-07-13 14:40:48 -0700198[FIXING] tests/test1.rs
ThiƩbaud Weksteen5bd94c12021-01-06 15:18:42 +0100199[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
200",
201 )
202 .run();
203}
204
205#[cargo_test]
206fn run_example_and_bin() {
207 let p = full_project();
208 p.cargo("run -v --bin 'bi*1'")
209 .with_status(101)
210 .with_stderr("[ERROR] `cargo run` does not support glob patterns on target selection")
211 .run();
212
213 p.cargo("run -v --example 'ex*1'")
214 .with_status(101)
215 .with_stderr("[ERROR] `cargo run` does not support glob patterns on target selection")
216 .run();
217}
218
219#[cargo_test]
220fn test_example() {
221 full_project()
222 .cargo("test -v --example 'ex*1'")
223 .with_stderr(
224 "\
225[COMPILING] foo v0.0.1 ([CWD])
226[RUNNING] `rustc --crate-name example1 [..]`
227[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
228[RUNNING] [..]example1[..]
229",
230 )
231 .run();
232}
233
234#[cargo_test]
235fn test_bin() {
236 full_project()
237 .cargo("test -v --bin 'bi*1'")
238 .with_stderr(
239 "\
240[COMPILING] foo v0.0.1 ([CWD])
241[RUNNING] `rustc --crate-name bin1 [..]`
242[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
243[RUNNING] [..]bin1[..]
244",
245 )
246 .run();
247}
248
249#[cargo_test]
250fn test_bench() {
251 full_project()
252 .cargo("test -v --bench 'be*1'")
253 .with_stderr_contains("[RUNNING] `rustc --crate-name bench1 [..]`")
254 .with_stderr_contains("[RUNNING] `rustc --crate-name bin2 [..]`")
255 .with_stderr_contains("[RUNNING] `rustc --crate-name bin1 [..]`")
256 .with_stderr_contains("[RUNNING] `rustc --crate-name foo [..]`")
257 .with_stderr(
258 "\
259[COMPILING] foo v0.0.1 ([CWD])
260[RUNNING] `rustc --crate-name [..]`
261[RUNNING] `rustc --crate-name [..]`
262[RUNNING] `rustc --crate-name [..]`
263[RUNNING] `rustc --crate-name [..]`
264[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
265[RUNNING] [..]bench1[..]
266",
267 )
268 .run();
269}
270
271#[cargo_test]
272fn test_test() {
273 full_project()
274 .cargo("test -v --test 'te*1'")
275 .with_stderr_contains("[RUNNING] `rustc --crate-name test1 [..]`")
276 .with_stderr_contains("[RUNNING] `rustc --crate-name bin2 [..]`")
277 .with_stderr_contains("[RUNNING] `rustc --crate-name bin1 [..]`")
278 .with_stderr_contains("[RUNNING] `rustc --crate-name foo [..]`")
279 .with_stderr(
280 "\
281[COMPILING] foo v0.0.1 ([CWD])
282[RUNNING] `rustc --crate-name [..]`
283[RUNNING] `rustc --crate-name [..]`
284[RUNNING] `rustc --crate-name [..]`
285[RUNNING] `rustc --crate-name [..]`
286[FINISHED] test [unoptimized + debuginfo] target(s) in [..]
287[RUNNING] [..]test1[..]
288",
289 )
290 .run();
291}
292
293#[cargo_test]
294fn bench_example() {
295 full_project()
296 .cargo("bench -v --example 'ex*1'")
297 .with_stderr(
298 "\
299[COMPILING] foo v0.0.1 ([CWD])
300[RUNNING] `rustc --crate-name example1 [..]`
301[FINISHED] bench [optimized] target(s) in [..]
302[RUNNING] `[..]example1[..] --bench`
303",
304 )
305 .run();
306}
307
308#[cargo_test]
309fn bench_bin() {
310 full_project()
311 .cargo("bench -v --bin 'bi*1'")
312 .with_stderr(
313 "\
314[COMPILING] foo v0.0.1 ([CWD])
315[RUNNING] `rustc --crate-name bin1 [..]`
316[FINISHED] bench [optimized] target(s) in [..]
317[RUNNING] `[..]bin1[..] --bench`
318",
319 )
320 .run();
321}
322
323#[cargo_test]
324fn bench_bench() {
325 full_project()
326 .cargo("bench -v --bench 'be*1'")
327 .with_stderr_contains("[RUNNING] `rustc --crate-name bench1 [..]`")
328 .with_stderr_contains("[RUNNING] `rustc --crate-name bin2 [..]`")
329 .with_stderr_contains("[RUNNING] `rustc --crate-name bin1 [..]`")
330 .with_stderr_contains("[RUNNING] `rustc --crate-name foo [..]`")
331 .with_stderr(
332 "\
333[COMPILING] foo v0.0.1 ([CWD])
334[RUNNING] `rustc --crate-name [..]`
335[RUNNING] `rustc --crate-name [..]`
336[RUNNING] `rustc --crate-name [..]`
337[RUNNING] `rustc --crate-name [..]`
338[FINISHED] bench [optimized] target(s) in [..]
339[RUNNING] `[..]bench1[..] --bench`
340",
341 )
342 .run();
343}
344
345#[cargo_test]
346fn bench_test() {
347 full_project()
348 .cargo("bench -v --test 'te*1'")
349 .with_stderr_contains("[RUNNING] `rustc --crate-name test1 [..]`")
350 .with_stderr_contains("[RUNNING] `rustc --crate-name bin2 [..]`")
351 .with_stderr_contains("[RUNNING] `rustc --crate-name bin1 [..]`")
352 .with_stderr_contains("[RUNNING] `rustc --crate-name foo [..]`")
353 .with_stderr(
354 "\
355[COMPILING] foo v0.0.1 ([CWD])
356[RUNNING] `rustc --crate-name [..]`
357[RUNNING] `rustc --crate-name [..]`
358[RUNNING] `rustc --crate-name [..]`
359[RUNNING] `rustc --crate-name [..]`
360[FINISHED] bench [optimized] target(s) in [..]
361[RUNNING] `[..]test1[..] --bench`
362",
363 )
364 .run();
365}
366
367#[cargo_test]
368fn install_example() {
369 full_project()
370 .cargo("install --path . --example 'ex*1'")
371 .with_stderr(
372 "\
373[INSTALLING] foo v0.0.1 ([CWD])
374[COMPILING] foo v0.0.1 ([CWD])
375[FINISHED] release [optimized] target(s) in [..]
376[INSTALLING] [..]/home/.cargo/bin/example1[EXE]
377[INSTALLED] package `foo v0.0.1 ([CWD])` (executable `example1[EXE]`)
378[WARNING] be sure to add [..]
379",
380 )
381 .run();
382}
383
384#[cargo_test]
385fn install_bin() {
386 full_project()
387 .cargo("install --path . --bin 'bi*1'")
388 .with_stderr(
389 "\
390[INSTALLING] foo v0.0.1 ([CWD])
391[COMPILING] foo v0.0.1 ([CWD])
392[FINISHED] release [optimized] target(s) in [..]
393[INSTALLING] [..]/home/.cargo/bin/bin1[EXE]
394[INSTALLED] package `foo v0.0.1 ([CWD])` (executable `bin1[EXE]`)
395[WARNING] be sure to add [..]
396",
397 )
398 .run();
399}
400
401#[cargo_test]
402fn rustdoc_example() {
403 full_project()
404 .cargo("rustdoc -v --example 'ex*1'")
405 .with_stderr(
406 "\
407[DOCUMENTING] foo v0.0.1 ([CWD])
408[RUNNING] `rustdoc --crate-type bin --crate-name example1 [..]`
409[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
410",
411 )
412 .run();
413}
414
415#[cargo_test]
416fn rustdoc_bin() {
417 full_project()
418 .cargo("rustdoc -v --bin 'bi*1'")
419 .with_stderr(
420 "\
421[DOCUMENTING] foo v0.0.1 ([CWD])
422[RUNNING] `rustdoc --crate-type bin --crate-name bin1 [..]`
423[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
424",
425 )
426 .run();
427}
428
429#[cargo_test]
430fn rustdoc_bench() {
431 full_project()
432 .cargo("rustdoc -v --bench 'be*1'")
433 .with_stderr(
434 "\
435[DOCUMENTING] foo v0.0.1 ([CWD])
436[RUNNING] `rustdoc --crate-type bin --crate-name bench1 [..]`
437[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
438",
439 )
440 .run();
441}
442
443#[cargo_test]
444fn rustdoc_test() {
445 full_project()
446 .cargo("rustdoc -v --test 'te*1'")
447 .with_stderr(
448 "\
449[DOCUMENTING] foo v0.0.1 ([CWD])
450[RUNNING] `rustdoc --crate-type bin --crate-name test1 [..]`
451[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
452",
453 )
454 .run();
455}
456
457#[cargo_test]
458fn rustc_example() {
459 full_project()
460 .cargo("rustc -v --example 'ex*1'")
461 .with_stderr(
462 "\
463[COMPILING] foo v0.0.1 ([CWD])
464[RUNNING] `rustc --crate-name example1 [..]`
465[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
466",
467 )
468 .run();
469}
470
471#[cargo_test]
472fn rustc_bin() {
473 full_project()
474 .cargo("rustc -v --bin 'bi*1'")
475 .with_stderr(
476 "\
477[COMPILING] foo v0.0.1 ([CWD])
478[RUNNING] `rustc --crate-name bin1 [..]`
479[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
480",
481 )
482 .run();
483}
484
485#[cargo_test]
486fn rustc_bench() {
487 full_project()
488 .cargo("rustc -v --bench 'be*1'")
489 .with_stderr_contains("[RUNNING] `rustc --crate-name bench1 [..]`")
490 .with_stderr_contains("[RUNNING] `rustc --crate-name bin2 [..]`")
491 .with_stderr_contains("[RUNNING] `rustc --crate-name bin1 [..]`")
492 .with_stderr_contains("[RUNNING] `rustc --crate-name foo [..]`")
493 .with_stderr(
494 "\
495[COMPILING] foo v0.0.1 ([CWD])
496[RUNNING] `rustc --crate-name [..]`
497[RUNNING] `rustc --crate-name [..]`
498[RUNNING] `rustc --crate-name [..]`
499[RUNNING] `rustc --crate-name [..]`
500[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
501",
502 )
503 .run();
504}
505
506#[cargo_test]
507fn rustc_test() {
508 full_project()
509 .cargo("rustc -v --test 'te*1'")
510 .with_stderr_contains("[RUNNING] `rustc --crate-name test1 [..]`")
511 .with_stderr_contains("[RUNNING] `rustc --crate-name bin2 [..]`")
512 .with_stderr_contains("[RUNNING] `rustc --crate-name bin1 [..]`")
513 .with_stderr_contains("[RUNNING] `rustc --crate-name foo [..]`")
514 .with_stderr(
515 "\
516[COMPILING] foo v0.0.1 ([CWD])
517[RUNNING] `rustc --crate-name [..]`
518[RUNNING] `rustc --crate-name [..]`
519[RUNNING] `rustc --crate-name [..]`
520[RUNNING] `rustc --crate-name [..]`
521[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
522",
523 )
524 .run();
525}
526
527fn full_project() -> Project {
528 project()
529 .file("examples/example1.rs", "fn main() { }")
530 .file("examples/example2.rs", "fn main() { }")
531 .file("benches/bench1.rs", "")
532 .file("benches/bench2.rs", "")
533 .file("tests/test1.rs", "")
534 .file("tests/test2.rs", "")
535 .file("src/main.rs", "fn main() { }")
536 .file("src/bin/bin1.rs", "fn main() { }")
537 .file("src/bin/bin2.rs", "fn main() { }")
538 .build()
539}