1 //! Tests for `path` dependencies.
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}
;
10 // I have no idea why this is failing spuriously on Windows;
11 // for more info, see #3466.
13 fn cargo_compile_with_nested_deps_shorthand() {
22 authors = ["wycats@example.com"]
30 .file("src/main.rs", &main_file(r
#""{}", bar::gimme()"#, &["bar"]))
38 authors = ["wycats@example.com"]
55 pub fn gimme() -> String {
60 .file("bar/baz/Cargo.toml", &basic_lib_manifest("baz"))
64 pub fn gimme() -> String {
65 "test passed".to_string()
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) \
81 assert
!(p
.bin("foo").is_file());
83 p
.process(&p
.bin("foo")).with_stdout("test passed\n").run();
86 p
.cargo("clean -v").with_stdout("").run();
87 println
!("building baz");
88 p
.cargo("build -p baz")
90 "[COMPILING] baz v0.5.0 ([CWD]/bar/baz)\n\
91 [FINISHED] dev [unoptimized + debuginfo] target(s) \
95 println
!("building foo");
96 p
.cargo("build -p foo")
98 "[COMPILING] bar v0.5.0 ([CWD]/bar)\n\
99 [COMPILING] foo v0.5.0 ([CWD])\n\
100 [FINISHED] dev [unoptimized + debuginfo] target(s) \
107 fn cargo_compile_with_root_dev_deps() {
116 authors = ["wycats@example.com"]
118 [dev-dependencies.bar]
127 .file("src/main.rs", &main_file(r
#""{}", bar::gimme()"#, &["bar"]))
131 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
135 pub fn gimme() -> &'static str {
144 .with_stderr_contains("[..]can't find crate for `bar`")
149 fn cargo_compile_with_root_dev_deps_with_testing() {
158 authors = ["wycats@example.com"]
160 [dev-dependencies.bar]
169 .file("src/main.rs", &main_file(r
#""{}", bar::gimme()"#, &["bar"]))
173 .file("Cargo.toml", &basic_manifest("bar", "0.5.0"))
177 pub fn gimme() -> &'static str {
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])",
192 .with_stdout_contains("running 0 tests")
197 fn cargo_compile_with_transitive_dev_deps() {
206 authors = ["wycats@example.com"]
214 .file("src/main.rs", &main_file(r
#""{}", bar::gimme()"#, &["bar"]))
222 authors = ["wycats@example.com"]
224 [dev-dependencies.baz]
226 git = "git://example.com/path/to/nowhere"
236 pub fn gimme() -> &'
static str {
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 \
252 assert!(p.bin("foo
").is_file());
254 p.process(&p.bin("foo
")).with_stdout("zoidberg
\n").run();
258 fn no_rebuild_dependency() {
267 authors
= ["wycats@example.com"]
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() {}
")
277 // First time around we should compile both foo and bar
280 "[COMPILING
] bar v0
.5
.0 ([CWD
]/bar
)\n\
281 [COMPILING
] foo v0
.5
.0 ([CWD
])\n\
282 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) \
292 fn main() { bar::bar(); }
295 // Don't compile bar, but do recompile foo.
298 "[COMPILING
] foo v0
.5
.0 ([..])\n\
299 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) \
306 fn deep_dependencies_trigger_rebuild() {
315 authors
= ["wycats@example.com"]
321 .file("src
/main
.rs
", "extern crate bar
; fn main() { bar::bar() }
")
329 authors
= ["wycats@example.com"]
339 "extern crate baz
; pub fn bar() { baz::baz() }
",
341 .file("baz
/Cargo
.toml
", &basic_lib_manifest("baz
"))
342 .file("baz
/src
/baz
.rs
", "pub fn baz() {}
")
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
) \
353 p.cargo("build
").with_stdout("").run();
355 // Make sure an update to baz triggers a rebuild of bar
357 // We base recompilation off mtime, so sleep for at least a second to ensure
358 // that this write will change the mtime.
360 p.change_file("baz
/src
/baz
.rs
", r#"pub fn baz() { println!("hello!"); }
"#);
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
) \
372 // Make sure an update to bar doesn't trigger baz
378 pub fn bar() { println!("hello!"); baz::baz(); }
384 "[COMPILING
] bar v0
.5
.0 ([CWD
]/bar
)\n\
385 [COMPILING
] foo v0
.5
.0 ([CWD
])\n\
386 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) \
393 fn no_rebuild_two_deps() {
402 authors
= ["wycats@example.com"]
410 .file("src
/main
.rs
", "extern crate bar
; fn main() { bar::bar() }
")
418 authors
= ["wycats@example.com"]
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() {}
")
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
) \
439 assert!(p.bin("foo
").is_file());
440 p.cargo("build
").with_stdout("").run();
441 assert!(p.bin("foo
").is_file());
445 fn nested_deps_recompile() {
454 authors
= ["wycats@example.com"]
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 }
")
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
) \
477 p.change_file("src
/main
.rs
", r#"fn main() {}
"#);
479 // This shouldn't recompile `bar`
482 "[COMPILING
] foo v0
.5
.0 ([CWD
])\n\
483 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) \
490 fn error_message_for_missing_manifest() {
499 authors
= ["wycats@example.com"]
506 .file("src
/lib
.rs
", "")
507 .file("src
/bar
/not
-a
-manifest
", "")
514 [ERROR
] failed to get `bar`
as a dependency of package `foo v0
.5
.0 [..]`
517 failed to load source
for dependency `bar`
520 Unable to update
[CWD
]/src
/bar
523 failed to read `
[..]bar
/Cargo
.toml`
533 fn override_relative() {
536 .file("Cargo
.toml
", &basic_manifest("bar
", "0.5.0"))
537 .file("src
/lib
.rs
", "")
540 fs::create_dir(&paths::root().join(".cargo
")).unwrap();
541 fs::write(&paths::root().join(".cargo
/config
"), r#"paths
= ["bar"]"#).unwrap();
552 authors
= ["wycats@example.com"]
560 .file("src
/lib
.rs
", "")
562 p.cargo("build
-v
").run();
569 .file("Cargo
.toml
", &basic_manifest("bar
", "0.5.0"))
570 .file("src
/lib
.rs
", "")
576 .file(".cargo
/config
", &format!("paths
= ['{}'
]", root.display()))
585 authors
= ["wycats@example.com"]
594 .file("src
/lib
.rs
", "")
595 .file("src
/main
.rs
", "fn main() {}
")
598 p.cargo("build
").run();
602 fn override_path_dep() {
617 .file("p1
/src
/lib
.rs
", "")
618 .file("p2
/Cargo
.toml
", &basic_manifest("p2
", "0.5.0"))
619 .file("p2
/src
/lib
.rs
", "")
626 "paths
= ['{}'
, '{}'
]",
627 bar.root().join("p1
").display(),
628 bar.root().join("p2
").display()
639 authors
= ["wycats@example.com"]
645 bar.root().join("p2
").display()
648 .file("src
/lib
.rs
", "")
651 p.cargo("build
-v
").run();
655 fn path_dep_build_cmd() {
664 authors
= ["wycats@example.com"]
672 .file("src
/main
.rs
", &main_file(r#""{}", bar
::gimme()"#, &["bar
"]))
680 authors
= ["wycats@example.com"]
693 fs
::copy("src/bar.rs.in", "src/bar.rs").unwrap();
697 .file("bar
/src
/bar
.rs
.in", "pub fn gimme() -> i32 { 0 }
")
699 p.root().join("bar
").move_into_the_past();
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 \
710 assert!(p.bin("foo
").is_file());
712 p.process(&p.bin("foo
")).with_stdout("0\n").run();
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 }
");
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 \
726 p.process(&p.bin("foo
")).with_stdout("1\n").run();
730 fn dev_deps_no_rebuild_lib() {
740 [dev
-dependencies
.bar
]
751 #[cfg(test)] #[allow(unused_extern_crates)] extern crate bar;
752 #[cfg(not(test))] pub fn foo() { env!("FOO"); }
755 .file("bar
/Cargo
.toml
", &basic_manifest("bar
", "0.5.0"))
756 .file("bar
/src
/lib
.rs
", "pub fn bar() {}
")
761 "[COMPILING
] foo v0
.5
.0 ([CWD
])\n\
762 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) \
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
])",
775 .with_stdout_contains("running
0 tests
")
780 fn custom_target_no_rebuild() {
795 .file("src
/lib
.rs
", "")
796 .file("a
/Cargo
.toml
", &basic_manifest("a
", "0.5.0"))
797 .file("a
/src
/lib
.rs
", "")
806 a
= { path = "../a" }
809 .file("b
/src
/lib
.rs
", "")
814 [COMPILING
] a v0
.5
.0 ([..])
815 [COMPILING
] foo v0
.5
.0 ([..])
816 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
822 p.root().join("target
"),
823 p.root().join("target_moved
")
825 p.cargo("build
--manifest
-path
=b
/Cargo
.toml
")
826 .env("CARGO_TARGET_DIR
", "target_moved
")
829 [COMPILING
] b v0
.5
.0 ([..])
830 [FINISHED
] dev
[unoptimized
+ debuginfo
] target(s
) in [..]
837 fn override_and_depend() {
848 a2
= { path = "../a2" }
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
", "")
862 a1
= { path = "../a/a1" }
863 a2
= { path = "../a/a2" }
866 .file("b
/src
/lib
.rs
", "")
867 .file("b
/.cargo
/config
", r#"paths
= ["../a"]"#)
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 [..]
884 fn missing_path_dependency() {
886 .file("Cargo
.toml
", &basic_manifest("a
", "0.5.0"))
887 .file("src
/lib
.rs
", "")
890 r#"paths
= ["../whoa-this-does-not-exist"]"#,
897 [ERROR
] failed to update path
override `
[..]../whoa
-this
-does
-not
-exist`
\
901 failed to read directory `
[..]`
911 fn invalid_path_dep_in_workspace_with_lockfile() {
912 Package::new("bar
", "1.0.0").publish();
926 foo
= { path = "foo" }
929 .file("src
/lib
.rs
", "")
942 .file("foo
/src
/lib
.rs
", "")
945 // Generate a lock file
946 p.cargo("build
").run();
948 // Change the dependency on `bar` to an invalid path
962 // Make sure we get a nice error. In the past this actually stack
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 ([..])`
979 fn workspace_produces_rlib() {
992 foo
= { path = "foo" }
995 .file("src
/lib
.rs
", "")
996 .file("foo
/Cargo
.toml
", &basic_manifest("foo
", "0.5.0"))
997 .file("foo
/src
/lib
.rs
", "")
1000 p.cargo("build
").run();
1002 assert!(p.root().join("target
/debug
/libtop
.rlib
").is_file());
1003 assert!(!p.root().join("target
/debug
/libfoo
.rlib
").is_file());
1007 fn deep_path_error() {
1008 // Test for an error loading a path deep in the dependency graph.
1020 .file("src
/lib
.rs
", "")
1031 .file("a
/src
/lib
.rs
", "")
1042 .file("b
/src
/lib
.rs
", "")
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 [..]`
1054 failed to load source
for dependency `c`
1057 Unable to update
[..]/foo
/c
1060 failed to read `
[..]/foo
/c
/Cargo
.toml`
1070 fn catch_tricky_cycle() {
1080 test
= { path = "test" }
1083 .file("src
/lib
.rs
", "")
1085 "tangle
/Cargo
.toml
",
1092 message
= { path = ".." }
1093 snapshot
= { path = "../snapshot" }
1096 .file("tangle
/src
/lib
.rs
", "")
1098 "snapshot
/Cargo
.toml
",
1105 ledger
= { path = "../ledger" }
1108 .file("snapshot
/src
/lib
.rs
", "")
1110 "ledger
/Cargo
.toml
",
1117 tangle
= { path = "../tangle" }
1120 .file("ledger
/src
/lib
.rs
", "")
1129 snapshot
= { path = "../snapshot" }
1132 .file("test
/src
/lib
.rs
", "")
1136 .with_stderr_contains("[..]cyclic package dependency
[..]")