cargo/tests/testsuite/rename_deps.rs

392 lines
9.4 KiB
Rust
Raw Normal View History

2019-11-25 02:42:45 +00:00
//! Tests for renaming dependencies.
use cargo_test_support::git;
use cargo_test_support::paths;
use cargo_test_support::registry::{self, Package};
use cargo_test_support::{basic_manifest, project};
#[cargo_test]
fn rename_dependency() {
Package::new("bar", "0.1.0").publish();
Package::new("bar", "0.2.0").publish();
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.0.1"
authors = []
[dependencies]
bar = { version = "0.1.0" }
baz = { version = "0.2.0", package = "bar" }
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "extern crate bar; extern crate baz;")
.build();
p.cargo("build").run();
}
#[cargo_test]
fn rename_with_different_names() {
let p = project()
2018-03-14 15:17:44 +00:00
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.0.1"
authors = []
2020-09-27 00:59:58 +00:00
[dependencies]
baz = { path = "bar", package = "bar" }
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "extern crate baz;")
2018-03-14 15:17:44 +00:00
.file(
"bar/Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "bar"
version = "0.0.1"
authors = []
2020-09-27 00:59:58 +00:00
[lib]
name = "random_name"
"#,
2018-12-08 11:19:47 +00:00
)
.file("bar/src/lib.rs", "")
.build();
p.cargo("build").run();
}
#[cargo_test]
fn lots_of_names() {
registry::alt_init();
Package::new("foo", "0.1.0")
.file("src/lib.rs", "pub fn foo1() {}")
.publish();
Package::new("foo", "0.2.0")
.file("src/lib.rs", "pub fn foo() {}")
.publish();
Package::new("foo", "0.1.0")
.file("src/lib.rs", "pub fn foo2() {}")
.alternative(true)
.publish();
let g = git::repo(&paths::root().join("another"))
2018-07-24 22:35:01 +00:00
.file("Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("src/lib.rs", "pub fn foo3() {}")
.build();
let p = project()
.file(
"Cargo.toml",
&format!(
r#"
2020-09-27 00:59:58 +00:00
[package]
name = "test"
version = "0.1.0"
authors = []
[dependencies]
foo = "0.2"
foo1 = {{ version = "0.1", package = "foo" }}
foo2 = {{ version = "0.1", registry = "alternative", package = "foo" }}
foo3 = {{ git = '{}', package = "foo" }}
foo4 = {{ path = "foo", package = "foo" }}
"#,
g.url()
),
2018-12-08 11:19:47 +00:00
)
.file(
"src/lib.rs",
"
extern crate foo;
extern crate foo1;
extern crate foo2;
extern crate foo3;
extern crate foo4;
pub fn foo() {
foo::foo();
foo1::foo1();
foo2::foo2();
foo3::foo3();
foo4::foo4();
}
",
2018-12-08 11:19:47 +00:00
)
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("foo/src/lib.rs", "pub fn foo4() {}")
.build();
p.cargo("build -v").run();
}
#[cargo_test]
fn rename_and_patch() {
Package::new("foo", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.1.0"
authors = []
[dependencies]
bar = { version = "0.1", package = "foo" }
[patch.crates-io]
foo = { path = "foo" }
"#,
2018-12-08 11:19:47 +00:00
)
.file(
"src/lib.rs",
"extern crate bar; pub fn foo() { bar::foo(); }",
2018-12-08 11:19:47 +00:00
)
.file("foo/Cargo.toml", &basic_manifest("foo", "0.1.0"))
.file("foo/src/lib.rs", "pub fn foo() {}")
.build();
p.cargo("build -v").run();
}
#[cargo_test]
fn rename_twice() {
Package::new("foo", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.1.0"
authors = []
[dependencies]
bar = { version = "0.1", package = "foo" }
[build-dependencies]
foo = { version = "0.1" }
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.build();
p.cargo("build -v")
.with_status(101)
.with_stderr(
"\
[UPDATING] `[..]` index
2018-09-14 20:33:18 +00:00
[DOWNLOADING] crates ...
[DOWNLOADED] foo v0.1.0 (registry [..])
2019-01-27 17:53:13 +00:00
error: the crate `test v0.1.0 ([CWD])` depends on crate `foo v0.1.0` multiple times with different names
",
2018-12-08 11:19:47 +00:00
)
.run();
}
2018-04-28 10:35:49 +00:00
#[cargo_test]
2018-04-28 10:35:49 +00:00
fn rename_affects_fingerprint() {
Package::new("foo", "0.1.0").publish();
let p = project()
2018-04-28 10:35:49 +00:00
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.1.0"
authors = []
[dependencies]
foo = { version = "0.1", package = "foo" }
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "extern crate foo;")
2018-04-28 10:35:49 +00:00
.build();
p.cargo("build -v").run();
2018-04-28 10:35:49 +00:00
p.change_file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.1.0"
authors = []
[dependencies]
bar = { version = "0.1", package = "foo" }
"#,
);
p.cargo("build -v")
.with_status(101)
.with_stderr_contains("[..]can't find crate for `foo`")
.run();
2018-04-28 10:35:49 +00:00
}
#[cargo_test]
fn can_run_doc_tests() {
Package::new("bar", "0.1.0").publish();
Package::new("bar", "0.2.0").publish();
let foo = project()
.file(
"Cargo.toml",
r#"
[package]
2020-09-27 00:59:58 +00:00
name = "foo"
version = "0.0.1"
2020-09-27 00:59:58 +00:00
[dependencies]
bar = { version = "0.1.0" }
baz = { version = "0.2.0", package = "bar" }
"#,
2018-12-08 11:19:47 +00:00
)
.file(
"src/lib.rs",
"
extern crate bar;
extern crate baz;
",
2018-12-08 11:19:47 +00:00
)
.build();
foo.cargo("test -v")
.with_stderr_contains(
"\
[DOCTEST] foo
[RUNNING] `rustdoc [..]--test [..]src/lib.rs \
[..] \
--extern bar=[CWD]/target/debug/deps/libbar-[..].rlib \
--extern baz=[CWD]/target/debug/deps/libbar-[..].rlib \
[..]`
",
2018-12-08 11:19:47 +00:00
)
.run();
}
#[cargo_test]
fn features_still_work() {
Package::new("foo", "0.1.0").publish();
Package::new("bar", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.1.0"
authors = []
[dependencies]
p1 = { path = 'a', features = ['b'] }
p2 = { path = 'b' }
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.file(
"a/Cargo.toml",
r#"
[package]
name = "p1"
version = "0.1.0"
authors = []
[dependencies]
b = { version = "0.1", package = "foo", optional = true }
"#,
2018-12-08 11:19:47 +00:00
)
.file("a/src/lib.rs", "extern crate b;")
.file(
"b/Cargo.toml",
r#"
[package]
name = "p2"
version = "0.1.0"
authors = []
[dependencies]
b = { version = "0.1", package = "bar", optional = true }
[features]
default = ['b']
"#,
2018-12-08 11:19:47 +00:00
)
.file("b/src/lib.rs", "extern crate b;")
.build();
p.cargo("build -v").run();
}
#[cargo_test]
fn features_not_working() {
Package::new("foo", "0.1.0").publish();
Package::new("bar", "0.1.0").publish();
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "test"
version = "0.1.0"
authors = []
[dependencies]
a = { path = 'a', package = 'p1', optional = true }
[features]
default = ['p1']
"#,
2018-12-08 11:19:47 +00:00
)
.file("src/lib.rs", "")
.file("a/Cargo.toml", &basic_manifest("p1", "0.1.0"))
.build();
p.cargo("build -v")
.with_status(101)
.with_stderr(
"\
error: failed to parse manifest at `[..]`
Caused by:
feature `default` includes `p1` which is neither a dependency nor another feature
",
2018-12-08 11:19:47 +00:00
)
.run();
}
2018-10-05 21:05:24 +00:00
#[cargo_test]
2018-10-05 21:05:24 +00:00
fn rename_with_dash() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "qwerty"
version = "0.1.0"
[dependencies]
foo-bar = { path = 'a', package = 'a' }
"#,
)
.file("src/lib.rs", "extern crate foo_bar;")
.file("a/Cargo.toml", &basic_manifest("a", "0.1.0"))
.file("a/src/lib.rs", "")
.build();
2018-12-08 11:19:47 +00:00
p.cargo("build").run();
2018-10-05 21:05:24 +00:00
}