]> git.proxmox.com Git - cargo.git/blob - tests/testsuite/path.rs
1b8f2bf20bed249f70525d3dc0eb186dd07e5b49
[cargo.git] / tests / testsuite / path.rs
1 //! Tests for `path` dependencies.
2
3 use cargo_test_support::paths::{self, CargoPathExt};
4 use cargo_test_support::registry::Package;
5 use cargo_test_support::{basic_lib_manifest, basic_manifest, main_file, project};
6 use cargo_test_support::{sleep_ms, t};
7 use std::fs;
8
9 #[cargo_test]
10 // I have no idea why this is failing spuriously on Windows;
11 // for more info, see #3466.
12 #[cfg(not(windows))]
13 fn cargo_compile_with_nested_deps_shorthand() {
14 let p = project()
15 .file(
16 "Cargo.toml",
17 r#"
18 [project]
19
20 name = "foo"
21 version = "0.5.0"
22 authors = ["wycats@example.com"]
23
24 [dependencies.bar]
25
26 version = "0.5.0"
27 path = "bar"
28 "#,
29 )
30 .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
31 .file(
32 "bar/Cargo.toml",
33 r#"
34 [project]
35
36 name = "bar"
37 version = "0.5.0"
38 authors = ["wycats@example.com"]
39
40 [dependencies.baz]
41
42 version = "0.5.0"
43 path = "baz"
44
45 [lib]
46
47 name = "bar"
48 "#,
49 )
50 .file(
51 "bar/src/bar.rs",
52 r#"
53 extern crate baz;
54
55 pub fn gimme() -> String {
56 baz::gimme()
57 }
58 "#,
59 )
60 .file("bar/baz/Cargo.toml", &basic_lib_manifest("baz"))
61 .file(
62 "bar/baz/src/baz.rs",
63 r#"
64 pub fn gimme() -> String {
65 "test passed".to_string()
66 }
67 "#,
68 )
69 .build();
70
71 p.cargo("build")
72 .with_stderr(
73 "[COMPILING] baz v0.5.0 ([CWD]/bar/baz)\n\
74 [COMPILING] bar v0.5.0 ([CWD]/bar)\n\
75 [COMPILING] foo v0.5.0 ([CWD])\n\
76 [FINISHED] dev [unoptimized + debuginfo] target(s) \
77 in [..]\n",
78 )
79 .run();
80
81 assert!(p.bin("foo").is_file());
82
83 p.process(&p.bin("foo")).with_stdout("test passed\n").run();
84
85 println!("cleaning");
86 p.cargo("clean -v").with_stdout("").run();
87 println!("building baz");
88 p.cargo("build -p baz")
89 .with_stderr(
90 "[COMPILING] baz v0.5.0 ([CWD]/bar/baz)\n\
91 [FINISHED] dev [unoptimized + debuginfo] target(s) \
92 in [..]\n",
93 )
94 .run();
95 println!("building foo");
96 p.cargo("build -p foo")
97 .with_stderr(
98 "[COMPILING] bar v0.5.0 ([CWD]/bar)\n\
99 [COMPILING] foo v0.5.0 ([CWD])\n\
100 [FINISHED] dev [unoptimized + debuginfo] target(s) \
101 in [..]\n",
102 )
103 .run();
104 }
105
106 #[cargo_test]
107 fn cargo_compile_with_root_dev_deps() {
108 let p = project()
109 .file(
110 "Cargo.toml",
111 r#"
112 [project]
113
114 name = "foo"
115 version = "0.5.0"
116 authors = ["wycats@example.com"]
117
118 [dev-dependencies.bar]
119
120 version = "0.5.0"
121 path = "../bar"
122
123 [[bin]]
124 name = "foo"
125 "#,
126 )
127 .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
128 .build();
129 let _p2 = project()
130 .at("bar")
131 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
132 .file(
133 "src/lib.rs",
134 r#"
135 pub fn gimme() -> &'static str {
136 "zoidberg"
137 }
138 "#,
139 )
140 .build();
141
142 p.cargo("build")
143 .with_status(101)
144 .with_stderr_contains("[..]can't find crate for `bar`")
145 .run();
146 }
147
148 #[cargo_test]
149 fn cargo_compile_with_root_dev_deps_with_testing() {
150 let p = project()
151 .file(
152 "Cargo.toml",
153 r#"
154 [project]
155
156 name = "foo"
157 version = "0.5.0"
158 authors = ["wycats@example.com"]
159
160 [dev-dependencies.bar]
161
162 version = "0.5.0"
163 path = "../bar"
164
165 [[bin]]
166 name = "foo"
167 "#,
168 )
169 .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
170 .build();
171 let _p2 = project()
172 .at("bar")
173 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
174 .file(
175 "src/lib.rs",
176 r#"
177 pub fn gimme() -> &'static str {
178 "zoidberg"
179 }
180 "#,
181 )
182 .build();
183
184 p.cargo("test")
185 .with_stderr(
186 "\
187 [COMPILING] [..] v0.5.0 ([..])
188 [COMPILING] [..] v0.5.0 ([..])
189 [FINISHED] test [unoptimized + debuginfo] target(s) in [..]
190 [RUNNING] [..] (target/debug/deps/foo-[..][EXE])",
191 )
192 .with_stdout_contains("running 0 tests")
193 .run();
194 }
195
196 #[cargo_test]
197 fn cargo_compile_with_transitive_dev_deps() {
198 let p = project()
199 .file(
200 "Cargo.toml",
201 r#"
202 [project]
203
204 name = "foo"
205 version = "0.5.0"
206 authors = ["wycats@example.com"]
207
208 [dependencies.bar]
209
210 version = "0.5.0"
211 path = "bar"
212 "#,
213 )
214 .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
215 .file(
216 "bar/Cargo.toml",
217 r#"
218 [project]
219
220 name = "bar"
221 version = "0.5.0"
222 authors = ["wycats@example.com"]
223
224 [dev-dependencies.baz]
225
226 git = "git://example.com/path/to/nowhere"
227
228 [lib]
229
230 name = "bar"
231 "#,
232 )
233 .file(
234 "bar/src/bar.rs",
235 r#"
236 pub fn gimme() -> &'static str {
237 "zoidberg"
238 }
239 "#,
240 )
241 .build();
242
243 p.cargo("build")
244 .with_stderr(
245 "[COMPILING] bar v0.5.0 ([CWD]/bar)\n\
246 [COMPILING] foo v0.5.0 ([CWD])\n\
247 [FINISHED] dev [unoptimized + debuginfo] target(s) in \
248 [..]\n",
249 )
250 .run();
251
252 assert!(p.bin("foo").is_file());
253
254 p.process(&p.bin("foo")).with_stdout("zoidberg\n").run();
255 }
256
257 #[cargo_test]
258 fn no_rebuild_dependency() {
259 let p = project()
260 .file(
261 "Cargo.toml",
262 r#"
263 [project]
264
265 name = "foo"
266 version = "0.5.0"
267 authors = ["wycats@example.com"]
268
269 [dependencies.bar]
270 path = "bar"
271 "#,
272 )
273 .file("src/main.rs", "extern crate bar; fn main() { bar::bar() }")
274 .file("bar/Cargo.toml", &basic_lib_manifest("bar"))
275 .file("bar/src/bar.rs", "pub fn bar() {}")
276 .build();
277 // First time around we should compile both foo and bar
278 p.cargo("build")
279 .with_stderr(
280 "[COMPILING] bar v0.5.0 ([CWD]/bar)\n\
281 [COMPILING] foo v0.5.0 ([CWD])\n\
282 [FINISHED] dev [unoptimized + debuginfo] target(s) \
283 in [..]\n",
284 )
285 .run();
286
287 sleep_ms(1000);
288 p.change_file(
289 "src/main.rs",
290 r#"
291 extern crate bar;
292 fn main() { bar::bar(); }
293 "#,
294 );
295 // Don't compile bar, but do recompile foo.
296 p.cargo("build")
297 .with_stderr(
298 "[COMPILING] foo v0.5.0 ([..])\n\
299 [FINISHED] dev [unoptimized + debuginfo] target(s) \
300 in [..]\n",
301 )
302 .run();
303 }
304
305 #[cargo_test]
306 fn deep_dependencies_trigger_rebuild() {
307 let p = project()
308 .file(
309 "Cargo.toml",
310 r#"
311 [project]
312
313 name = "foo"
314 version = "0.5.0"
315 authors = ["wycats@example.com"]
316
317 [dependencies.bar]
318 path = "bar"
319 "#,
320 )
321 .file("src/main.rs", "extern crate bar; fn main() { bar::bar() }")
322 .file(
323 "bar/Cargo.toml",
324 r#"
325 [project]
326
327 name = "bar"
328 version = "0.5.0"
329 authors = ["wycats@example.com"]
330
331 [lib]
332 name = "bar"
333 [dependencies.baz]
334 path = "../baz"
335 "#,
336 )
337 .file(
338 "bar/src/bar.rs",
339 "extern crate baz; pub fn bar() { baz::baz() }",
340 )
341 .file("baz/Cargo.toml", &basic_lib_manifest("baz"))
342 .file("baz/src/baz.rs", "pub fn baz() {}")
343 .build();
344 p.cargo("build")
345 .with_stderr(
346 "[COMPILING] baz v0.5.0 ([CWD]/baz)\n\
347 [COMPILING] bar v0.5.0 ([CWD]/bar)\n\
348 [COMPILING] foo v0.5.0 ([CWD])\n\
349 [FINISHED] dev [unoptimized + debuginfo] target(s) \
350 in [..]\n",
351 )
352 .run();
353 p.cargo("build").with_stdout("").run();
354
355 // Make sure an update to baz triggers a rebuild of bar
356 //
357 // We base recompilation off mtime, so sleep for at least a second to ensure
358 // that this write will change the mtime.
359 sleep_ms(1000);
360 p.change_file("baz/src/baz.rs", r#"pub fn baz() { println!("hello!"); }"#);
361 sleep_ms(1000);
362 p.cargo("build")
363 .with_stderr(
364 "[COMPILING] baz v0.5.0 ([CWD]/baz)\n\
365 [COMPILING] bar v0.5.0 ([CWD]/bar)\n\
366 [COMPILING] foo v0.5.0 ([CWD])\n\
367 [FINISHED] dev [unoptimized + debuginfo] target(s) \
368 in [..]\n",
369 )
370 .run();
371
372 // Make sure an update to bar doesn't trigger baz
373 sleep_ms(1000);
374 p.change_file(
375 "bar/src/bar.rs",
376 r#"
377 extern crate baz;
378 pub fn bar() { println!("hello!"); baz::baz(); }
379 "#,
380 );
381 sleep_ms(1000);
382 p.cargo("build")
383 .with_stderr(
384 "[COMPILING] bar v0.5.0 ([CWD]/bar)\n\
385 [COMPILING] foo v0.5.0 ([CWD])\n\
386 [FINISHED] dev [unoptimized + debuginfo] target(s) \
387 in [..]\n",
388 )
389 .run();
390 }
391
392 #[cargo_test]
393 fn no_rebuild_two_deps() {
394 let p = project()
395 .file(
396 "Cargo.toml",
397 r#"
398 [project]
399
400 name = "foo"
401 version = "0.5.0"
402 authors = ["wycats@example.com"]
403
404 [dependencies.bar]
405 path = "bar"
406 [dependencies.baz]
407 path = "baz"
408 "#,
409 )
410 .file("src/main.rs", "extern crate bar; fn main() { bar::bar() }")
411 .file(
412 "bar/Cargo.toml",
413 r#"
414 [project]
415
416 name = "bar"
417 version = "0.5.0"
418 authors = ["wycats@example.com"]
419
420 [lib]
421 name = "bar"
422 [dependencies.baz]
423 path = "../baz"
424 "#,
425 )
426 .file("bar/src/bar.rs", "pub fn bar() {}")
427 .file("baz/Cargo.toml", &basic_lib_manifest("baz"))
428 .file("baz/src/baz.rs", "pub fn baz() {}")
429 .build();
430 p.cargo("build")
431 .with_stderr(
432 "[COMPILING] baz v0.5.0 ([CWD]/baz)\n\
433 [COMPILING] bar v0.5.0 ([CWD]/bar)\n\
434 [COMPILING] foo v0.5.0 ([CWD])\n\
435 [FINISHED] dev [unoptimized + debuginfo] target(s) \
436 in [..]\n",
437 )
438 .run();
439 assert!(p.bin("foo").is_file());
440 p.cargo("build").with_stdout("").run();
441 assert!(p.bin("foo").is_file());
442 }
443
444 #[cargo_test]
445 fn nested_deps_recompile() {
446 let p = project()
447 .file(
448 "Cargo.toml",
449 r#"
450 [project]
451
452 name = "foo"
453 version = "0.5.0"
454 authors = ["wycats@example.com"]
455
456 [dependencies.bar]
457
458 version = "0.5.0"
459 path = "src/bar"
460 "#,
461 )
462 .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
463 .file("src/bar/Cargo.toml", &basic_lib_manifest("bar"))
464 .file("src/bar/src/bar.rs", "pub fn gimme() -> i32 { 92 }")
465 .build();
466
467 p.cargo("build")
468 .with_stderr(
469 "[COMPILING] bar v0.5.0 ([CWD]/src/bar)\n\
470 [COMPILING] foo v0.5.0 ([CWD])\n\
471 [FINISHED] dev [unoptimized + debuginfo] target(s) \
472 in [..]\n",
473 )
474 .run();
475 sleep_ms(1000);
476
477 p.change_file("src/main.rs", r#"fn main() {}"#);
478
479 // This shouldn't recompile `bar`
480 p.cargo("build")
481 .with_stderr(
482 "[COMPILING] foo v0.5.0 ([CWD])\n\
483 [FINISHED] dev [unoptimized + debuginfo] target(s) \
484 in [..]\n",
485 )
486 .run();
487 }
488
489 #[cargo_test]
490 fn error_message_for_missing_manifest() {
491 let p = project()
492 .file(
493 "Cargo.toml",
494 r#"
495 [project]
496
497 name = "foo"
498 version = "0.5.0"
499 authors = ["wycats@example.com"]
500
501 [dependencies.bar]
502
503 path = "src/bar"
504 "#,
505 )
506 .file("src/lib.rs", "")
507 .file("src/bar/not-a-manifest", "")
508 .build();
509
510 p.cargo("build")
511 .with_status(101)
512 .with_stderr(
513 "\
514 [ERROR] failed to get `bar` as a dependency of package `foo v0.5.0 [..]`
515
516 Caused by:
517 failed to load source for dependency `bar`
518
519 Caused by:
520 Unable to update [CWD]/src/bar
521
522 Caused by:
523 failed to read `[..]bar/Cargo.toml`
524
525 Caused by:
526 [..] (os error [..])
527 ",
528 )
529 .run();
530 }
531
532 #[cargo_test]
533 fn override_relative() {
534 let bar = project()
535 .at("bar")
536 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
537 .file("src/lib.rs", "")
538 .build();
539
540 fs::create_dir(&paths::root().join(".cargo")).unwrap();
541 fs::write(&paths::root().join(".cargo/config"), r#"paths = ["bar"]"#).unwrap();
542
543 let p = project()
544 .file(
545 "Cargo.toml",
546 &format!(
547 r#"
548 [package]
549
550 name = "foo"
551 version = "0.5.0"
552 authors = ["wycats@example.com"]
553
554 [dependencies.bar]
555 path = '{}'
556 "#,
557 bar.root().display()
558 ),
559 )
560 .file("src/lib.rs", "")
561 .build();
562 p.cargo("build -v").run();
563 }
564
565 #[cargo_test]
566 fn override_self() {
567 let bar = project()
568 .at("bar")
569 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
570 .file("src/lib.rs", "")
571 .build();
572
573 let p = project();
574 let root = p.root();
575 let p = p
576 .file(".cargo/config", &format!("paths = ['{}']", root.display()))
577 .file(
578 "Cargo.toml",
579 &format!(
580 r#"
581 [package]
582
583 name = "foo"
584 version = "0.5.0"
585 authors = ["wycats@example.com"]
586
587 [dependencies.bar]
588 path = '{}'
589
590 "#,
591 bar.root().display()
592 ),
593 )
594 .file("src/lib.rs", "")
595 .file("src/main.rs", "fn main() {}")
596 .build();
597
598 p.cargo("build").run();
599 }
600
601 #[cargo_test]
602 fn override_path_dep() {
603 let bar = project()
604 .at("bar")
605 .file(
606 "p1/Cargo.toml",
607 r#"
608 [package]
609 name = "p1"
610 version = "0.5.0"
611 authors = []
612
613 [dependencies.p2]
614 path = "../p2"
615 "#,
616 )
617 .file("p1/src/lib.rs", "")
618 .file("p2/Cargo.toml", &basic_manifest("p2", "0.5.0"))
619 .file("p2/src/lib.rs", "")
620 .build();
621
622 let p = project()
623 .file(
624 ".cargo/config",
625 &format!(
626 "paths = ['{}', '{}']",
627 bar.root().join("p1").display(),
628 bar.root().join("p2").display()
629 ),
630 )
631 .file(
632 "Cargo.toml",
633 &format!(
634 r#"
635 [package]
636
637 name = "foo"
638 version = "0.5.0"
639 authors = ["wycats@example.com"]
640
641 [dependencies.p2]
642 path = '{}'
643
644 "#,
645 bar.root().join("p2").display()
646 ),
647 )
648 .file("src/lib.rs", "")
649 .build();
650
651 p.cargo("build -v").run();
652 }
653
654 #[cargo_test]
655 fn path_dep_build_cmd() {
656 let p = project()
657 .file(
658 "Cargo.toml",
659 r#"
660 [project]
661
662 name = "foo"
663 version = "0.5.0"
664 authors = ["wycats@example.com"]
665
666 [dependencies.bar]
667
668 version = "0.5.0"
669 path = "bar"
670 "#,
671 )
672 .file("src/main.rs", &main_file(r#""{}", bar::gimme()"#, &["bar"]))
673 .file(
674 "bar/Cargo.toml",
675 r#"
676 [project]
677
678 name = "bar"
679 version = "0.5.0"
680 authors = ["wycats@example.com"]
681 build = "build.rs"
682
683 [lib]
684 name = "bar"
685 path = "src/bar.rs"
686 "#,
687 )
688 .file(
689 "bar/build.rs",
690 r#"
691 use std::fs;
692 fn main() {
693 fs::copy("src/bar.rs.in", "src/bar.rs").unwrap();
694 }
695 "#,
696 )
697 .file("bar/src/bar.rs.in", "pub fn gimme() -> i32 { 0 }")
698 .build();
699 p.root().join("bar").move_into_the_past();
700
701 p.cargo("build")
702 .with_stderr(
703 "[COMPILING] bar v0.5.0 ([CWD]/bar)\n\
704 [COMPILING] foo v0.5.0 ([CWD])\n\
705 [FINISHED] dev [unoptimized + debuginfo] target(s) in \
706 [..]\n",
707 )
708 .run();
709
710 assert!(p.bin("foo").is_file());
711
712 p.process(&p.bin("foo")).with_stdout("0\n").run();
713
714 // Touching bar.rs.in should cause the `build` command to run again.
715 p.change_file("bar/src/bar.rs.in", "pub fn gimme() -> i32 { 1 }");
716
717 p.cargo("build")
718 .with_stderr(
719 "[COMPILING] bar v0.5.0 ([CWD]/bar)\n\
720 [COMPILING] foo v0.5.0 ([CWD])\n\
721 [FINISHED] dev [unoptimized + debuginfo] target(s) in \
722 [..]\n",
723 )
724 .run();
725
726 p.process(&p.bin("foo")).with_stdout("1\n").run();
727 }
728
729 #[cargo_test]
730 fn dev_deps_no_rebuild_lib() {
731 let p = project()
732 .file(
733 "Cargo.toml",
734 r#"
735 [project]
736 name = "foo"
737 version = "0.5.0"
738 authors = []
739
740 [dev-dependencies.bar]
741 path = "bar"
742
743 [lib]
744 name = "foo"
745 doctest = false
746 "#,
747 )
748 .file(
749 "src/lib.rs",
750 r#"
751 #[cfg(test)] #[allow(unused_extern_crates)] extern crate bar;
752 #[cfg(not(test))] pub fn foo() { env!("FOO"); }
753 "#,
754 )
755 .file("bar/Cargo.toml", &basic_manifest("bar", "0.5.0"))
756 .file("bar/src/lib.rs", "pub fn bar() {}")
757 .build();
758 p.cargo("build")
759 .env("FOO", "bar")
760 .with_stderr(
761 "[COMPILING] foo v0.5.0 ([CWD])\n\
762 [FINISHED] dev [unoptimized + debuginfo] target(s) \
763 in [..]\n",
764 )
765 .run();
766
767 p.cargo("test")
768 .with_stderr(
769 "\
770 [COMPILING] [..] v0.5.0 ([CWD][..])
771 [COMPILING] [..] v0.5.0 ([CWD][..])
772 [FINISHED] test [unoptimized + debuginfo] target(s) in [..]
773 [RUNNING] [..] (target/debug/deps/foo-[..][EXE])",
774 )
775 .with_stdout_contains("running 0 tests")
776 .run();
777 }
778
779 #[cargo_test]
780 fn custom_target_no_rebuild() {
781 let p = project()
782 .file(
783 "Cargo.toml",
784 r#"
785 [project]
786 name = "foo"
787 version = "0.5.0"
788 authors = []
789 [dependencies]
790 a = { path = "a" }
791 [workspace]
792 members = ["a", "b"]
793 "#,
794 )
795 .file("src/lib.rs", "")
796 .file("a/Cargo.toml", &basic_manifest("a", "0.5.0"))
797 .file("a/src/lib.rs", "")
798 .file(
799 "b/Cargo.toml",
800 r#"
801 [project]
802 name = "b"
803 version = "0.5.0"
804 authors = []
805 [dependencies]
806 a = { path = "../a" }
807 "#,
808 )
809 .file("b/src/lib.rs", "")
810 .build();
811 p.cargo("build")
812 .with_stderr(
813 "\
814 [COMPILING] a v0.5.0 ([..])
815 [COMPILING] foo v0.5.0 ([..])
816 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
817 ",
818 )
819 .run();
820
821 t!(fs::rename(
822 p.root().join("target"),
823 p.root().join("target_moved")
824 ));
825 p.cargo("build --manifest-path=b/Cargo.toml")
826 .env("CARGO_TARGET_DIR", "target_moved")
827 .with_stderr(
828 "\
829 [COMPILING] b v0.5.0 ([..])
830 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
831 ",
832 )
833 .run();
834 }
835
836 #[cargo_test]
837 fn override_and_depend() {
838 let p = project()
839 .no_manifest()
840 .file(
841 "a/a1/Cargo.toml",
842 r#"
843 [project]
844 name = "a1"
845 version = "0.5.0"
846 authors = []
847 [dependencies]
848 a2 = { path = "../a2" }
849 "#,
850 )
851 .file("a/a1/src/lib.rs", "")
852 .file("a/a2/Cargo.toml", &basic_manifest("a2", "0.5.0"))
853 .file("a/a2/src/lib.rs", "")
854 .file(
855 "b/Cargo.toml",
856 r#"
857 [project]
858 name = "b"
859 version = "0.5.0"
860 authors = []
861 [dependencies]
862 a1 = { path = "../a/a1" }
863 a2 = { path = "../a/a2" }
864 "#,
865 )
866 .file("b/src/lib.rs", "")
867 .file("b/.cargo/config", r#"paths = ["../a"]"#)
868 .build();
869 p.cargo("build")
870 .cwd("b")
871 .with_stderr(
872 "\
873 [WARNING] skipping duplicate package `a2` found at `[..]`
874 [COMPILING] a2 v0.5.0 ([..])
875 [COMPILING] a1 v0.5.0 ([..])
876 [COMPILING] b v0.5.0 ([..])
877 [FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
878 ",
879 )
880 .run();
881 }
882
883 #[cargo_test]
884 fn missing_path_dependency() {
885 let p = project()
886 .file("Cargo.toml", &basic_manifest("a", "0.5.0"))
887 .file("src/lib.rs", "")
888 .file(
889 ".cargo/config",
890 r#"paths = ["../whoa-this-does-not-exist"]"#,
891 )
892 .build();
893 p.cargo("build")
894 .with_status(101)
895 .with_stderr(
896 "\
897 [ERROR] failed to update path override `[..]../whoa-this-does-not-exist` \
898 (defined in `[..]`)
899
900 Caused by:
901 failed to read directory `[..]`
902
903 Caused by:
904 [..] (os error [..])
905 ",
906 )
907 .run();
908 }
909
910 #[cargo_test]
911 fn invalid_path_dep_in_workspace_with_lockfile() {
912 Package::new("bar", "1.0.0").publish();
913
914 let p = project()
915 .file(
916 "Cargo.toml",
917 r#"
918 [project]
919 name = "top"
920 version = "0.5.0"
921 authors = []
922
923 [workspace]
924
925 [dependencies]
926 foo = { path = "foo" }
927 "#,
928 )
929 .file("src/lib.rs", "")
930 .file(
931 "foo/Cargo.toml",
932 r#"
933 [project]
934 name = "foo"
935 version = "0.5.0"
936 authors = []
937
938 [dependencies]
939 bar = "*"
940 "#,
941 )
942 .file("foo/src/lib.rs", "")
943 .build();
944
945 // Generate a lock file
946 p.cargo("build").run();
947
948 // Change the dependency on `bar` to an invalid path
949 p.change_file(
950 "foo/Cargo.toml",
951 r#"
952 [project]
953 name = "foo"
954 version = "0.5.0"
955 authors = []
956
957 [dependencies]
958 bar = { path = "" }
959 "#,
960 );
961
962 // Make sure we get a nice error. In the past this actually stack
963 // overflowed!
964 p.cargo("build")
965 .with_status(101)
966 .with_stderr(
967 "\
968 error: no matching package found
969 searched package name: `bar`
970 perhaps you meant: foo
971 location searched: [..]
972 required by package `foo v0.5.0 ([..])`
973 ",
974 )
975 .run();
976 }
977
978 #[cargo_test]
979 fn workspace_produces_rlib() {
980 let p = project()
981 .file(
982 "Cargo.toml",
983 r#"
984 [project]
985 name = "top"
986 version = "0.5.0"
987 authors = []
988
989 [workspace]
990
991 [dependencies]
992 foo = { path = "foo" }
993 "#,
994 )
995 .file("src/lib.rs", "")
996 .file("foo/Cargo.toml", &basic_manifest("foo", "0.5.0"))
997 .file("foo/src/lib.rs", "")
998 .build();
999
1000 p.cargo("build").run();
1001
1002 assert!(p.root().join("target/debug/libtop.rlib").is_file());
1003 assert!(!p.root().join("target/debug/libfoo.rlib").is_file());
1004 }
1005
1006 #[cargo_test]
1007 fn deep_path_error() {
1008 // Test for an error loading a path deep in the dependency graph.
1009 let p = project()
1010 .file(
1011 "Cargo.toml",
1012 r#"
1013 [package]
1014 name = "foo"
1015 version = "0.1.0"
1016 [dependencies]
1017 a = {path="a"}
1018 "#,
1019 )
1020 .file("src/lib.rs", "")
1021 .file(
1022 "a/Cargo.toml",
1023 r#"
1024 [package]
1025 name = "a"
1026 version = "0.1.0"
1027 [dependencies]
1028 b = {path="../b"}
1029 "#,
1030 )
1031 .file("a/src/lib.rs", "")
1032 .file(
1033 "b/Cargo.toml",
1034 r#"
1035 [package]
1036 name = "b"
1037 version = "0.1.0"
1038 [dependencies]
1039 c = {path="../c"}
1040 "#,
1041 )
1042 .file("b/src/lib.rs", "")
1043 .build();
1044
1045 p.cargo("check")
1046 .with_status(101)
1047 .with_stderr(
1048 "\
1049 [ERROR] failed to get `c` as a dependency of package `b v0.1.0 [..]`
1050 ... which satisfies path dependency `b` of package `a v0.1.0 [..]`
1051 ... which satisfies path dependency `a` of package `foo v0.1.0 [..]`
1052
1053 Caused by:
1054 failed to load source for dependency `c`
1055
1056 Caused by:
1057 Unable to update [..]/foo/c
1058
1059 Caused by:
1060 failed to read `[..]/foo/c/Cargo.toml`
1061
1062 Caused by:
1063 [..]
1064 ",
1065 )
1066 .run();
1067 }
1068
1069 #[cargo_test]
1070 fn catch_tricky_cycle() {
1071 let p = project()
1072 .file(
1073 "Cargo.toml",
1074 r#"
1075 [package]
1076 name = "message"
1077 version = "0.1.0"
1078
1079 [dev-dependencies]
1080 test = { path = "test" }
1081 "#,
1082 )
1083 .file("src/lib.rs", "")
1084 .file(
1085 "tangle/Cargo.toml",
1086 r#"
1087 [package]
1088 name = "tangle"
1089 version = "0.1.0"
1090
1091 [dependencies]
1092 message = { path = ".." }
1093 snapshot = { path = "../snapshot" }
1094 "#,
1095 )
1096 .file("tangle/src/lib.rs", "")
1097 .file(
1098 "snapshot/Cargo.toml",
1099 r#"
1100 [package]
1101 name = "snapshot"
1102 version = "0.1.0"
1103
1104 [dependencies]
1105 ledger = { path = "../ledger" }
1106 "#,
1107 )
1108 .file("snapshot/src/lib.rs", "")
1109 .file(
1110 "ledger/Cargo.toml",
1111 r#"
1112 [package]
1113 name = "ledger"
1114 version = "0.1.0"
1115
1116 [dependencies]
1117 tangle = { path = "../tangle" }
1118 "#,
1119 )
1120 .file("ledger/src/lib.rs", "")
1121 .file(
1122 "test/Cargo.toml",
1123 r#"
1124 [package]
1125 name = "test"
1126 version = "0.1.0"
1127
1128 [dependencies]
1129 snapshot = { path = "../snapshot" }
1130 "#,
1131 )
1132 .file("test/src/lib.rs", "")
1133 .build();
1134
1135 p.cargo("test")
1136 .with_stderr_contains("[..]cyclic package dependency[..]")
1137 .with_status(101)
1138 .run();
1139 }